Commit cfb0d900bc267205040bb66153b2dcfdb25d4de2

Authored by Daniela Feitosa
1 parent 36553bc6

Fixed chat

- Syntax error on chat
- Reviewed INSTALL.chat
- Added function to update the list of users online on main window

(ActionItem2667)
@@ -6,15 +6,13 @@ To configure XMPP/BOSH in Noosfero you need: @@ -6,15 +6,13 @@ To configure XMPP/BOSH in Noosfero you need:
6 * SystemTimer - http://ph7spot.com/musings/system-timer 6 * SystemTimer - http://ph7spot.com/musings/system-timer
7 * Pidgin data files - http://www.pidgin.im/ 7 * Pidgin data files - http://www.pidgin.im/
8 8
9 -If you use Debian Lenny: 9 +If you use Debian Wheezy:
10 10
11 -# apt-get install librestclient-ruby (from backports)  
12 -# apt-get install pidgin-data  
13 -# apt-get install ruby1.8-dev 11 +# apt-get install librestclient-ruby pidgin-data ruby1.8-dev
14 # gem install SystemTimer 12 # gem install SystemTimer
15 13
16 -Take a look at util/chat directory to see samples of config file to configure a  
17 -XMPP/BOSH server with ejabberd, postgresql and apache2. 14 +The samples of config file to configure a XMPP/BOSH server with
  15 +ejabberd, postgresql and apache2 can be found at util/chat directory.
18 16
19 == XMPP/Chat Server Setup 17 == XMPP/Chat Server Setup
20 18
@@ -22,8 +20,7 @@ This is a step-by-step guide to get a XMPP service working, in a Debian system. @@ -22,8 +20,7 @@ This is a step-by-step guide to get a XMPP service working, in a Debian system.
22 20
23 1. Install the required packages 21 1. Install the required packages
24 22
25 -# apt-get -t lenny-backports install ejabberd  
26 -# apt-get install odbc-postgresql 23 +# apt-get install ejabberd odbc-postgresql
27 24
28 2. Ejabberd configuration 25 2. Ejabberd configuration
29 26
@@ -108,7 +105,7 @@ Unused modules can be disabled, for example: @@ -108,7 +105,7 @@ Unused modules can be disabled, for example:
108 * web_admin 105 * web_admin
109 * mod_pubsub 106 * mod_pubsub
110 * mod_irc 107 * mod_irc
111 - * mod_offine 108 + * mod_offline
112 * mod_admin_extra 109 * mod_admin_extra
113 * mod_register 110 * mod_register
114 111
@@ -132,7 +129,7 @@ This will create a new schema inside the noosfero database, called 'ejabberd'. @@ -132,7 +129,7 @@ This will create a new schema inside the noosfero database, called 'ejabberd'.
132 129
133 Note 'noosfero' user should have permission to create Postgresql schemas. Also, 130 Note 'noosfero' user should have permission to create Postgresql schemas. Also,
134 there should be at least one domain with 'is_default = true' in 'domains' 131 there should be at least one domain with 'is_default = true' in 'domains'
135 -table, otherwise people couldn't see your friends online. 132 +table, otherwise people won't be able to see their friends online.
136 133
137 134
138 4. ODBC configuration 135 4. ODBC configuration
@@ -168,9 +165,12 @@ Debug = 0 @@ -168,9 +165,12 @@ Debug = 0
168 CommLog = 1 165 CommLog = 1
169 UsageCount = 3 166 UsageCount = 3
170 167
171 - * testing all: 168 + 4.1 testing all:
172 169
173 -# isql 'PostgreSQLEjabberdNoosfero' DBUSER 170 +# isql 'PostgreSQLEjabberdNoosfero'
  171 +
  172 +If the configuration was done right, the message "Connected!"
  173 +will be displayed.
174 174
175 175
176 5. Enabling kernel polling and SMP in /etc/default/ejabberd 176 5. Enabling kernel polling and SMP in /etc/default/ejabberd
app/models/user.rb
@@ -294,7 +294,8 @@ class User < ActiveRecord::Base @@ -294,7 +294,8 @@ class User < ActiveRecord::Base
294 'email_domain' => self.enable_email ? self.email_domain : nil, 294 'email_domain' => self.enable_email ? self.email_domain : nil,
295 'friends_list' => friends_list, 295 'friends_list' => friends_list,
296 'enterprises' => enterprises, 296 'enterprises' => enterprises,
297 - 'amount_of_friends' => friends_list.count 297 + 'amount_of_friends' => friends_list.count,
  298 + 'chat_enabled' => person.environment.enabled?('xmpp_chat')
