diff --git a/app/controllers/public/chat_controller.rb b/app/controllers/public/chat_controller.rb index ee4cdd2..3c54bd9 100644 --- a/app/controllers/public/chat_controller.rb +++ b/app/controllers/public/chat_controller.rb @@ -65,7 +65,7 @@ class ChatController < PublicController def recent_conversations 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']} - render :json => conversations_order.to_json + render :json => {:order => conversations_order.reverse, :domain => environment.default_hostname.gsub('.','-')}.to_json end protected diff --git a/public/javascripts/chat.js b/public/javascripts/chat.js index d15e5f9..5467b1b 100644 --- a/public/javascripts/chat.js +++ b/public/javascripts/chat.js @@ -450,6 +450,8 @@ jQuery(function($) { .c('active', {xmlns: Strophe.NS.CHAT_STATES}); Jabber.connection.send(message); Jabber.show_message(jid, $own_name, escape_html(body), 'self', Strophe.getNodeFromJid(Jabber.connection.jid)); + Archive.register(jid, Jabber.connection.jid, body); + move_conversation_to_the_top(jid); }, is_a_room: function(jid_id) { @@ -613,10 +615,29 @@ jQuery(function($) { Jabber.show_message(jid, from['name'], body, who, from['id'], date, offset); }); stop_fetching('.history'); + console.log('Done fetching...'); ensure_scroll(jid, offset); }); } + function move_conversation_to_the_top(jid) { + id = Jabber.jid_to_id(jid); + console.log('Moving ' + id); + console.log(id); + var link = $('#'+id); + var li = link.closest('li'); + var ul = link.closest('ul'); + ul.prepend(li); + } + + function recent_conversations() { + $.getJSON('/chat/recent_conversations', {}, function(data) { + $.each(data['order'], function(i, identifier) { + move_conversation_to_the_top(identifier+'-'+data['domain']); + }) + }) + } + function count_unread_messages(jid_id, hide) { var unread = $('.buddies #'+jid_id+ ' .unread-messages'); if (hide) { -- libgit2 0.21.2