| ... | ... |
@@ -96,57 +96,11 @@ class WsRosterController < WsController |
| 96 | 96 |
## |
| 97 | 97 |
# Zacni pocuvat zmeny stavov v rosteri |
| 98 | 98 |
def start_polling_contacts_state |
| 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 |
|
| 105 |
- roster.add_subscription_callback do |roster_item, stanza| |
|
| 106 |
- # stan unsubscribe = niekto uz ma nesubscribuje |
|
| 107 |
- # stan unsubscribed = niekto ma uz nesubscribuje a aj si ma vymazal |
|
| 108 |
- # stan subscribed = niekto moze vidiet moj stav |
|
| 109 |
- |
|
| 110 |
- client = connection_store[:link_roster_client][roster] |
|
| 111 |
- |
|
| 112 |
- send_message 'app.roster.subscriptionChanged', |
|
| 113 |
- action: stanza.type, |
|
| 114 |
- jid: roster_item.jid.strip.to_s, |
|
| 115 |
- belongsTo: client.jid.strip.to_s |
|
| 116 |
- end |
|
| 117 |
- |
|
| 118 |
- #presence |
|
| 119 |
- roster.add_presence_callback do |roster_item, old_presence, new_presence| |
|
| 120 |
- if new_presence.type == :unavailable |
|
| 121 |
- result = {message: ''}
|
|
| 122 |
- |
|
| 123 |
- unless connection_store[:presences][roster_item.jid.strip.to_s].nil? |
|
| 124 |
- connection_store[:presences][roster_item.jid.strip.to_s.to_sym].delete(new_presence.from.to_s) |
|
| 125 |
- end |
|
| 126 |
- |
|
| 127 |
- # mozno treba vyhodit cloveka z multichatu, ak som jeho owner |
|
| 128 |
- #kick_from_all_multichats(roster_item.jid.to_s) |
|
| 129 |
- else |
|
| 130 |
- status = uniform_presence(new_presence.show) |
|
| 131 |
- result = {message: new_presence.status.to_s}
|
|
| 132 |
- |
|
| 133 |
- if connection_store[:presences][roster_item.jid.strip.to_s.to_sym].nil? |
|
| 134 |
- connection_store[:presences][roster_item.jid.strip.to_s.to_sym] = Hash.new() |
|
| 135 |
- end |
|
| 136 |
- |
|
| 137 |
- connection_store[:presences][roster_item.jid.strip.to_s][new_presence.from.to_s.to_sym] = {
|
|
| 138 |
- status: status, |
|
| 139 |
- multichat: false |
|
| 140 |
- } |
|
| 141 |
- |
|
| 142 |
- ask_if_using_this_app(connection_store[:link_roster_client][roster], new_presence.from.strip.to_s) |
|
| 143 |
- end |
|
| 144 |
- |
|
| 145 |
- result[:status] = select_most_online_status(roster_item.jid.strip.to_s) |
|
| 99 |
+ start_polling_control_answer() |
|
| 146 | 100 |
|
| 147 |
- send_message 'app.roster.statusChanged', |
|
| 148 |
- jid: roster_item.jid.strip.to_s, status: result |
|
| 149 |
- end |
|
| 101 |
+ connection_store[:rosters].each do |roster| |
|
| 102 |
+ start_polling_subscription(roster) |
|
| 103 |
+ start_polling_presence(roster) |
|
| 150 | 104 |
end |
| 151 | 105 |
end |
| 152 | 106 |
|
| ... | ... |
@@ -292,6 +246,55 @@ class WsRosterController < WsController |
| 292 | 292 |
end |
| 293 | 293 |
end |
| 294 | 294 |
|
| 295 |
+ def start_polling_presence(roster) |
|
| 296 |
+ roster.add_presence_callback do |roster_item, old_presence, new_presence| |
|
| 297 |
+ if new_presence.type == :unavailable |
|
| 298 |
+ result = {message: ''}
|
|
| 299 |
+ |
|
| 300 |
+ unless connection_store[:presences][roster_item.jid.strip.to_s].nil? |
|
| 301 |
+ connection_store[:presences][roster_item.jid.strip.to_s.to_sym].delete(new_presence.from.to_s) |
|
| 302 |
+ end |
|
| 303 |
+ |
|
| 304 |
+ # mozno treba vyhodit cloveka z multichatu, ak som jeho owner |
|
| 305 |
+ #kick_from_all_multichats(roster_item.jid.to_s) |
|
| 306 |
+ else |
|
| 307 |
+ status = uniform_presence(new_presence.show) |
|
| 308 |
+ result = {message: new_presence.status.to_s}
|
|
| 309 |
+ |
|
| 310 |
+ if connection_store[:presences][roster_item.jid.strip.to_s.to_sym].nil? |
|
| 311 |
+ connection_store[:presences][roster_item.jid.strip.to_s.to_sym] = Hash.new() |
|
| 312 |
+ end |
|
| 313 |
+ |
|
| 314 |
+ connection_store[:presences][roster_item.jid.strip.to_s][new_presence.from.to_s.to_sym] = {
|
|
| 315 |
+ status: status, |
|
| 316 |
+ multichat: false |
|
| 317 |
+ } |
|
| 318 |
+ |
|
| 319 |
+ ask_if_using_this_app(connection_store[:link_roster_client][roster], new_presence.from.strip.to_s) |
|
| 320 |
+ end |
|
| 321 |
+ |
|
| 322 |
+ result[:status] = select_most_online_status(roster_item.jid.strip.to_s) |
|
| 323 |
+ |
|
| 324 |
+ send_message 'app.roster.statusChanged', |
|
| 325 |
+ jid: roster_item.jid.strip.to_s, status: result |
|
| 326 |
+ end |
|
| 327 |
+ end |
|
| 328 |
+ |
|
| 329 |
+ def start_polling_subscription(roster) |
|
| 330 |
+ roster.add_subscription_callback do |roster_item, stanza| |
|
| 331 |
+ # stan unsubscribe = niekto uz ma nesubscribuje |
|
| 332 |
+ # stan unsubscribed = niekto ma uz nesubscribuje a aj si ma vymazal |
|
| 333 |
+ # stan subscribed = niekto moze vidiet moj stav |
|
| 334 |
+ |
|
| 335 |
+ client = connection_store[:link_roster_client][roster] |
|
| 336 |
+ |
|
| 337 |
+ send_message 'app.roster.subscriptionChanged', |
|
| 338 |
+ action: stanza.type, |
|
| 339 |
+ jid: roster_item.jid.strip.to_s, |
|
| 340 |
+ belongsTo: client.jid.strip.to_s |
|
| 341 |
+ end |
|
| 342 |
+ end |
|
| 343 |
+ |
|
| 295 | 344 |
def ask_if_using_this_app(client, contact) |
| 296 | 345 |
return unless connection_store[:presences][contact] |
| 297 | 346 |
|