comparison mod_cloud_notify/mod_cloud_notify.lua @ 3079:2a918a8c47db

mod_cloud_notify: use next() instead of # operator and update README
author tmolitor <thilo@eightysoft.de>
date Fri, 01 Jun 2018 18:24:34 +0200
parents 6b860de18a53
children 1ea6861b533f
comparison
equal deleted inserted replaced
3078:6b860de18a53 3079:2a918a8c47db
6 6
7 local t_insert = table.insert; 7 local t_insert = table.insert;
8 local s_match = string.match; 8 local s_match = string.match;
9 local s_sub = string.sub; 9 local s_sub = string.sub;
10 local os_time = os.time; 10 local os_time = os.time;
11 local next = next;
11 local st = require"util.stanza"; 12 local st = require"util.stanza";
12 local jid = require"util.jid"; 13 local jid = require"util.jid";
13 local dataform = require"util.dataforms".new; 14 local dataform = require"util.dataforms".new;
14 local filters = require"util.filters"; 15 local filters = require"util.filters";
15 local hashes = require"util.hashes"; 16 local hashes = require"util.hashes";
358 }; 359 };
359 360
360 -- http://xmpp.org/extensions/xep-0357.html#publishing 361 -- http://xmpp.org/extensions/xep-0357.html#publishing
361 local function handle_notify_request(stanza, node, user_push_services) 362 local function handle_notify_request(stanza, node, user_push_services)
362 local pushes = 0; 363 local pushes = 0;
363 if not user_push_services or not #user_push_services then return pushes end 364 if not user_push_services or next(user_push_services) == nil then return pushes end
364 365
365 for push_identifier, push_info in pairs(user_push_services) do 366 for push_identifier, push_info in pairs(user_push_services) do
366 local send_push = true; -- only send push to this node when not already done for this stanza or if no stanza is given at all 367 local send_push = true; -- only send push to this node when not already done for this stanza or if no stanza is given at all
367 if stanza then 368 if stanza then
368 if not stanza._push_notify then stanza._push_notify = {}; end 369 if not stanza._push_notify then stanza._push_notify = {}; end
494 to = to and jid.split(to) or event.origin.username; 495 to = to and jid.split(to) or event.origin.username;
495 496
496 -- only notify if the stanza destination is the mam user we store it for 497 -- only notify if the stanza destination is the mam user we store it for
497 if event.for_user == to then 498 if event.for_user == to then
498 local user_push_services = push_store:get(to); 499 local user_push_services = push_store:get(to);
499 if not #user_push_services then return end 500 if next(user_push_services) == nil then return end
500 501
501 -- only notify nodes with no active sessions (smacks is counted as active and handled separate) 502 -- only notify nodes with no active sessions (smacks is counted as active and handled separate)
502 local notify_push_sevices = {}; 503 local notify_push_sevices = {};
503 for identifier, push_info in pairs(user_push_services) do 504 for identifier, push_info in pairs(user_push_services) do
504 local identifier_found = nil; 505 local identifier_found = nil;