Commit 7e781e2409528fb143362fee44e64445a9269975

Authored by Rodrigo Souto
2 parents d29ca9e2 e779fb69

Merge branch 'chat' of gitlab.com:diguliu/noosfero into chat

public/javascripts/application.js
... ... @@ -587,20 +587,6 @@ function display_notice(message) {
587 587 setTimeout(function() { $noticeBox.fadeOut('fast'); }, 5000);
588 588 }
589 589  
590   -function open_chat_window(anchor) {
591   - jQuery('#chat').addClass('opened');
592   - jQuery('#chat-label').addClass('opened');
593   - jQuery("#chat" ).trigger('opengroup', anchor);
594   - return false;
595   -}
596   -
597   -function toggle_chat_window() {
598   - if(jQuery('#conversations .conversation').length == 0) jQuery('.buddies a').first().click();
599   - jQuery('#chat').toggleClass('opened');
600   - jQuery('#chat-label').toggleClass('opened');
601   - return false;
602   -}
603   -
604 590 jQuery(function($) {
605 591 /* Adds a class to "opera" to the body element if Opera browser detected.
606 592 */
... ...
public/javascripts/chat.js
... ... @@ -200,19 +200,19 @@ jQuery(function($) {
200 200 $.post('/chat/join', {room_id: jid});
201 201 },
202 202  
203   - leave_room: function(room_jid) {
  203 + leave_room: function(jid, push) {
204 204 if(push == undefined)
205 205 push = true
206   - var jid_id = Jabber.jid_to_id(room_jid);
  206 + var jid_id = Jabber.jid_to_id(jid);
207 207 var conversation_id = Jabber.conversation_prefix + jid_id;
208 208 var button = $('#' + conversation_id + ' .leave');
209 209 button.hide();
210 210 button.siblings('.join').show();
211   - Jabber.connection.send($pres({from: Jabber.connection.jid, to: room_jid + '/' + $own_name, type: 'unavailable'}))
212   - Jabber.insert_or_update_group(room_jid, 'offline');
  211 + Jabber.connection.send($pres({from: Jabber.connection.jid, to: jid + '/' + $own_name, type: 'unavailable'}))
  212 + Jabber.insert_or_update_group(jid, 'offline');
213 213 sort_conversations();
214 214 if(push)
215   - $.post('/chat/leave', {room_id: room_jid});
  215 + $.post('/chat/leave', {room_id: jid});
216 216 },
217 217  
218 218 update_chat_title: function () {
... ... @@ -498,7 +498,6 @@ jQuery(function($) {
498 498 .c('active', {xmlns: Strophe.NS.CHAT_STATES});
499 499 Jabber.connection.send(message);
500 500 Jabber.show_message(jid, $own_name, escape_html(body), 'self', Strophe.getNodeFromJid(Jabber.connection.jid));
501   - Archive.register(jid, Jabber.connection.jid, body);
502 501 move_conversation_to_the_top(jid);
503 502 },
504 503  
... ... @@ -535,34 +534,6 @@ jQuery(function($) {
535 534 Jabber.connect();
536 535 });
537 536  
538   - // detect when click in chat with a community or person in main window of Noosfero environment
539   - $('#chat').bind('opengroup', function(ev, anchor) {
540   - var full_jid = anchor.replace('#', '');
541   - var jid = Strophe.getBareJidFromJid(full_jid);
542   - console.log('>>>> '+jid);
543   - var name = Strophe.getResourceFromJid(full_jid);
544   - var jid_id = Jabber.jid_to_id(full_jid);
545   - if (full_jid) {
546   - if (Strophe.getDomainFromJid(jid) == Jabber.muc_domain) {
547   - if (Jabber.muc_supported) {
548   - log('opening groupchat with ' + jid);
549   - Jabber.jids[jid_id] = {jid: jid, name: name, type: 'groupchat'};
550   - Jabber.enter_room(jid);
551   - var conversation = create_conversation_tab(name, jid_id);
552   - conversation.find('.conversation').show();
553   - recent_messages(jid);
554   - }
555   - }
556   - else {
557   - log('opening chat with ' + jid);
558   - var conversation = create_conversation_tab(name, jid_id);
559   - conversation.find('.conversation').show();
560   - recent_messages(jid);
561   - }
562   - conversation.find('.input').focus();
563   - }
564   - });
565   -
566 537 $('.conversation textarea').live('keydown', function(e) {
567 538 if (e.keyCode == 13) {
568 539 var jid = $(this).attr('data-to');
... ... @@ -609,6 +580,51 @@ jQuery(function($) {
609 580 $('.conversation textarea:visible').focus();
610 581 });
611 582  
  583 + function toggle_chat_window() {
  584 + if(jQuery('#conversations .conversation').length == 0) jQuery('.buddies a').first().click();
  585 + jQuery('#chat').toggleClass('opened');
  586 + jQuery('#chat-label').toggleClass('opened');
  587 + }
  588 +
  589 + function load_conversation(jid) {
  590 + var jid_id = Jabber.jid_to_id(jid);
  591 + var name = Jabber.name_of(jid_id);
  592 + if (jid) {
  593 + if (Strophe.getDomainFromJid(jid) == Jabber.muc_domain) {
  594 + if (Jabber.muc_supported) {
  595 + log('opening groupchat with ' + jid);
  596 + Jabber.jids[jid_id] = {jid: jid, name: name, type: 'groupchat'};
  597 + var conversation = create_conversation_tab(name, jid_id);
  598 + Jabber.enter_room(jid);
  599 + recent_messages(jid);
  600 + return conversation;
  601 + }
  602 + }
  603 + else {
  604 + log('opening chat with ' + jid);
  605 + Jabber.jids[jid_id] = {jid: jid, name: name, type: 'friendchat'};
  606 + var conversation = create_conversation_tab(name, jid_id);
  607 + recent_messages(jid);
  608 + return conversation;
  609 + }
  610 + }
  611 + }
  612 +
  613 + function open_conversation(jid) {
  614 + var conversation = load_conversation(jid);
  615 + var jid_id = $(this).attr('id');
  616 +
  617 + $('.conversation').hide();
  618 + conversation.show();
  619 + count_unread_messages(jid_id, true);
  620 + if(conversation.find('.chat-offset-container-0').length == 0)
  621 + recent_messages(Jabber.jid_of(jid_id));
  622 + conversation.find('.input').focus();
  623 + $('#chat').addClass('opened');
  624 + $('#chat-label').addClass('opened');
  625 + $.post('/chat/tab', {tab_id: jid_id});
  626 + }
  627 +
612 628 function create_conversation_tab(title, jid_id) {
613 629 var conversation_id = Jabber.conversation_prefix + jid_id;
614 630 var conversation = $('#' + conversation_id);
... ... @@ -701,12 +717,11 @@ jQuery(function($) {
701 717 function load_defaults() {
702 718 $.getJSON('/chat/my_session', {}, function(data) {
703 719 $.each(data.rooms, function(i, room_jid) {
704   - Jabber.enter_room(room_jid, false);
  720 + $('#chat').trigger('opengroup', room_jid);
705 721 })
706 722  
707 723 $('#'+data.tab_id).click();
708 724  
709   - console.log(data);
710 725 if(data.status == 'opened')
711 726 toggle_chat_window();
712 727 })
... ... @@ -794,7 +809,7 @@ jQuery(function($) {
794 809 var options = {body: message.body, icon: avatar, tag: jid_id};
795 810 console.log('Notify '+name);
796 811 $(notifyMe(name, options)).on('click', function(){
797   - open_chat_window('#'+jid+'/'+name);
  812 + open_conversation(jid);
798 813 });
799 814 $.sound.play('/sounds/receive.wav');
800 815 }
... ...
public/stylesheets/chat.css
... ... @@ -237,7 +237,7 @@
237 237 }
238 238 #chat-window .history .message p {
239 239 margin-left: 40px;
240   - word-break: break-all;
  240 + word-wrap: break-word;
241 241 }
242 242  
243 243 #chat-window .history .message.self p {
... ...