Commit dc4e304dec80741bc5dee8d287e2500be8043d00
Committed by
Rodrigo Souto
1 parent
2ec9c789
Exists in
master
and in
27 other branches
Fix group chat
Showing
4 changed files
with
88 additions
and
62 deletions
Show diff stats
app/views/shared/logged_in/xmpp_chat.html.erb
... | ... | @@ -21,12 +21,18 @@ |
21 | 21 | </div> |
22 | 22 | <div class='dialog-error' style='display: none'></div> |
23 | 23 | </div> |
24 | - <div id='title-bar'> | |
25 | - <h1 class='title'><%= _("Online") % h(page_title) %> (<span id='friends-online'>0</span>)</h1> | |
24 | + | |
25 | + <div id="friends"> | |
26 | + <div id='title-bar'><h1 class='title'><%= _("Online") %> (<span id='friends-online'>0</span>)</h1></div> | |
27 | + <ul class='buddy-list'></ul> | |
28 | + </div> | |
29 | + | |
30 | + <div id="rooms"> | |
31 | + <div id='title-bar'><h1 class='title'><%= _("Groups") %></h1></div> | |
32 | + <ul class="buddy-list room-list"></ul> | |
26 | 33 | </div> |
27 | - <ul class='buddy-list'> | |
28 | - </ul> | |
29 | 34 | </div> |
35 | + | |
30 | 36 | <div id='chat-window'> |
31 | 37 | <div id='conversations'></div> |
32 | 38 | </div> | ... | ... |
public/javascripts/application.js
... | ... | @@ -569,7 +569,12 @@ function display_notice(message) { |
569 | 569 | } |
570 | 570 | |
571 | 571 | function open_chat_window(self_link, anchor) { |
572 | - jQuery('#chat').toggle('fast'); | |
572 | + if(anchor) { | |
573 | + jQuery('#chat').show('fast'); | |
574 | + jQuery("#chat" ).trigger('opengroup', anchor); | |
575 | + } else { | |
576 | + jQuery('#chat').toggle('fast'); | |
577 | + } | |
573 | 578 | return false; |
574 | 579 | } |
575 | 580 | ... | ... |
public/javascripts/chat.js
... | ... | @@ -54,7 +54,7 @@ jQuery(function($) { |
54 | 54 | return Jabber.jids[jid_id].unread_messages; |
55 | 55 | }, |
56 | 56 | |
57 | - insert_or_update_user: function (list, item, jid, name, presence, template) { | |
57 | + insert_or_update_user: function (list, item, jid, name, presence, template, type) { | |
58 | 58 | var jid_id = Jabber.jid_to_id(jid); |
59 | 59 | var identifier = Strophe.getNodeFromJid(jid); |
60 | 60 | var html = template |
... | ... | @@ -67,15 +67,26 @@ jQuery(function($) { |
67 | 67 | } else { |
68 | 68 | $(list).append(html); |
69 | 69 | } |
70 | - Jabber.jids[jid_id] = {jid: jid, name: name, type: 'chat', presence: presence}; | |
70 | + Jabber.jids[jid_id] = {jid: jid, name: name, type: type, presence: presence}; | |
71 | + }, | |
72 | + insert_or_update_group: function (jid, presence) { | |
73 | + var jid_id = Jabber.jid_to_id(jid); | |
74 | + var list = $('#buddy-list #rooms .room-list'); | |
75 | + var item = $('#' + jid_id); | |
76 | + presence = presence || ($(item).length > 0 ? $(item).parent('li').attr('class') : 'offline'); | |
77 | + log('adding or updating contact ' + jid + ' as ' + presence); | |
78 | + Jabber.insert_or_update_user(list, item, jid, Jabber.name_of(jid_id), presence, $('#chat #chat-templates .buddy-item').clone().html(), 'groupchat'); | |
79 | + $("#chat-window .tab a[href='#"+ Jabber.conversation_prefix + jid_id +"']") | |
80 | + .removeClass() | |
81 | + .addClass('icon-menu-' + presence + '-11'); | |
71 | 82 | }, |
72 | 83 | insert_or_update_contact: function (jid, name, presence) { |
73 | 84 | var jid_id = Jabber.jid_to_id(jid); |
74 | - var list = $('#buddy-list .buddy-list'); | |
85 | + var list = $('#buddy-list #friends .buddy-list'); | |
75 | 86 | var item = $('#' + jid_id); |
76 | 87 | presence = presence || ($(item).length > 0 ? $(item).parent('li').attr('class') : 'offline'); |
77 | 88 | log('adding or updating contact ' + jid + ' as ' + presence); |
78 | - Jabber.insert_or_update_user(list, item, jid, name, presence, $('#chat #chat-templates .buddy-item').clone().html()); | |
89 | + Jabber.insert_or_update_user(list, item, jid, name, presence, $('#chat #chat-templates .buddy-item').clone().html(), 'chat'); | |
79 | 90 | $("#chat-window .tab a[href='#"+ Jabber.conversation_prefix + jid_id +"']") |
80 | 91 | .removeClass() |
81 | 92 | .addClass('icon-menu-' + presence + '-11'); |
... | ... | @@ -85,7 +96,7 @@ jQuery(function($) { |
85 | 96 | var jid_id = Jabber.jid_to_id(jid); |
86 | 97 | var list = $('#' + Jabber.conversation_prefix + Jabber.jid_to_id(room_jid) + ' .occupant-list ul'); |
87 | 98 | var item = $(list).find('a[data-id='+ jid_id +']'); |
88 | - Jabber.insert_or_update_user(list, item, jid, name, presence, Jabber.templates.occupant_item); | |
99 | + Jabber.insert_or_update_user(list, item, jid, name, presence, Jabber.templates.occupant_item, 'chat'); | |
89 | 100 | if (Jabber.rooms[Jabber.jid_to_id(room_jid)] === undefined) { |
90 | 101 | Jabber.rooms[Jabber.jid_to_id(room_jid)] = {}; |
91 | 102 | } |
... | ... | @@ -159,10 +170,13 @@ jQuery(function($) { |
159 | 170 | Jabber.connection.send( |
160 | 171 | $pres({to: room_jid + '/' + $own_name}).c('x', {xmlns: Strophe.NS.MUC}).c('history', {maxchars: 0}) |
161 | 172 | ); |
173 | + //FIXME list group | |
174 | + Jabber.insert_or_update_group(room_jid, 'group'); | |
162 | 175 | }, |
163 | 176 | |
164 | 177 | leave_room: function(room_jid) { |
165 | 178 | Jabber.connection.send($pres({from: Jabber.connection.jid, to: room_jid + '/' + $own_name, type: 'unavailable'})) |
179 | + //FIXME remove group | |
166 | 180 | }, |
167 | 181 | |
168 | 182 | update_chat_title: function () { |
... | ... | @@ -211,8 +225,6 @@ jQuery(function($) { |
211 | 225 | // set up presence handler and send initial presence |
212 | 226 | Jabber.connection.addHandler(Jabber.on_presence, null, "presence"); |
213 | 227 | Jabber.send_availability_status(Jabber.presence_status); |
214 | - // detect if chat was opened with anchor like #community@conference.jabber.colivre | |
215 | - $(window).trigger('hashchange'); | |
216 | 228 | }, |
217 | 229 | |
218 | 230 | // NOTE: cause Noosfero store's rosters in database based on friendship relation between people |
... | ... | @@ -468,29 +480,26 @@ jQuery(function($) { |
468 | 480 | Jabber.connect(); |
469 | 481 | }); |
470 | 482 | |
471 | - // FIXME | |
472 | 483 | // detect when click in chat with a community or person in main window of Noosfero environment |
473 | - $(window).bind('hashchange', function() { | |
474 | - if (window.location.hash) { | |
475 | - var full_jid = window.location.hash.replace('#', ''); | |
476 | - var jid = Strophe.getBareJidFromJid(full_jid); | |
477 | - var name = Strophe.getResourceFromJid(full_jid); | |
478 | - var jid_id = Jabber.jid_to_id(full_jid); | |
479 | - window.location.hash = '#'; | |
480 | - if (full_jid) { | |
481 | - if (Strophe.getDomainFromJid(jid) == Jabber.muc_domain) { | |
482 | - if (Jabber.muc_supported) { | |
483 | - log('opening groupchat with ' + jid); | |
484 | - Jabber.jids[jid_id] = {jid: jid, name: name, type: 'groupchat'}; | |
485 | - Jabber.enter_room(jid); | |
486 | - create_conversation_tab(name, jid_id); | |
487 | - } | |
488 | - } | |
489 | - else { | |
490 | - log('opening chat with ' + jid); | |
491 | - create_conversation_tab(name, jid_id); | |
484 | + $('#chat').bind('opengroup', function(ev, anchor) { | |
485 | + var full_jid = anchor.replace('#', ''); | |
486 | + var jid = Strophe.getBareJidFromJid(full_jid); | |
487 | + var name = Strophe.getResourceFromJid(full_jid); | |
488 | + var jid_id = Jabber.jid_to_id(full_jid); | |
489 | + if (full_jid) { | |
490 | + if (Strophe.getDomainFromJid(jid) == Jabber.muc_domain) { | |
491 | + if (Jabber.muc_supported) { | |
492 | + log('opening groupchat with ' + jid); | |
493 | + Jabber.jids[jid_id] = {jid: jid, name: name, type: 'groupchat'}; | |
494 | + Jabber.enter_room(jid); | |
495 | + var conversation = create_conversation_tab(name, jid_id); | |
496 | + conversation.find('.conversation').show(); | |
492 | 497 | } |
493 | 498 | } |
499 | + else { | |
500 | + log('opening chat with ' + jid); | |
501 | + create_conversation_tab(name, jid_id); | |
502 | + } | |
494 | 503 | } |
495 | 504 | }); |
496 | 505 | |
... | ... | @@ -509,15 +518,15 @@ jQuery(function($) { |
509 | 518 | $('#buddy-list .buddy-list li a').live('click', function() { |
510 | 519 | var jid_id = $(this).attr('id'); |
511 | 520 | var name = Jabber.name_of(jid_id); |
512 | - create_conversation_tab(name, jid_id); | |
521 | + var conversation = create_conversation_tab(name, jid_id); | |
513 | 522 | |
514 | - var conversation_id = Jabber.conversation_prefix + jid_id; | |
515 | - $('#' + conversation_id).find('.conversation').show(); | |
523 | + conversation.find('.conversation').show(); | |
516 | 524 | count_unread_messages(jid_id, true); |
517 | - $('#' + conversation_id).find('.conversation .input-div textarea.input').focus(); | |
525 | + conversation.find('.conversation .input-div textarea.input').focus(); | |
518 | 526 | }); |
519 | 527 | |
520 | 528 | // put name into text area when click in one occupant |
529 | + // FIXME | |
521 | 530 | $('.occupant-list .occupant-list li a').live('click', function() { |
522 | 531 | var jid_id = $(this).attr('data-id'); |
523 | 532 | var name = Jabber.name_of(jid_id); |
... | ... | @@ -535,26 +544,30 @@ jQuery(function($) { |
535 | 544 | |
536 | 545 | function create_conversation_tab(title, jid_id) { |
537 | 546 | var conversation_id = Jabber.conversation_prefix + jid_id; |
538 | - if (! $('#' + conversation_id).length > 0) { | |
539 | - var jid = Jabber.jid_of(jid_id); | |
540 | - var identifier = getIdentifier(jid); | |
541 | - | |
542 | - // opening chat with selected online friend | |
543 | - var panel = $('<div id="'+conversation_id +'"></div>').appendTo($conversations); | |
544 | - panel.append($('#chat #chat-templates .conversation').clone()); | |
545 | - panel.find('.chat-target .avatar').replaceWith(getAvatar(identifier)); | |
546 | - panel.find('.chat-target .other-name').html(title); | |
547 | - $('#chat .history').perfectScrollbar(); | |
548 | - | |
549 | - var textarea = panel.find('textarea'); | |
550 | - textarea.attr('name', panel.id); | |
551 | - | |
552 | - if (Jabber.is_a_room(jid_id)) { | |
553 | - panel.append(Jabber.templates.occupant_list); | |
554 | - panel.find('.history').addClass('room'); | |
555 | - } | |
556 | - textarea.attr('data-to', jid); | |
547 | + var conversation = $('#' + conversation_id); | |
548 | + if (conversation.length > 0) { | |
549 | + return conversation; | |
557 | 550 | } |
551 | + | |
552 | + var jid = Jabber.jid_of(jid_id); | |
553 | + var identifier = getIdentifier(jid); | |
554 | + | |
555 | + // opening chat with selected online friend | |
556 | + var panel = $('<div id="'+conversation_id +'"></div>').appendTo($conversations); | |
557 | + panel.append($('#chat #chat-templates .conversation').clone()); | |
558 | + panel.find('.chat-target .avatar').replaceWith(getAvatar(identifier)); | |
559 | + panel.find('.chat-target .other-name').html(title); | |
560 | + $('#chat .history').perfectScrollbar(); | |
561 | + | |
562 | + var textarea = panel.find('textarea'); | |
563 | + textarea.attr('name', panel.id); | |
564 | + | |
565 | + if (Jabber.is_a_room(jid_id)) { | |
566 | + panel.append(Jabber.templates.occupant_list); | |
567 | + panel.find('.history').addClass('room'); | |
568 | + } | |
569 | + textarea.attr('data-to', jid); | |
570 | + return panel; | |
558 | 571 | } |
559 | 572 | |
560 | 573 | function count_unread_messages(jid_id, hide) { |
... | ... | @@ -633,7 +646,7 @@ jQuery(function($) { |
633 | 646 | } else if($presence == 'dnd') { |
634 | 647 | $('#chat-busy').trigger('click'); |
635 | 648 | } |
636 | - | |
649 | + $('#chat #buddy-list').perfectScrollbar(); | |
637 | 650 | }); |
638 | 651 | |
639 | 652 | function checkTime(i) { | ... | ... |
public/stylesheets/chat.css
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 | width: 250px; |
14 | 14 | height: 100%; |
15 | 15 | overflow: hidden; |
16 | + position: absolute; | |
16 | 17 | } |
17 | 18 | #buddy-list .buddy-list { |
18 | 19 | list-style-type: none; |
... | ... | @@ -72,7 +73,12 @@ |
72 | 73 | background: white; |
73 | 74 | } |
74 | 75 | .conversation { |
75 | - margin: 15px; | |
76 | + background-color: #303030; | |
77 | + height: 100%; | |
78 | + position: absolute; | |
79 | + width: 100%; | |
80 | + top: 0; | |
81 | + right: 0; | |
76 | 82 | } |
77 | 83 | .conversation .input-div { |
78 | 84 | position: absolute; |
... | ... | @@ -106,7 +112,6 @@ |
106 | 112 | bottom: 100px; |
107 | 113 | overflow: hidden; |
108 | 114 | width: 100%; |
109 | - background-color: #303030; | |
110 | 115 | } |
111 | 116 | .msie7 #chat-window .conversation .history { |
112 | 117 | overflow-x: hidden; |
... | ... | @@ -175,9 +180,6 @@ |
175 | 180 | list-style: none; |
176 | 181 | font-size: 12px; |
177 | 182 | } |
178 | -#chat-window .history.room { | |
179 | - right: 200px | |
180 | -} | |
181 | 183 | #chat-window .comment-balloon-content { |
182 | 184 | min-height: 50px; |
183 | 185 | padding: 5px 0 5px 25px; |
... | ... | @@ -230,7 +232,7 @@ |
230 | 232 | font-weight: bold; |
231 | 233 | color: white; |
232 | 234 | } |
233 | -#chat #chat-window .other-name, #chat #chat-window .history .self-name { | |
235 | +#chat #chat-window .other-name, #chat #chat-window .history .self-name, #chat #chat-window .history h5 { | |
234 | 236 | color: #257CAD; |
235 | 237 | height: 23px; |
236 | 238 | overflow: hidden; | ... | ... |