added a id and a autoscroll to first unread message in conversation (Fix: #3216)

This commit is contained in:
Lennart Prelle 2013-02-05 15:19:35 +01:00 committed by Lennart Prelle
parent 1c2b80b7aa
commit 2d0abe8309
7 changed files with 39 additions and 6 deletions

View file

@ -37,6 +37,7 @@
* Add settings web mobile. [#3701](https://github.com/diaspora/diaspora/pull/3701)
* Stream form on profile page [#3910](https://github.com/diaspora/diaspora/issues/3910).
* Add Getting_Started page mobile. [#3949](https://github.com/diaspora/diaspora/issues/3949).
* Autoscroll to the first unread message in conversations [#3216](https://github.com/diaspora/diaspora/issues/3216)
## Bug Fixes

View file

@ -6,6 +6,10 @@
$(document).ready(function(){
if ($('#first_unread').length > 0) {
$("html").scrollTop($('#first_unread').offset().top-45);
}
$('a.conversation').live('click', function(){
$.getScript(this.href, function() {
Diaspora.page.directionDetector.updateBinds();
@ -13,7 +17,7 @@ $(document).ready(function(){
history.pushState(null, "", this.href);
var conv = $(this).children('.stream_element'),
cBadge = $("#message_inbox_badge").children(".badge_count");
cBadge = $("#message_inbox_badge .badge_count");
if(conv.hasClass('unread') ){
conv.removeClass('unread');
}

View file

@ -10,16 +10,18 @@ class ConversationsController < ApplicationController
@visibilities = ConversationVisibility.where(:person_id => current_user.person_id).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@conversation = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person_id, :conversation_id => params[:conversation_id]}).first
@unread_counts = {}
@visibilities.each { |v| @unread_counts[v.conversation_id] = v.unread }
@first_unread_message_id = @conversation.try(:first_unread_message, current_user).try(:id)
@authors = {}
@conversations.each { |c| @authors[c.id] = c.last_author }
@conversation = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person_id, :conversation_id => params[:conversation_id]}).first
respond_with do |format|
format.html
format.json { render :json => @conversations, :status => 200 }
@ -56,6 +58,8 @@ class ConversationsController < ApplicationController
def show
if @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
:conversation_visibilities => {:person_id => current_user.person_id}).first
@first_unread_message_id = @conversation.first_unread_message(current_user).try(:id)
if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
@visibility.unread = 0
@visibility.save

View file

@ -33,6 +33,12 @@ class Conversation < ActiveRecord::Base
def diaspora_handle= nh
self.author = Webfinger.new(nh).fetch
end
def first_unread_message(user)
if visibility = self.conversation_visibilities.where(:person_id => user.person.id).where('unread > 0').first
self.messages.all[-visibility.unread]
end
end
def public?
false

View file

@ -4,4 +4,6 @@ $(".stream_element", "#conversation_inbox").removeClass('selected');
$(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").addClass('selected');
$(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").find(".unread_message_count").remove()
$("html").scrollTop($('#first_unread').offset().top-45);
Diaspora.page.timeAgo.updateTimeAgo();

View file

@ -2,7 +2,7 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.stream_element{:data=>{:guid=>message.id}}
.stream_element{:data=>{:guid=>message.id}, :id => ('first_unread' if @first_unread_message_id == message.id)}
.media
.img
= person_image_link(message.author, :size => :thumb_small)
@ -12,4 +12,4 @@
= t('ago', :time => time_ago_in_words(message.created_at))
%div{ :class => direction_for(message.text) }
= markdownify(message, :oembed => true)
= markdownify(message, :oembed => true)

View file

@ -32,6 +32,22 @@ describe Conversation do
end
end
describe '#first_unread_message' do
before do
@cnv = Conversation.create(@create_hash)
@message = Message.create(:author => @user2.person, :created_at => Time.now + 100, :text => "last", :conversation_id => @cnv.id)
@message.increase_unread(@user1)
end
it 'returns the first unread message if there are unread messages in a conversation' do
@cnv.first_unread_message(@user1) == @message
end
it 'returns nil if there are no unread messages in a conversation' do
@cnv.conversation_visibilities.where(:person_id => @user1.person.id).first.tap { |cv| cv.unread = 0 }.save
@cnv.first_unread_message(@user1).should be_nil
end
end
context 'transport' do
before do