Commit 024c2e05b347bd1c897ba7ee39a04847177ff45a
Committed by
Rodrigo Souto
1 parent
bbde3e9f
Exists in
master
and in
29 other branches
Chat improvement
Showing
4 changed files
with
27 additions
and
38 deletions
Show diff stats
app/controllers/public/chat_controller.rb
... | ... | @@ -45,9 +45,14 @@ class ChatController < PublicController |
45 | 45 | |
46 | 46 | def recent_messages |
47 | 47 | other = environment.profiles.find_by_identifier(params[:identifier]) |
48 | - messages = ChatMessage.where('(to_id=:other and from_id=:me) or (to_id=:me and from_id=:other)', {:me => user.id, :other => other.id}).order('created_at DESC').includes(:to, :from).limit(20) | |
48 | + if other.kind_of?(Organization) | |
49 | + messages = ChatMessage.where('to_id=:other', :other => other.id) | |
50 | + else | |
51 | + messages = ChatMessage.where('(to_id=:other and from_id=:me) or (to_id=:me and from_id=:other)', {:me => user.id, :other => other.id}) | |
52 | + end | |
49 | 53 | |
50 | - messages = messages.map do |message| | |
54 | + messages = messages.order('created_at DESC').includes(:to, :from).limit(20) | |
55 | + messages_json = messages.map do |message| | |
51 | 56 | { |
52 | 57 | :body => message.body, |
53 | 58 | :to => {:id => message.to.identifier, :name => message.to.name, :type => message.to.type}, |
... | ... | @@ -55,7 +60,7 @@ class ChatController < PublicController |
55 | 60 | :created_at => message.created_at |
56 | 61 | } |
57 | 62 | end |
58 | - render :json => messages.reverse | |
63 | + render :json => messages_json.reverse | |
59 | 64 | end |
60 | 65 | |
61 | 66 | protected | ... | ... |
app/views/shared/logged_in/xmpp_chat.html.erb
... | ... | @@ -25,7 +25,10 @@ |
25 | 25 | |
26 | 26 | <div id="friends"> |
27 | 27 | <div id='title-bar'><h1 class='title'><%= _("Online") %> (<span id='friends-online'>0</span>)</h1></div> |
28 | - <ul class='buddy-list'></ul> | |
28 | + <ul class='buddy-list online'></ul> | |
29 | + | |
30 | + <div id='title-bar'><h1 class='title'><%= _("Offline") %></h1></div> | |
31 | + <ul class='buddy-list offline'></ul> | |
29 | 32 | </div> |
30 | 33 | |
31 | 34 | <div id="rooms"> | ... | ... |
public/javascripts/chat.js
... | ... | @@ -24,7 +24,6 @@ jQuery(function($) { |
24 | 24 | muc_domain: $muc_domain, |
25 | 25 | muc_supported: false, |
26 | 26 | presence_status: '', |
27 | - update_presence_status_every: $update_presence_status_every, // time in seconds of how often update presence status to Noosfero DB | |
28 | 27 | conversation_prefix: 'conversation-', |
29 | 28 | jids: {}, |
30 | 29 | rooms: {}, |
... | ... | @@ -62,11 +61,9 @@ jQuery(function($) { |
62 | 61 | .replace(/%{presence_status}/g, presence) |
63 | 62 | .replace('%{avatar}', getAvatar(identifier)) |
64 | 63 | .replace('%{name}', name); |
65 | - if ($(item).length > 0) { | |
66 | - $(item).parent('li').replaceWith(html); | |
67 | - } else { | |
68 | - $(list).append(html); | |
69 | - } | |
64 | + | |
65 | + $(item).parent().remove(); | |
66 | + $(list).append(html); | |
70 | 67 | Jabber.jids[jid_id] = {jid: jid, name: name, type: type, presence: presence}; |
71 | 68 | }, |
72 | 69 | insert_or_update_group: function (jid, presence) { |
... | ... | @@ -82,9 +79,10 @@ jQuery(function($) { |
82 | 79 | }, |
83 | 80 | insert_or_update_contact: function (jid, name, presence) { |
84 | 81 | var jid_id = Jabber.jid_to_id(jid); |
85 | - var list = $('#buddy-list #friends .buddy-list'); | |
86 | 82 | var item = $('#' + jid_id); |
87 | 83 | presence = presence || ($(item).length > 0 ? $(item).parent('li').attr('class') : 'offline'); |
84 | + var list = $('#buddy-list #friends .buddy-list' + (presence=='offline' ? '.offline' : '.online')); | |
85 | + | |
88 | 86 | log('adding or updating contact ' + jid + ' as ' + presence); |
89 | 87 | Jabber.insert_or_update_user(list, item, jid, name, presence, $('#chat #chat-templates .buddy-item').clone().html(), 'chat'); |
90 | 88 | $("#chat-window .tab a[href='#"+ Jabber.conversation_prefix + jid_id +"']") |
... | ... | @@ -182,7 +180,7 @@ jQuery(function($) { |
182 | 180 | }, |
183 | 181 | |
184 | 182 | update_chat_title: function () { |
185 | - var friends_online = $('#buddy-list .buddy-list li:not(.offline)').length; | |
183 | + var friends_online = $('#buddy-list .buddy-list.online li').length; | |
186 | 184 | $('#friends-online').text(friends_online); |
187 | 185 | }, |
188 | 186 | |
... | ... | @@ -200,7 +198,6 @@ jQuery(function($) { |
200 | 198 | break; |
201 | 199 | case Strophe.Status.DISCONNECTED: |
202 | 200 | log('disconnected'); |
203 | - //Jabber.show_status(''); | |
204 | 201 | $('#buddy-list ul.buddy-list, .occupant-list ul.occupant-list').html(''); |
205 | 202 | Jabber.update_chat_title(); |
206 | 203 | $('#buddy-list .toolbar').removeClass('small-loading-dark'); |
... | ... | @@ -402,13 +399,6 @@ jQuery(function($) { |
402 | 399 | Jabber.on_muc_support |
403 | 400 | ); |
404 | 401 | |
405 | - // Timed handle to save presence status to Noosfero DB every (N) seconds | |
406 | - Jabber.connection.addTimedHandler(Jabber.update_presence_status_every * 1000, function() { | |
407 | - log('saving presence status to Noosfero DB'); | |
408 | - $.get('/chat/update_presence_status', { status: {chat_status: Jabber.presence_status} }); | |
409 | - return true; | |
410 | - }); | |
411 | - | |
412 | 402 | // uncomment for extra debugging |
413 | 403 | //Strophe.log = function (lvl, msg) { log(msg); }; |
414 | 404 | }, |
... | ... | @@ -467,11 +457,6 @@ jQuery(function($) { |
467 | 457 | disconnect(); |
468 | 458 | }); |
469 | 459 | |
470 | - // save presence_status as offline in Noosfero database when close or reload chat window | |
471 | - $(window).unload(function() { | |
472 | - //disconnect(); | |
473 | - }); | |
474 | - | |
475 | 460 | $('#chat-busy').click(function() { |
476 | 461 | Jabber.presence_status = 'dnd'; |
477 | 462 | Jabber.connect(); |
... | ... | @@ -496,6 +481,7 @@ jQuery(function($) { |
496 | 481 | Jabber.enter_room(jid); |
497 | 482 | var conversation = create_conversation_tab(name, jid_id); |
498 | 483 | conversation.find('.conversation').show(); |
484 | + recent_messages(jid); | |
499 | 485 | } |
500 | 486 | } |
501 | 487 | else { |
... | ... | @@ -532,6 +518,7 @@ jQuery(function($) { |
532 | 518 | |
533 | 519 | conversation.find('.conversation').show(); |
534 | 520 | count_unread_messages(jid_id, true); |
521 | + recent_messages(Jabber.jid_of(jid_id)); | |
535 | 522 | conversation.find('.conversation .input-div textarea.input').focus(); |
536 | 523 | }); |
537 | 524 | |
... | ... | @@ -582,8 +569,6 @@ jQuery(function($) { |
582 | 569 | } |
583 | 570 | textarea.attr('data-to', jid); |
584 | 571 | |
585 | - recent_messages(jid); | |
586 | - | |
587 | 572 | return panel; |
588 | 573 | } |
589 | 574 | |
... | ... | @@ -596,11 +581,14 @@ jQuery(function($) { |
596 | 581 | var from = message['from']; |
597 | 582 | var to = message['to']; |
598 | 583 | var date = message['created_at']; |
584 | + var group = to['type']=='Community' ? 'conference.' : ''; | |
585 | + var domain = '127.0.0.1'; | |
599 | 586 | |
600 | - if(from['id']!=getCurrentIdentifier()) { | |
601 | - Jabber.show_message(from['id']+'@127.0.0.1', from['name'], body, 'other', from['id'], date); | |
587 | + if(from['id']==getCurrentIdentifier()) { | |
588 | + Jabber.show_message(to['id']+'@'+group+domain, $own_name, body, 'self', to['id'], date); | |
602 | 589 | } else { |
603 | - Jabber.show_message(to['id']+'@127.0.0.1', $own_name, body, 'self', to['id'], date); | |
590 | + var target = group!='' ? to['id'] : from['id'] | |
591 | + Jabber.show_message(target+'@'+group+domain, from['name'], body, 'other', from['id'], date); | |
604 | 592 | } |
605 | 593 | }); |
606 | 594 | }); |
... | ... | @@ -684,10 +672,3 @@ jQuery(function($) { |
684 | 672 | } |
685 | 673 | $('#chat #buddy-list').perfectScrollbar(); |
686 | 674 | }); |
687 | - | |
688 | -function checkTime(i) { | |
689 | - if (i<10) { | |
690 | - i="0" + i; | |
691 | - } | |
692 | - return i; | |
693 | -} | ... | ... |
public/stylesheets/chat.css