Commit 7e781e2409528fb143362fee44e64445a9269975
Exists in
master
and in
29 other branches
Merge branch 'chat' of gitlab.com:diguliu/noosfero into chat
Showing
3 changed files
with
53 additions
and
52 deletions
Show diff stats
public/javascripts/application.js
@@ -587,20 +587,6 @@ function display_notice(message) { | @@ -587,20 +587,6 @@ 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) { | ||
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 | jQuery(function($) { | 590 | jQuery(function($) { |
605 | /* Adds a class to "opera" to the body element if Opera browser detected. | 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,19 +200,19 @@ jQuery(function($) { | ||
200 | $.post('/chat/join', {room_id: jid}); | 200 | $.post('/chat/join', {room_id: jid}); |
201 | }, | 201 | }, |
202 | 202 | ||
203 | - leave_room: function(room_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(room_jid); | 206 | + var jid_id = Jabber.jid_to_id(jid); |
207 | var conversation_id = Jabber.conversation_prefix + jid_id; | 207 | var conversation_id = Jabber.conversation_prefix + jid_id; |
208 | var button = $('#' + conversation_id + ' .leave'); | 208 | var button = $('#' + conversation_id + ' .leave'); |
209 | button.hide(); | 209 | button.hide(); |
210 | button.siblings('.join').show(); | 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 | sort_conversations(); | 213 | sort_conversations(); |
214 | if(push) | 214 | if(push) |
215 | - $.post('/chat/leave', {room_id: room_jid}); | 215 | + $.post('/chat/leave', {room_id: jid}); |
216 | }, | 216 | }, |
217 | 217 | ||
218 | update_chat_title: function () { | 218 | update_chat_title: function () { |
@@ -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 | ||
@@ -535,34 +534,6 @@ jQuery(function($) { | @@ -535,34 +534,6 @@ jQuery(function($) { | ||
535 | Jabber.connect(); | 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 | $('.conversation textarea').live('keydown', function(e) { | 537 | $('.conversation textarea').live('keydown', function(e) { |
567 | if (e.keyCode == 13) { | 538 | if (e.keyCode == 13) { |
568 | var jid = $(this).attr('data-to'); | 539 | var jid = $(this).attr('data-to'); |
@@ -609,6 +580,51 @@ jQuery(function($) { | @@ -609,6 +580,51 @@ jQuery(function($) { | ||
609 | $('.conversation textarea:visible').focus(); | 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 | function create_conversation_tab(title, jid_id) { | 628 | function create_conversation_tab(title, jid_id) { |
613 | var conversation_id = Jabber.conversation_prefix + jid_id; | 629 | var conversation_id = Jabber.conversation_prefix + jid_id; |
614 | var conversation = $('#' + conversation_id); | 630 | var conversation = $('#' + conversation_id); |
@@ -701,12 +717,11 @@ jQuery(function($) { | @@ -701,12 +717,11 @@ jQuery(function($) { | ||
701 | function load_defaults() { | 717 | function load_defaults() { |
702 | $.getJSON('/chat/my_session', {}, function(data) { | 718 | $.getJSON('/chat/my_session', {}, function(data) { |
703 | $.each(data.rooms, function(i, room_jid) { | 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 | $('#'+data.tab_id).click(); | 723 | $('#'+data.tab_id).click(); |
708 | 724 | ||
709 | - console.log(data); | ||
710 | if(data.status == 'opened') | 725 | if(data.status == 'opened') |
711 | toggle_chat_window(); | 726 | toggle_chat_window(); |
712 | }) | 727 | }) |
@@ -794,7 +809,7 @@ jQuery(function($) { | @@ -794,7 +809,7 @@ jQuery(function($) { | ||
794 | var options = {body: message.body, icon: avatar, tag: jid_id}; | 809 | var options = {body: message.body, icon: avatar, tag: jid_id}; |
795 | console.log('Notify '+name); | 810 | console.log('Notify '+name); |
796 | $(notifyMe(name, options)).on('click', function(){ | 811 | $(notifyMe(name, options)).on('click', function(){ |
797 | - open_chat_window('#'+jid+'/'+name); | 812 | + open_conversation(jid); |
798 | }); | 813 | }); |
799 | $.sound.play('/sounds/receive.wav'); | 814 | $.sound.play('/sounds/receive.wav'); |
800 | } | 815 | } |
public/stylesheets/chat.css
@@ -237,7 +237,7 @@ | @@ -237,7 +237,7 @@ | ||
237 | } | 237 | } |
238 | #chat-window .history .message p { | 238 | #chat-window .history .message p { |
239 | margin-left: 40px; | 239 | margin-left: 40px; |
240 | - word-break: break-all; | 240 | + word-wrap: break-word; |
241 | } | 241 | } |
242 | 242 | ||
243 | #chat-window .history .message.self p { | 243 | #chat-window .history .message.self p { |