Commit 7a83424bfb6b6dfdc9e093490b7857a14733c4d3

Authored by Rodrigo Souto
1 parent 80bac445

chat: open group chat properly after page reload

public/javascripts/application.js
@@ -587,10 +587,10 @@ function display_notice(message) { @@ -587,10 +587,10 @@ function display_notice(message) {
587 setTimeout(function() { $noticeBox.fadeOut('fast'); }, 5000); 587 setTimeout(function() { $noticeBox.fadeOut('fast'); }, 5000);
588 } 588 }
589 589
590 -function open_chat_window(anchor) { 590 +function open_chat_window(jid) {
591 jQuery('#chat').addClass('opened'); 591 jQuery('#chat').addClass('opened');
592 jQuery('#chat-label').addClass('opened'); 592 jQuery('#chat-label').addClass('opened');
593 - jQuery("#chat" ).trigger('opengroup', anchor); 593 + jQuery("#chat" ).trigger('opengroup', jid);
594 return false; 594 return false;
595 } 595 }
596 596
public/javascripts/chat.js
@@ -200,7 +200,7 @@ jQuery(function($) { @@ -200,7 +200,7 @@ jQuery(function($) {
200 $.post('/chat/join', {room_id: jid}); 200 $.post('/chat/join', {room_id: jid});
201 }, 201 },
202 202
203 - leave_room: function(jid) { 203 + leave_room: function(jid, push) {
204 if(push == undefined) 204 if(push == undefined)
205 push = true 205 push = true
206 var jid_id = Jabber.jid_to_id(jid); 206 var jid_id = Jabber.jid_to_id(jid);
@@ -498,7 +498,6 @@ jQuery(function($) { @@ -498,7 +498,6 @@ jQuery(function($) {
498 .c('active', {xmlns: Strophe.NS.CHAT_STATES}); 498 .c('active', {xmlns: Strophe.NS.CHAT_STATES});
499 Jabber.connection.send(message); 499 Jabber.connection.send(message);
500 Jabber.show_message(jid, $own_name, escape_html(body), 'self', Strophe.getNodeFromJid(Jabber.connection.jid)); 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 move_conversation_to_the_top(jid); 501 move_conversation_to_the_top(jid);
503 }, 502 },
504 503
@@ -536,19 +535,16 @@ jQuery(function($) { @@ -536,19 +535,16 @@ jQuery(function($) {
536 }); 535 });
537 536
538 // detect when click in chat with a community or person in main window of Noosfero environment 537 // 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) { 538 + $('#chat').bind('opengroup', function(ev, jid) {
  539 + var jid_id = Jabber.jid_to_id(jid);
  540 + var name = Jabber.name_of(jid_id);
  541 + if (jid) {
546 if (Strophe.getDomainFromJid(jid) == Jabber.muc_domain) { 542 if (Strophe.getDomainFromJid(jid) == Jabber.muc_domain) {
547 if (Jabber.muc_supported) { 543 if (Jabber.muc_supported) {
548 log('opening groupchat with ' + jid); 544 log('opening groupchat with ' + jid);
549 Jabber.jids[jid_id] = {jid: jid, name: name, type: 'groupchat'}; 545 Jabber.jids[jid_id] = {jid: jid, name: name, type: 'groupchat'};
550 - Jabber.enter_room(jid);  
551 var conversation = create_conversation_tab(name, jid_id); 546 var conversation = create_conversation_tab(name, jid_id);
  547 + Jabber.enter_room(jid);
552 conversation.find('.conversation').show(); 548 conversation.find('.conversation').show();
553 recent_messages(jid); 549 recent_messages(jid);
554 } 550 }
@@ -701,12 +697,11 @@ jQuery(function($) { @@ -701,12 +697,11 @@ jQuery(function($) {
701 function load_defaults() { 697 function load_defaults() {
702 $.getJSON('/chat/my_session', {}, function(data) { 698 $.getJSON('/chat/my_session', {}, function(data) {
703 $.each(data.rooms, function(i, room_jid) { 699 $.each(data.rooms, function(i, room_jid) {
704 - Jabber.enter_room(room_jid, false); 700 + $('#chat').trigger('opengroup', room_jid);
705 }) 701 })
706 702
707 $('#'+data.tab_id).click(); 703 $('#'+data.tab_id).click();
708 704
709 - console.log(data);  
710 if(data.status == 'opened') 705 if(data.status == 'opened')
711 toggle_chat_window(); 706 toggle_chat_window();
712 }) 707 })
@@ -794,7 +789,7 @@ jQuery(function($) { @@ -794,7 +789,7 @@ jQuery(function($) {
794 var options = {body: message.body, icon: avatar, tag: jid_id}; 789 var options = {body: message.body, icon: avatar, tag: jid_id};
795 console.log('Notify '+name); 790 console.log('Notify '+name);
796 $(notifyMe(name, options)).on('click', function(){ 791 $(notifyMe(name, options)).on('click', function(){
797 - open_chat_window('#'+jid+'/'+name); 792 + open_chat_window(jid);
798 }); 793 });
799 $.sound.play('/sounds/receive.wav'); 794 $.sound.play('/sounds/receive.wav');
800 } 795 }