Commit 41d26bb77ee4cfd1bb0e9ec3eb93647085920bdf
1 parent
c6665719
Exists in
staging
and in
3 other branches
chat-workarounds: get roster groups and friends from noosfero
This patch is part of several workarounds done to fix ejabberd problems with usernames bigger than 8 chars. For more information check: https://github.com/processone/ejabberd/issues/1152
Showing
2 changed files
with
25 additions
and
15 deletions
Show diff stats
app/controllers/public/chat_controller.rb
| ... | ... | @@ -113,8 +113,11 @@ class ChatController < PublicController |
| 113 | 113 | end |
| 114 | 114 | |
| 115 | 115 | #TODO Ideally this is done through roster table on ejabberd. |
| 116 | - def roster_groups | |
| 117 | - render :text => user.memberships.map {|m| {:jid => m.jid, :name => m.name}}.to_json | |
| 116 | + def rosters | |
| 117 | + rooms = user.memberships.map {|m| {:jid => m.jid, :name => m.name}} | |
| 118 | + friends = user.friends.map {|f| {:jid => f.jid, :name => f.name}} | |
| 119 | + rosters = {:rooms => rooms, :friends => friends} | |
| 120 | + render :text => rosters.to_json | |
| 118 | 121 | end |
| 119 | 122 | |
| 120 | 123 | protected | ... | ... |
public/javascripts/chat.js
| ... | ... | @@ -271,27 +271,35 @@ jQuery(function($) { |
| 271 | 271 | var contacts_to_insert = {}; |
| 272 | 272 | var groups_to_insert = []; |
| 273 | 273 | |
| 274 | - $(iq).find('item').each(function () { | |
| 275 | - var jid = $(this).attr('jid'); | |
| 276 | - profiles.push(getIdentifier(jid)); | |
| 277 | - var name = $(this).attr('name') || jid; | |
| 278 | - var jid_id = Jabber.jid_to_id(jid); | |
| 279 | - contacts_to_insert[jid] = name; | |
| 280 | - }); | |
| 274 | + //FIXME User ejabberd roster when the username length limit bug is solved. | |
| 275 | + // $(iq).find('item').each(function () { | |
| 276 | + // var jid = $(this).attr('jid'); | |
| 277 | + // profiles.push(getIdentifier(jid)); | |
| 278 | + // var name = $(this).attr('name') || jid; | |
| 279 | + // var jid_id = Jabber.jid_to_id(jid); | |
| 280 | + // contacts_to_insert[jid] = name; | |
| 281 | + // }); | |
| 281 | 282 | |
| 282 | - //TODO Add groups through roster too... | |
| 283 | 283 | $.ajax({ |
| 284 | - url: '/chat/roster_groups', | |
| 285 | - dataType: 'json', | |
| 284 | + url: '/chat/rosters', | |
| 285 | + dataType: 'json,' | |
| 286 | 286 | success: function(data){ |
| 287 | - $(data).each(function(index, room){ | |
| 287 | + $(data.friends).each(function(index, friend){ | |
| 288 | + var jid = friend.jid; | |
| 289 | + profiles.push(getIdentifier(jid)); | |
| 290 | + var name = friend.name; | |
| 291 | + var jid_id = Jabber.jid_to_id(jid); | |
| 292 | + contacts_to_insert[jid] = name; | |
| 293 | + }); | |
| 294 | + | |
| 295 | + $(data.rooms).each(function(index, room){ | |
| 288 | 296 | profiles.push(getIdentifier(room.jid)); |
| 289 | 297 | var jid_id = Jabber.jid_to_id(room.jid); |
| 290 | 298 | Jabber.jids[jid_id] = {jid: room.jid, name: room.name, type: 'groupchat'}; |
| 291 | 299 | //FIXME This must check on session if the user is inside the room... |
| 292 | 300 | groups_to_insert.push(room.jid); |
| 293 | - | |
| 294 | 301 | }); |
| 302 | + | |
| 295 | 303 | $.getJSON('/chat/avatars', {profiles: profiles}, function(data) { |
| 296 | 304 | for(identifier in data) |
| 297 | 305 | Jabber.avatars[identifier] = data[identifier]; |
| ... | ... | @@ -319,7 +327,6 @@ jQuery(function($) { |
| 319 | 327 | console.log(data); |
| 320 | 328 | }, |
| 321 | 329 | }); |
| 322 | - | |
| 323 | 330 | }, |
| 324 | 331 | |
| 325 | 332 | // NOTE: cause Noosfero store's rosters in database based on friendship relation between people | ... | ... |