298 } 299 }
299 end 300 end
300 301
app/views/shared/logged_in/xmpp_chat.rhtml
@@ -6,6 +6,6 @@ @@ -6,6 +6,6 @@
6 </div> 6 </div>
7 </div> 7 </div>
8 <a href='#' id='chat-online-users-title' onclick='return false;'> 8 <a href='#' id='chat-online-users-title' onclick='return false;'>
9 - <div class='header'><i class='icon-chat'></i><span><%= _("Friends in chat <span class='amount_of_friends'>(%{amount})</span>") %></span></div> 9 + <div class='header'><i class='icon-chat'></i><span><%= _("Friends in chat (<span class='amount_of_friends'>%{amount}</span>)") %></span></div>
10 </a> 10 </a>
11 </div> 11 </div>
public/javascripts/application.js
@@ -486,7 +486,9 @@ jQuery(function($) { @@ -486,7 +486,9 @@ jQuery(function($) {
486 // logged in 486 // logged in
487 loggedInDataCallBack(data); 487 loggedInDataCallBack(data);
488 addManageEnterprisesToOldStyleMenu(data); 488 addManageEnterprisesToOldStyleMenu(data);
489 - chatOnlineUsersDataCallBack(data); 489 + if (data.chat_enabled) {
  490 + setInterval(function(){ $.getJSON('/account/user_data', chatOnlineUsersDataCallBack)}, 10000);
  491 + }
490 } else { 492 } else {
491 // not logged in 493 // not logged in
492 $('#user .not-logged-in, .login-block .not-logged-user').fadeIn(); 494 $('#user .not-logged-in, .login-block .not-logged-user').fadeIn();
@@ -538,7 +540,7 @@ jQuery(function($) { @@ -538,7 +540,7 @@ jQuery(function($) {
538 return; 540 return;
539 } 541 }
540 var content = ''; 542 var content = '';
541 - $('#chat-online-users').html($('#chat-online-users').html().replace(/%{amount}/g, data['amount_of_friends'])); 543 + $('#chat-online-users .amount_of_friends').html(data['amount_of_friends']);
542 $('#chat-online-users').fadeIn(); 544 $('#chat-online-users').fadeIn();
543 for (var user in data['friends_list']) { 545 for (var user in data['friends_list']) {
544 var name = "<span class='friend_name'>%{name}</span>"; 546 var name = "<span class='friend_name'>%{name}</span>";
public/javascripts/chat.js
@@ -253,7 +253,7 @@ jQuery(function($) { @@ -253,7 +253,7 @@ jQuery(function($) {
253 result.show = 'away'; 253 result.show = 'away';
254 } 254 }
255 } 255 }
256 - if ($(stanza).find('x[xmlns='+ Strophe.NS.MUC_USER +']').length > 0) { 256 + if ($(stanza).find('x[xmlns="'+ Strophe.NS.MUC_USER +'"]').length > 0) {
257 result.is_from_room = true; 257 result.is_from_room = true;
258 result.from_user = $(stanza).find('x item').attr('jid'); 258 result.from_user = $(stanza).find('x item').attr('jid');
259 if ($(stanza).find('x item').attr('affiliation') == 'owner') { 259 if ($(stanza).find('x item').attr('affiliation') == 'owner') {
@@ -351,7 +351,7 @@ jQuery(function($) { @@ -351,7 +351,7 @@ jQuery(function($) {
351 }, 351 },
352 352
353 on_muc_support: function(iq) { 353 on_muc_support: function(iq) {
354 - if ($(iq).find('identity[category=conference]').length > 0 && $(iq).find('feature[var='+ Strophe.NS.MUC +']').length > 0) { 354 + if ($(iq).find('identity[category=conference]').length > 0 && $(iq).find('feature[var="'+ Strophe.NS.MUC +'"]').length > 0) {
355 var name = $(iq).find('identity[category=conference]').attr('name'); 355 var name = $(iq).find('identity[category=conference]').attr('name');
356 log('muc support found with identity '+ name); 356 log('muc support found with identity '+ name);
357 Jabber.muc_supported = true; 357 Jabber.muc_supported = true;
test/unit/user_test.rb
@@ -399,6 +399,19 @@ class UserTest &lt; ActiveSupport::TestCase @@ -399,6 +399,19 @@ class UserTest &lt; ActiveSupport::TestCase
399 assert_equal 15, User.expires_chat_status_every 399 assert_equal 15, User.expires_chat_status_every
400 end 400 end
401 401
  402 + should "return status of chat on environment in data_hash" do
  403 + person = create_user('coldplay').person
  404 + env = person.environment
  405 + env.enable('xmpp_chat')
  406 + env.save
  407 + assert_equal true, person.user.data_hash['chat_enabled']
  408 +
  409 + env.disable('xmpp_chat')
  410 + env.save
  411 + person.reload
  412 + assert_equal false, person.user.data_hash['chat_enabled']
  413 + end
  414 +
402 should 'respond name with related person name' do 415 should 'respond name with related person name' do
403 user = create_user('testuser') 416 user = create_user('testuser')
404 user.person.name = 'Test User' 417 user.person.name = 'Test User'