Browse code

Metoda na vytvorenie noveho multichatu

Cinan Rakosnik authored on 06/05/2013 at 12:56:27
Showing 2 changed files
... ...
@@ -42,14 +42,8 @@ class WsChatController < WsController
42 42
 
43 43
     def import_people_in_chat(from, to, chat_id, contacts)
44 44
         #Rails.logger.debug ['imported chat arrived', message.to_s, chat_id]
45
-
46 45
         client = find_client(to)
47
-
48
-        connection_store[:opened_chats] = {} if ! connection_store[:opened_chats]
49
-        connection_store[:opened_chats][client] = {} if ! connection_store[:opened_chats][client]
50
-        connection_store[:opened_chats][client][chat_id] = {attendants: contacts, owner: from}
51
-
52
-        #Rails.logger.debug [connection_store[:opened_chats][client], client.jid.to_s]
46
+        create_opened_chat(client, chat_id, from, contacts)
53 47
 
54 48
         send_message 'app.chat.importChat',
55 49
                      owner:    from,
... ...
@@ -61,14 +55,12 @@ class WsChatController < WsController
61 61
     def new_multichat
62 62
         me = message[:chatOwner]
63 63
         hash = Digest::SHA2.hexdigest(me)
64
-        id = hash + Time.now.to_f.to_s
64
+        chat_id = hash + Time.now.to_f.to_s
65 65
         client = find_client(me)
66 66
 
67
-        connection_store[:opened_chats] = {} if ! connection_store[:opened_chats]
68
-        connection_store[:opened_chats][client] = {} if ! connection_store[:opened_chats][client]
69
-        connection_store[:opened_chats][client][id] = {attendants: [], owner: me}
67
+        create_opened_chat(client, chat_id, me)
70 68
 
71
-        trigger_success id: id
69
+        trigger_success id: chat_id
72 70
     end
73 71
 
74 72
     # Owner posle novemu cloveku informaciu o chat_id a kontaktoch
... ...
@@ -2,6 +2,12 @@ class WsController < WebsocketRails::BaseController
2 2
 
3 3
     protected
4 4
 
5
+    def create_opened_chat(client, chat_id, owner = '', attendants = [])
6
+        connection_store[:opened_chats] = {} if ! connection_store[:opened_chats]
7
+        connection_store[:opened_chats][client] = {} if ! connection_store[:opened_chats][client]
8
+        connection_store[:opened_chats][client][chat_id] = {owner: owner, attendants: attendants}
9
+    end
10
+
5 11
     def find_client(client_jid)
6 12
         connection_store[:clients].find do |client|
7 13
             client.jid.strip.to_s == client_jid