Browse code

FIX: akcia po odpojeni klienta z multichatu

Cinan Rakosnik authored on 07/05/2013 at 22:16:18
Showing 3 changed files
... ...
@@ -3,11 +3,9 @@ class WsChatController < WsController
3 3
     def start_polling_messages
4 4
         connection_store[:clients].each do |client|
5 5
             client.add_message_callback do |message|
6
-                chat_id = message.attribute('chat_id').to_s
7
-
8 6
                 #noinspection RubyAssignmentExpressionInConditionalInspection
9 7
                 if message.body
10
-                    process_incoming_message(message.from, message.to, message.body, chat_id)
8
+                    process_incoming_message(message.from, message.to, message.body, message.attribute('chat_id').to_s)
11 9
                 #elsif request = message.first_element('sync_contacts_request')
12 10
                 #    # toto mozem prijat len ako admin multichatu
13 11
                 #    send_contacts(message.from, message.to, request.attribute('chat_id').to_s)
... ...
@@ -18,12 +16,12 @@ class WsChatController < WsController
18 18
                 elsif answer = message.first_element('exported_chat')
19 19
                     contacts = xml_contacts_to_array(message.first_element('exported_chat'))
20 20
                     import_people_in_chat(message.from, message.to, answer.attribute('chat_id').to_s, contacts)
21
-                #elsif message.attribute('destroy_multichat')
22
-                #    destroy_multichat(to, chat_id)
23
-                #elsif message.attribute('req_update_contacts')
24
-                #    added   = xml_contacts_to_array(message.first_element('added'))
25
-                #    removed = xml_contacts_to_array(message.first_element('removed'))
26
-                #    update_attendants_in_multichat(message.from, message.to, chat_id, removed, added)
21
+                elsif message.attribute('destroy_multichat')
22
+                    destroy_multichat(message.to, message.attribute('chat_id').to_s)
23
+                elsif message.attribute('req_update_contacts')
24
+                    added   = xml_contacts_to_array(message.first_element('added'))
25
+                    removed = xml_contacts_to_array(message.first_element('removed'))
26
+                    update_attendants_in_multichat(message.from, message.to, message.attribute('chat_id').to_s, removed, added)
27 27
                 end
28 28
                 #TODO: upozornit na pisanie spravy
29 29
                 #TODO: odoslat informaciu o tom, ze pisem spravu
... ...
@@ -124,7 +122,7 @@ class WsChatController < WsController
124 124
     def i_closed_multichat
125 125
         chat_id = message[:chatId]
126 126
         client  = find_client(message[:me])
127
-        me      = client.jid.strip.to_s
127
+        me      = client.jid.to_s
128 128
         owner   = connection_store[:opened_chats][client][chat_id][:owner]
129 129
 
130 130
         if owner == me
... ...
@@ -156,8 +154,8 @@ class WsChatController < WsController
156 156
         client.send(MessageBuilder::send_multichat_contacts(client.jid.strip.to_s, from, chat_id, contacts))
157 157
     end
158 158
 
159
-    def update_attendants_in_multichat(from, to, chat_id, removed, added)
160
-        client = find_client(to)
159
+    def update_attendants_in_multichat(owner, me, chat_id, removed, added)
160
+        client = find_client(me.strip.to_s)
161 161
 
162 162
         contacts = connection_store[:opened_chats][client][chat_id][:attendants]
163 163
         contacts -= removed
... ...
@@ -166,13 +164,13 @@ class WsChatController < WsController
166 166
         connection_store[:opened_chats][client][chat_id][:attendants] = contacts
167 167
 
168 168
         if contacts.empty?
169
-            destroy_multichat(to, chat_id)
169
+            destroy_multichat(me, chat_id)
170 170
         else
171 171
             contacts.each do |contact|
172
-                client.send(MessageBuilder::send_multichat_contacts(to, contact, chat_id, contacts))
172
+                client.send(MessageBuilder::send_multichat_contacts(me.to_s, contact, chat_id, contacts))
173 173
             end
174 174
 
175
-            sync_contacts_frontend(from, to, chat_id, contacts)
175
+            sync_contacts_frontend(owner, me, chat_id, contacts)
176 176
         end
177 177
     end
178 178
 end
179 179
\ No newline at end of file
... ...
@@ -20,9 +20,9 @@ class WsController < WebsocketRails::BaseController
20 20
         if connection_store[:opened_chats]
21 21
             connection_store[:clients].each do |client|
22 22
                 connection_store[:opened_chats][client].each do |chat_id, contacts|
23
-                #    if contacts[:owner] == client.jid.strip.to_s
24
-                #        chats_owner[client] = chat_id
25
-                #    end
23
+                    if contacts[:owner] == client.jid.to_s
24
+                        chats_owner[client] = chat_id
25
+                    end
26 26
                 end
27 27
             end
28 28
         end
... ...
@@ -34,30 +34,30 @@ class WsController < WebsocketRails::BaseController
34 34
         chats = where_i_am_multichat_owner()
35 35
         chats.each do |client, chat_id|
36 36
             contacts = connection_store[:opened_chats][client][chat_id][:attendants]
37
-            contacts -= [kick]
37
+            contacts -= [kick.to_s]
38 38
 
39 39
             if contacts.empty?
40
-                destroy_multichat(client.jid.strip.to_s, chat_id)
40
+                destroy_multichat(client.jid, chat_id)
41 41
             else
42 42
                 contacts.each do |contact|
43
-                    client.send(MessageBuilder::send_multichat_contacts(client.jid.strip.to_s, contact, chat_id, contacts))
43
+                    client.send(MessageBuilder::send_multichat_contacts(client.jid.to_s, contact, chat_id, contacts))
44 44
                 end
45 45
 
46
-                sync_contacts_frontend('', client.jid.strip.to_s, chat_id, contacts)
46
+                sync_contacts_frontend(client.jid, client.jid, chat_id, contacts)
47 47
             end
48 48
         end
49 49
     end
50 50
 
51
-    def sync_contacts_frontend(from, to, chat_id, contacts)
51
+    def sync_contacts_frontend(owner, me, chat_id, contacts)
52 52
         send_message 'app.chat.updateSyncedContacts',
53
-                     me: to,
54
-                     contacts: contacts,
55
-                     owner: from,
53
+                     me: me.strip.to_s,
54
+                     contacts: strip_all(contacts),
55
+                     owner: owner.strip.to_s,
56 56
                      chat_id: chat_id
57 57
     end
58 58
 
59
-    def destroy_multichat(to, chat_id)
60
-        client = find_client(to)
59
+    def destroy_multichat(me, chat_id)
60
+        client = find_client(me.strip.to_s)
61 61
         connection_store[:opened_chats][client].delete(chat_id)
62 62
 
63 63
         send_message 'app.chat.destroyMultichat', chat_id: chat_id
... ...
@@ -256,7 +256,7 @@ class WsRosterController < WsController
256 256
                 end
257 257
 
258 258
                 # mozno treba vyhodit cloveka z multichatu, ak som jeho owner
259
-                #kick_from_all_multichats(roster_item.jid.to_s)
259
+                kick_from_all_multichats(new_presence.from)
260 260
             else
261 261
                 status = uniform_presence(new_presence.show)
262 262
                 result = {message: new_presence.status.to_s}