Commit d45f8eba1303de9699e61c3529e533b4b8d349d7
1 parent
f0426bdc
Exists in
master
and in
29 other branches
Move conversation to the top after message
Conflicts: public/javascripts/chat.js
Showing
2 changed files
with
22 additions
and
1 deletions
Show diff stats
app/controllers/public/chat_controller.rb
| ... | ... | @@ -65,7 +65,7 @@ class ChatController < PublicController |
| 65 | 65 | |
| 66 | 66 | def recent_conversations |
| 67 | 67 | conversations_order = ActiveRecord::Base.connection.execute("select profiles.identifier from profiles inner join (select distinct r.id as id, MAX(r.created_at) as created_at from (select from_id, to_id, created_at, (case when from_id=#{user.id} then to_id else from_id end) as id from chat_messages where from_id=#{user.id} or to_id=#{user.id}) as r group by id order by created_at desc, id) as t on profiles.id=t.id order by t.created_at desc").entries.map {|e| e['identifier']} |
| 68 | - render :json => conversations_order.to_json | |
| 68 | + render :json => {:order => conversations_order.reverse, :domain => environment.default_hostname.gsub('.','-')}.to_json | |
| 69 | 69 | end |
| 70 | 70 | |
| 71 | 71 | protected | ... | ... |
public/javascripts/chat.js
| ... | ... | @@ -450,6 +450,8 @@ jQuery(function($) { |
| 450 | 450 | .c('active', {xmlns: Strophe.NS.CHAT_STATES}); |
| 451 | 451 | Jabber.connection.send(message); |
| 452 | 452 | Jabber.show_message(jid, $own_name, escape_html(body), 'self', Strophe.getNodeFromJid(Jabber.connection.jid)); |
| 453 | + Archive.register(jid, Jabber.connection.jid, body); | |
| 454 | + move_conversation_to_the_top(jid); | |
| 453 | 455 | }, |
| 454 | 456 | |
| 455 | 457 | is_a_room: function(jid_id) { |
| ... | ... | @@ -613,10 +615,29 @@ jQuery(function($) { |
| 613 | 615 | Jabber.show_message(jid, from['name'], body, who, from['id'], date, offset); |
| 614 | 616 | }); |
| 615 | 617 | stop_fetching('.history'); |
| 618 | + console.log('Done fetching...'); | |
| 616 | 619 | ensure_scroll(jid, offset); |
| 617 | 620 | }); |
| 618 | 621 | } |
| 619 | 622 | |
| 623 | + function move_conversation_to_the_top(jid) { | |
| 624 | + id = Jabber.jid_to_id(jid); | |
| 625 | + console.log('Moving ' + id); | |
| 626 | + console.log(id); | |
| 627 | + var link = $('#'+id); | |
| 628 | + var li = link.closest('li'); | |
| 629 | + var ul = link.closest('ul'); | |
| 630 | + ul.prepend(li); | |
| 631 | + } | |
| 632 | + | |
| 633 | + function recent_conversations() { | |
| 634 | + $.getJSON('/chat/recent_conversations', {}, function(data) { | |
| 635 | + $.each(data['order'], function(i, identifier) { | |
| 636 | + move_conversation_to_the_top(identifier+'-'+data['domain']); | |
| 637 | + }) | |
| 638 | + }) | |
| 639 | + } | |
| 640 | + | |
| 620 | 641 | function count_unread_messages(jid_id, hide) { |
| 621 | 642 | var unread = $('.buddies #'+jid_id+ ' .unread-messages'); |
| 622 | 643 | if (hide) { | ... | ... |