... | ... |
@@ -47,9 +47,6 @@ this.App = |
47 | 47 |
startPollingMessages: -> |
48 | 48 |
App.Com.trigger(event: 'app.chat.startPollingMessages') |
49 | 49 |
|
50 |
- whoUseThisApp: -> |
|
51 |
- App.Com.trigger(event: 'app.roster.whoUseThisApp') |
|
52 |
- |
|
53 | 50 |
setPresence: -> |
54 | 51 |
App.Com.trigger(event: 'app.roster.setPresence') |
55 | 52 |
|
... | ... |
@@ -97,6 +97,11 @@ class WsRosterController < WsController |
97 | 97 |
# Zacni pocuvat zmeny stavov v rosteri |
98 | 98 |
def start_polling_contacts_state |
99 | 99 |
connection_store[:rosters].each do |roster| |
100 |
+ start_polling_control_answer() |
|
101 |
+ #start_polling_subscription(roster) |
|
102 |
+ #start_polling_presence(roster) |
|
103 |
+ |
|
104 |
+ #subscription |
|
100 | 105 |
roster.add_subscription_callback do |roster_item, stanza| |
101 | 106 |
# stan unsubscribe = niekto uz ma nesubscribuje |
102 | 107 |
# stan unsubscribed = niekto ma uz nesubscribuje a aj si ma vymazal |
... | ... |
@@ -110,12 +115,13 @@ class WsRosterController < WsController |
110 | 110 |
belongsTo: client.jid.strip.to_s |
111 | 111 |
end |
112 | 112 |
|
113 |
+ #presence |
|
113 | 114 |
roster.add_presence_callback do |roster_item, old_presence, new_presence| |
114 | 115 |
if new_presence.type == :unavailable |
115 | 116 |
result = {message: ''} |
116 | 117 |
|
117 | 118 |
unless connection_store[:presences][roster_item.jid.strip.to_s].nil? |
118 |
- connection_store[:presences][roster_item.jid.strip.to_s].delete(new_presence.from.to_s) |
|
119 |
+ connection_store[:presences][roster_item.jid.strip.to_s.to_sym].delete(new_presence.from.to_s) |
|
119 | 120 |
end |
120 | 121 |
|
121 | 122 |
# mozno treba vyhodit cloveka z multichatu, ak som jeho owner |
... | ... |
@@ -124,14 +130,16 @@ class WsRosterController < WsController |
124 | 124 |
status = uniform_presence(new_presence.show) |
125 | 125 |
result = {message: new_presence.status.to_s} |
126 | 126 |
|
127 |
- if connection_store[:presences][roster_item.jid.strip.to_s].nil? |
|
128 |
- connection_store[:presences][roster_item.jid.strip.to_s] = Hash.new() |
|
127 |
+ if connection_store[:presences][roster_item.jid.strip.to_s.to_sym].nil? |
|
128 |
+ connection_store[:presences][roster_item.jid.strip.to_s.to_sym] = Hash.new() |
|
129 | 129 |
end |
130 | 130 |
|
131 |
- connection_store[:presences][roster_item.jid.strip.to_s][new_presence.from.to_s] = { |
|
131 |
+ connection_store[:presences][roster_item.jid.strip.to_s][new_presence.from.to_s.to_sym] = { |
|
132 | 132 |
status: status, |
133 | 133 |
multichat: false |
134 | 134 |
} |
135 |
+ |
|
136 |
+ ask_if_using_this_app(connection_store[:link_roster_client][roster], new_presence.from.strip.to_s) |
|
135 | 137 |
end |
136 | 138 |
|
137 | 139 |
result[:status] = select_most_online_status(roster_item.jid.strip.to_s) |
... | ... |
@@ -228,18 +236,6 @@ class WsRosterController < WsController |
228 | 228 |
end |
229 | 229 |
end |
230 | 230 |
|
231 |
- def ask_if_using_this_app |
|
232 |
- connection_store[:rosters].each do |roster| |
|
233 |
- client = connection_store[:link_roster_client][roster] |
|
234 |
- |
|
235 |
- roster.items.each do |jid, contact| |
|
236 |
- client.send(MessageBuilder::control_question(client.jid.strip.to_s, jid)) |
|
237 |
- end |
|
238 |
- end |
|
239 |
- |
|
240 |
- start_polling_control_answer() |
|
241 |
- end |
|
242 |
- |
|
243 | 231 |
## |
244 | 232 |
# Pridaj noveho priatela do zoznamu |
245 | 233 |
def add_friend(data) |
... | ... |
@@ -285,12 +281,22 @@ class WsRosterController < WsController |
285 | 285 |
connection_store[:clients].each do |client| |
286 | 286 |
client.add_message_callback do |message| |
287 | 287 |
if message.attribute('i_am_using_same_app') |
288 |
+ connection_store[:presences][message.from.strip.to_s][message.from.to_s.to_sym][multichat: true] |
|
289 |
+ |
|
288 | 290 |
send_message 'app.roster.using_this_app', |
289 |
- jid: message.from.node + '@' + message.from.domain |
|
291 |
+ jid: message.from.strip.to_s |
|
290 | 292 |
elsif message.attribute('are_you_using_my_app') |
291 |
- client.send(MessageBuilder::control_answer(client.jid.strip.to_s, message.from)) |
|
293 |
+ client.send(MessageBuilder::control_answer(client.jid.to_s, message.from.to_s)) |
|
292 | 294 |
end |
293 | 295 |
end |
294 | 296 |
end |
295 | 297 |
end |
298 |
+ |
|
299 |
+ def ask_if_using_this_app(client, contact) |
|
300 |
+ return unless connection_store[:presences][contact] |
|
301 |
+ |
|
302 |
+ connection_store[:presences][contact].each do |jid_resource, state| |
|
303 |
+ client.send(MessageBuilder::control_question(client.jid.to_s, jid_resource.to_s)) |
|
304 |
+ end |
|
305 |
+ end |
|
296 | 306 |
end |
... | ... |
@@ -57,7 +57,6 @@ WebsocketRails::EventMap.describe do |
57 | 57 |
subscribe :updateMyStatus, to: WsRosterController, with_method: :me_update_status |
58 | 58 |
subscribe :updateMyVcard, to: WsRosterController, with_method: :me_update_vcard |
59 | 59 |
subscribe :removeContact, to: WsRosterController, with_method: :remove_contact |
60 |
- subscribe :whoUseThisApp, to: WsRosterController, with_method: :ask_if_using_this_app |
|
61 | 60 |
end |
62 | 61 |
|
63 | 62 |
namespace :chat do |