Merge pull request #3967 from prellele/autoscroll_to_unread_messages_in_conversation
added a id and a autoscroll to first unread message in conversation
This commit is contained in:
commit
c5f52248a6
7 changed files with 39 additions and 6 deletions
|
|
@ -37,6 +37,7 @@
|
||||||
* Add settings web mobile. [#3701](https://github.com/diaspora/diaspora/pull/3701)
|
* 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).
|
* 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).
|
* 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
|
## Bug Fixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
|
if ($('#first_unread').length > 0) {
|
||||||
|
$("html").scrollTop($('#first_unread').offset().top-45);
|
||||||
|
}
|
||||||
|
|
||||||
$('a.conversation').live('click', function(){
|
$('a.conversation').live('click', function(){
|
||||||
$.getScript(this.href, function() {
|
$.getScript(this.href, function() {
|
||||||
Diaspora.page.directionDetector.updateBinds();
|
Diaspora.page.directionDetector.updateBinds();
|
||||||
|
|
@ -13,7 +17,7 @@ $(document).ready(function(){
|
||||||
history.pushState(null, "", this.href);
|
history.pushState(null, "", this.href);
|
||||||
|
|
||||||
var conv = $(this).children('.stream_element'),
|
var conv = $(this).children('.stream_element'),
|
||||||
cBadge = $("#message_inbox_badge").children(".badge_count");
|
cBadge = $("#message_inbox_badge .badge_count");
|
||||||
if(conv.hasClass('unread') ){
|
if(conv.hasClass('unread') ){
|
||||||
conv.removeClass('unread');
|
conv.removeClass('unread');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,17 @@ class ConversationsController < ApplicationController
|
||||||
@visibilities = ConversationVisibility.where(:person_id => current_user.person_id).paginate(
|
@visibilities = ConversationVisibility.where(:person_id => current_user.person_id).paginate(
|
||||||
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')
|
: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 = {}
|
@unread_counts = {}
|
||||||
@visibilities.each { |v| @unread_counts[v.conversation_id] = v.unread }
|
@visibilities.each { |v| @unread_counts[v.conversation_id] = v.unread }
|
||||||
|
|
||||||
|
@first_unread_message_id = @conversation.try(:first_unread_message, current_user).try(:id)
|
||||||
|
|
||||||
@authors = {}
|
@authors = {}
|
||||||
@conversations.each { |c| @authors[c.id] = c.last_author }
|
@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|
|
respond_with do |format|
|
||||||
format.html
|
format.html
|
||||||
format.json { render :json => @conversations, :status => 200 }
|
format.json { render :json => @conversations, :status => 200 }
|
||||||
|
|
@ -56,6 +58,8 @@ class ConversationsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
if @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
|
if @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
|
||||||
:conversation_visibilities => {:person_id => current_user.person_id}).first
|
: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
|
if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
|
||||||
@visibility.unread = 0
|
@visibility.unread = 0
|
||||||
@visibility.save
|
@visibility.save
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,12 @@ class Conversation < ActiveRecord::Base
|
||||||
self.author = Webfinger.new(nh).fetch
|
self.author = Webfinger.new(nh).fetch
|
||||||
end
|
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?
|
def public?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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").addClass('selected');
|
||||||
$(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").find(".unread_message_count").remove()
|
$(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").find(".unread_message_count").remove()
|
||||||
|
|
||||||
|
$("html").scrollTop($('#first_unread').offset().top-45);
|
||||||
|
|
||||||
Diaspora.page.timeAgo.updateTimeAgo();
|
Diaspora.page.timeAgo.updateTimeAgo();
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
-# licensed under the Affero General Public License version 3 or later. See
|
-# licensed under the Affero General Public License version 3 or later. See
|
||||||
-# the COPYRIGHT file.
|
-# 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
|
.media
|
||||||
.img
|
.img
|
||||||
= person_image_link(message.author, :size => :thumb_small)
|
= person_image_link(message.author, :size => :thumb_small)
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,22 @@ describe Conversation do
|
||||||
end
|
end
|
||||||
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
|
context 'transport' do
|
||||||
before do
|
before do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue