comparison mod_cloud_notify/mod_cloud_notify.lua @ 2643:777d07e0cd73

mod_cloud_notify: Whitespace fixes
author Matthew Wild <mwild1@gmail.com>
date Thu, 23 Mar 2017 09:19:52 +0000
parents 0f1421af7f6a
children e6d243ed88ca
comparison
equal deleted inserted replaced
2642:0f1421af7f6a 2643:777d07e0cd73
62 local stanza = event.stanza; 62 local stanza = event.stanza;
63 local error_type, condition = stanza:get_error(); 63 local error_type, condition = stanza:get_error();
64 local node = jid.split(stanza.attr.to); 64 local node = jid.split(stanza.attr.to);
65 local from = stanza.attr.from; 65 local from = stanza.attr.from;
66 local user_push_services = push_store:get(node); 66 local user_push_services = push_store:get(node);
67 67
68 for push_identifier, _ in pairs(user_push_services) do 68 for push_identifier, _ in pairs(user_push_services) do
69 if hashes.sha256(push_identifier, true) == stanza.attr.id then 69 if hashes.sha256(push_identifier, true) == stanza.attr.id then
70 if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type ~= "wait" then 70 if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and error_type ~= "wait" then
71 push_errors[push_identifier] = push_errors[push_identifier] + 1; 71 push_errors[push_identifier] = push_errors[push_identifier] + 1;
72 module:log("info", "Got error of type '%s' (%s) for identifier '%s': " 72 module:log("info", "Got error of type '%s' (%s) for identifier '%s': "
100 function handle_push_success(event) 100 function handle_push_success(event)
101 local stanza = event.stanza; 101 local stanza = event.stanza;
102 local node = jid.split(stanza.attr.to); 102 local node = jid.split(stanza.attr.to);
103 local from = stanza.attr.from; 103 local from = stanza.attr.from;
104 local user_push_services = push_store:get(node); 104 local user_push_services = push_store:get(node);
105 105
106 for push_identifier, _ in pairs(user_push_services) do 106 for push_identifier, _ in pairs(user_push_services) do
107 if hashes.sha256(push_identifier, true) == stanza.attr.id then 107 if hashes.sha256(push_identifier, true) == stanza.attr.id then
108 if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and push_errors[push_identifier] then 108 if user_push_services[push_identifier] and user_push_services[push_identifier].jid == from and push_errors[push_identifier] then
109 push_errors[push_identifier] = 0; 109 push_errors[push_identifier] = 0;
110 module:log("debug", "Push succeeded, error count for identifier '%s' is now at %s", push_identifier, tostring(push_errors[push_identifier])); 110 module:log("debug", "Push succeeded, error count for identifier '%s' is now at %s", push_identifier, tostring(push_errors[push_identifier]));
211 module:log("debug", "Already sent push notification for %s@%s to %s (%s)", node, module.host, push_info.jid, tostring(push_info.node)); 211 module:log("debug", "Already sent push notification for %s@%s to %s (%s)", node, module.host, push_info.jid, tostring(push_info.node));
212 return; 212 return;
213 end 213 end
214 stanza._push_notify[push_identifier] = true; 214 stanza._push_notify[push_identifier] = true;
215 end 215 end
216 216
217 -- increment count and save it 217 -- increment count and save it
218 push_info.count = push_info.count + 1; 218 push_info.count = push_info.count + 1;
219 push_store:set_identifier(node, push_identifier, push_info); 219 push_store:set_identifier(node, push_identifier, push_info);
220 -- construct push stanza 220 -- construct push stanza
221 local push_publish = st.iq({ to = push_info.jid, from = node .. "@" .. module.host, type = "set", id = hashes.sha256(push_identifier, true) }) 221 local push_publish = st.iq({ to = push_info.jid, from = node .. "@" .. module.host, type = "set", id = hashes.sha256(push_identifier, true) })
318 if not event.for_user or not host_sessions[event.for_user] then return; end 318 if not event.for_user or not host_sessions[event.for_user] then return; end
319 local stanza = event.stanza; 319 local stanza = event.stanza;
320 local user_session = host_sessions[event.for_user].sessions; 320 local user_session = host_sessions[event.for_user].sessions;
321 local to = stanza.attr.to; 321 local to = stanza.attr.to;
322 to = to and jid.split(to) or event.origin.username; 322 to = to and jid.split(to) or event.origin.username;
323 323
324 -- only notify if the stanza destination is the mam user we store it for 324 -- only notify if the stanza destination is the mam user we store it for
325 if event.for_user == to then 325 if event.for_user == to then
326 local user_push_services = push_store:get(to); 326 local user_push_services = push_store:get(to);
327 if not #user_push_services then return end 327 if not #user_push_services then return end
328 328
341 identifier_found.log("debug", "Not notifying '%s' of new MAM stanza (session still alive)", identifier); 341 identifier_found.log("debug", "Not notifying '%s' of new MAM stanza (session still alive)", identifier);
342 else 342 else
343 notify_push_sevices[identifier] = push_info; 343 notify_push_sevices[identifier] = push_info;
344 end 344 end
345 end 345 end
346 346
347 return handle_notify_request(event.stanza, to, notify_push_sevices); 347 return handle_notify_request(event.stanza, to, notify_push_sevices);
348 end 348 end
349 end 349 end
350 350
351 module:hook("smacks-hibernation-start", hibernate_session); 351 module:hook("smacks-hibernation-start", hibernate_session);
380 module:log("info", "Module loaded"); 380 module:log("info", "Module loaded");
381 function module.unload() 381 function module.unload()
382 module:unhook("account-disco-info", account_dico_info); 382 module:unhook("account-disco-info", account_dico_info);
383 module:unhook("iq-set/self/"..xmlns_push..":enable", push_enable); 383 module:unhook("iq-set/self/"..xmlns_push..":enable", push_enable);
384 module:unhook("iq-set/self/"..xmlns_push..":disable", push_disable); 384 module:unhook("iq-set/self/"..xmlns_push..":disable", push_disable);
385 385
386 module:unhook("smacks-hibernation-start", hibernate_session); 386 module:unhook("smacks-hibernation-start", hibernate_session);
387 module:unhook("smacks-hibernation-end", restore_session); 387 module:unhook("smacks-hibernation-end", restore_session);
388 module:unhook("smacks-ack-delayed", ack_delayed); 388 module:unhook("smacks-ack-delayed", ack_delayed);
389 module:unhook("archive-message-added", archive_message_added); 389 module:unhook("archive-message-added", archive_message_added);
390 module:unhook("cloud-notify-ping", send_ping); 390 module:unhook("cloud-notify-ping", send_ping);
391 391
392 for push_identifier, _ in pairs(push_errors) do 392 for push_identifier, _ in pairs(push_errors) do
393 module:hook("iq-error/bare/"..hashes.sha256(push_identifier, true), handle_push_error); 393 module:hook("iq-error/bare/"..hashes.sha256(push_identifier, true), handle_push_error);
394 module:hook("iq-result/bare/"..hashes.sha256(push_identifier, true), handle_push_success); 394 module:hook("iq-result/bare/"..hashes.sha256(push_identifier, true), handle_push_success);
395 end 395 end
396 396
397 module:log("info", "Module unloaded"); 397 module:log("info", "Module unloaded");
398 end 398 end