Annotate

mod_muc_cloud_notify/mod_muc_cloud_notify.lua @ 3882:3b8f4f3b1718

mod_reload_modules: Ignore removed hosts...
author tmolitor <thilo@eightysoft.de>
date Wed, 05 Feb 2020 23:27:33 +0100
parent 3570:8a93af85f319
child 3883:571249f69577
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
1 -- XEP-XXX: MUC Push Notifications
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
2 -- Copyright (C) 2015-2016 Kim Alvefur
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
3 -- Copyright (C) 2017-2018 Thilo Molitor
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
4 --
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
5 -- This file is MIT/X11 licensed.
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
6
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
7 local s_match = string.match;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
8 local s_sub = string.sub;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
9 local os_time = os.time;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
10 local next = next;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
11 local st = require"util.stanza";
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
12 local jid = require"util.jid";
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
13 local dataform = require"util.dataforms".new;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
14 local hashes = require"util.hashes";
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
15
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
16 local xmlns_push = "urn:xmpp:push:0";
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
17
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
18 -- configuration
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
19 local include_body = module:get_option_boolean("push_notification_with_body", false);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
20 local include_sender = module:get_option_boolean("push_notification_with_sender", false);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
21 local max_push_errors = module:get_option_number("push_max_errors", 16);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
22 local max_push_devices = module:get_option_number("push_max_devices", 5);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
23 local dummy_body = module:get_option_string("push_notification_important_body", "New Message!");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
24
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
25 local host_sessions = prosody.hosts[module.host].sessions;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
26 local push_errors = {};
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
27 local id2room = {}
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
28 local id2user = {};
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
29
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
30 module:depends("muc");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
31
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
32 -- For keeping state across reloads while caching reads
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
33 local push_store = (function()
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
34 local store = module:open_store();
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
35 local push_services = {};
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
36 local api = {};
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
37 local function load_room(room)
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
38 if not push_services[room] then
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
39 local err;
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
40 push_services[room], err = store:get(room);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
41 if not push_services[room] and err then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
42 module:log("warn", "Error reading push notification storage for room '%s': %s", room, tostring(err));
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
43 push_services[room] = {};
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
44 return false;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
45 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
46 end
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
47 return true;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
48 end
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
49 function api:get(room, user)
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
50 load_room(room);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
51 if not push_services[room] then push_services[room] = {}; push_services[room][user] = {}; end
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
52 return push_services[room][user], true;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
53 end
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
54 function api:set(room, user, data)
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
55 push_services[room][user] = data;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
56 local ok, err = store:set(room, push_services[room]);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
57 if not ok then
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
58 module:log("error", "Error writing push notification storage for room '%s' on behalf of user '%s': %s", room, user, tostring(err));
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
59 return false;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
60 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
61 return true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
62 end
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
63 function api:get_room_users(room)
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
64 local users = {};
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
65 load_room(room);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
66 for k, v in pairs(push_services[room]) do
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
67 table.insert(users, k);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
68 end
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
69 return users;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
70 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
71 return api;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
72 end)();
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
73
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
74
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
75 -- Forward declarations, as both functions need to reference each other
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
76 local handle_push_success, handle_push_error;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
77
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
78 function handle_push_error(event)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
79 local stanza = event.stanza;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
80 local error_type, condition = stanza:get_error();
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
81 local room = id2room[stanza.attr.id];
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
82 local user = id2user[stanza.attr.id];
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
83 if room == nil or user == nil then return false; end -- unknown stanza? Ignore for now!
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
84 local push_service = push_store:get(room, user);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
85 local push_identifier = room.."<"..user..">";
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
86
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
87 local stanza_id = hashes.sha256(push_identifier, true);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
88 if stanza_id == stanza.attr.id then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
89 if push_service and push_service.push_jid == stanza.attr.from and error_type ~= "wait" then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
90 push_errors[push_identifier] = push_errors[push_identifier] + 1;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
91 module:log("info", "Got error of type '%s' (%s) for identifier '%s': "
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
92 .."error count for this identifier is now at %s", error_type, condition, push_identifier,
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
93 tostring(push_errors[push_identifier]));
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
94 if push_errors[push_identifier] >= max_push_errors then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
95 module:log("warn", "Disabling push notifications for identifier '%s'", push_identifier);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
96 -- save changed global config
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
97 push_store:set(room, user, nil);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
98 push_errors[push_identifier] = nil;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
99 -- unhook iq handlers for this identifier (if possible)
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
100 if module.unhook then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
101 module:unhook("iq-error/host/"..stanza_id, handle_push_error);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
102 module:unhook("iq-result/host/"..stanza_id, handle_push_success);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
103 id2room[stanza_id] = nil;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
104 id2user[stanza_id] = nil;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
105 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
106 end
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
107 elseif push_service and push_service.push_jid == stanza.attr.from and error_type == "wait" then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
108 module:log("debug", "Got error of type '%s' (%s) for identifier '%s': "
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
109 .."NOT increasing error count for this identifier", error_type, condition, push_identifier);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
110 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
111 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
112 return true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
113 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
114
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
115 function handle_push_success(event)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
116 local stanza = event.stanza;
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
117 local room = id2room[stanza.attr.id];
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
118 local user = id2user[stanza.attr.id];
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
119 if room == nil or user == nil then return false; end -- unknown stanza? Ignore for now!
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
120 local push_service = push_store:get(room, user);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
121 local push_identifier = room.."<"..user..">";
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
122
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
123 if hashes.sha256(push_identifier, true) == stanza.attr.id then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
124 if push_service and push_service.push_jid == stanza.attr.from and push_errors[push_identifier] > 0 then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
125 push_errors[push_identifier] = 0;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
126 -- unhook iq handlers for this identifier (if possible)
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
127 if module.unhook then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
128 module:unhook("iq-error/host/"..stanza.attr.id, handle_push_error);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
129 module:unhook("iq-result/host/"..stanza.attr.id, handle_push_success);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
130 id2room[stanza.attr.id] = nil;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
131 id2user[stanza.attr.id] = nil;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
132 end
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
133 module:log("debug", "Push succeeded, error count for identifier '%s' is now at %s again", push_identifier, tostring(push_errors[push_identifier]));
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
134 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
135 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
136 return true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
137 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
138
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
139 -- http://xmpp.org/extensions/xep-xxxx.html#disco
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
140 module:hook("muc-disco#info", function(event)
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
141 (event.reply or event.stanza):tag("feature", {var=xmlns_push}):up();
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
142 end);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
143
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
144 -- http://xmpp.org/extensions/xep-0357.html#enabling
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
145 local function push_enable(event)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
146 local origin, stanza = event.origin, event.stanza;
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
147 local room = jid.split(stanza.attr.to);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
148 local enable = stanza.tags[1];
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
149 origin.log("debug", "Attempting to enable push notifications");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
150 -- MUST contain a 'jid' attribute of the XMPP Push Service being enabled
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
151 local push_jid = enable.attr.jid;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
152 if not push_jid then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
153 origin.log("debug", "MUC Push notification enable request missing the 'jid' field");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
154 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid"));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
155 return true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
156 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
157 local publish_options = enable:get_child("x", "jabber:x:data");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
158 if not publish_options then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
159 -- Could be intentional
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
160 origin.log("debug", "No publish options in request");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
161 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
162 local push_service = {
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
163 push_jid = push_jid;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
164 device = stanza.attr.from;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
165 options = publish_options and st.preserialize(publish_options);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
166 timestamp = os_time();
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
167 };
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
168
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
169 local ok = push_store:set(room, stanza.attr.from, push_service);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
170 if not ok then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
171 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
172 else
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
173 origin.log("info", "MUC Push notifications enabled for room %s by %s (%s)",
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
174 tostring(room),
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
175 tostring(stanza.attr.from),
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
176 tostring(push_jid)
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
177 );
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
178 origin.send(st.reply(stanza));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
179 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
180 return true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
181 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
182 module:hook("iq-set/host/"..xmlns_push..":enable", push_enable);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
183
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
184
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
185 -- http://xmpp.org/extensions/xep-0357.html#disabling
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
186 local function push_disable(event)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
187 local origin, stanza = event.origin, event.stanza;
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
188 local room = jid.split(stanza.attr.to);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
189 local push_jid = stanza.tags[1].attr.jid; -- MUST include a 'jid' attribute
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
190 if not push_jid then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
191 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid"));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
192 return true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
193 end
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
194 local push_identifier = room.."<"..stanza.attr.from..">";
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
195 local push_service = push_store:get(room, stanza.attr.from);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
196 local ok = true;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
197 if push_service.push_jid == push_jid then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
198 origin.log("info", "Push notifications disabled for room %s by %s (%s)",
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
199 tostring(room),
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
200 sotring(stanza.attr.from),
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
201 tostring(push_jid)
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
202 );
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
203 ok = push_store:set(room, stanza.attr.from, nil);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
204 push_errors[push_identifier] = nil;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
205 if module.unhook then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
206 local stanza_id = hashes.sha256(push_identifier, true);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
207 module:unhook("iq-error/host/"..stanza_id, handle_push_error);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
208 module:unhook("iq-result/host/"..stanza_id, handle_push_success);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
209 id2room[stanza_id] = nil;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
210 id2user[stanza_id] = nil;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
211 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
212 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
213 if not ok then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
214 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
215 else
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
216 origin.send(st.reply(stanza));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
217 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
218 return true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
219 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
220 module:hook("iq-set/host/"..xmlns_push..":disable", push_disable);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
221
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
222 -- Patched version of util.stanza:find() that supports giving stanza names
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
223 -- without their namespace, allowing for every namespace.
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
224 local function find(self, path)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
225 local pos = 1;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
226 local len = #path + 1;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
227
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
228 repeat
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
229 local xmlns, name, text;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
230 local char = s_sub(path, pos, pos);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
231 if char == "@" then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
232 return self.attr[s_sub(path, pos + 1)];
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
233 elseif char == "{" then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
234 xmlns, pos = s_match(path, "^([^}]+)}()", pos + 1);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
235 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
236 name, text, pos = s_match(path, "^([^@/#]*)([/#]?)()", pos);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
237 name = name ~= "" and name or nil;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
238 if pos == len then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
239 if text == "#" then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
240 local child = xmlns ~= nil and self:get_child(name, xmlns) or self:child_with_name(name);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
241 return child and child:get_text() or nil;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
242 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
243 return xmlns ~= nil and self:get_child(name, xmlns) or self:child_with_name(name);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
244 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
245 self = xmlns ~= nil and self:get_child(name, xmlns) or self:child_with_name(name);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
246 until not self
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
247 return nil;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
248 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
249
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
250 -- is this push a high priority one (this is needed for ios apps not using voip pushes)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
251 local function is_important(stanza)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
252 local st_name = stanza and stanza.name or nil;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
253 if not st_name then return false; end -- nonzas are never important here
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
254 if st_name == "presence" then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
255 return false; -- same for presences
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
256 elseif st_name == "message" then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
257 -- unpack carbon copies
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
258 local stanza_direction = "in";
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
259 local carbon;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
260 local st_type;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
261 -- support carbon copied message stanzas having an arbitrary message-namespace or no message-namespace at all
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
262 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:2}/forwarded/message"); end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
263 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:1}/forwarded/message"); end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
264 stanza_direction = carbon and stanza:child_with_name("sent") and "out" or "in";
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
265 if carbon then stanza = carbon; end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
266 st_type = stanza.attr.type;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
267
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
268 -- headline message are always not important
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
269 if st_type == "headline" then return false; end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
270
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
271 -- carbon copied outgoing messages are not important
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
272 if carbon and stanza_direction == "out" then return false; end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
273
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
274 -- We can't check for body contents in encrypted messages, so let's treat them as important
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
275 -- Some clients don't even set a body or an empty body for encrypted messages
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
276
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
277 -- check omemo https://xmpp.org/extensions/inbox/omemo.html
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
278 if stanza:get_child("encrypted", "eu.siacs.conversations.axolotl") or stanza:get_child("encrypted", "urn:xmpp:omemo:0") then return true; end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
279
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
280 -- check xep27 pgp https://xmpp.org/extensions/xep-0027.html
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
281 if stanza:get_child("x", "jabber:x:encrypted") then return true; end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
282
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
283 -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
284 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
285
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
286 local body = stanza:get_child_text("body");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
287 if st_type == "groupchat" and stanza:get_child_text("subject") then return false; end -- groupchat subjects are not important here
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
288 return body ~= nil and body ~= ""; -- empty bodies are not important
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
289 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
290 return false; -- this stanza wasn't one of the above cases --> it is not important, too
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
291 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
292
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
293 local push_form = dataform {
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
294 { name = "FORM_TYPE"; type = "hidden"; value = "urn:xmpp:muc_push:summary"; };
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
295 --{ name = "dummy"; type = "text-single"; };
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
296 };
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
297
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
298 -- http://xmpp.org/extensions/xep-0357.html#publishing
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
299 local function handle_notify_request(stanza, user, user_push_services)
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
300 local pushes = 0;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
301 if not user_push_services or next(user_push_services) == nil then return pushes end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
302
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
303 for push_identifier, push_info in pairs(user_push_services) do
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
304 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
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
305 if stanza then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
306 if not stanza._push_notify then stanza._push_notify = {}; end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
307 if stanza._push_notify[push_identifier] then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
308 if log_push_decline then
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
309 module:log("debug", "Already sent push notification for %s to %s (%s)", user, push_info.push_jid, tostring(push_info.node));
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
310 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
311 send_push = false;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
312 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
313 stanza._push_notify[push_identifier] = true;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
314 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
315
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
316 if send_push then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
317 -- construct push stanza
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
318 local stanza_id = hashes.sha256(push_identifier, true);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
319 local push_publish = st.iq({ to = push_info.jid, from = module.host, type = "set", id = stanza_id })
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
320 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" })
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
321 :tag("publish", { node = push_info.node })
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
322 :tag("item")
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
323 :tag("notification", { xmlns = xmlns_push });
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
324 local form_data = {
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
325 -- hardcode to 1 because other numbers are just meaningless (the XEP does not specify *what exactly* to count)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
326 ["message-count"] = "1";
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
327 };
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
328 if stanza and include_sender then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
329 form_data["last-message-sender"] = stanza.attr.from;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
330 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
331 if stanza and include_body then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
332 form_data["last-message-body"] = stanza:get_child_text("body");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
333 elseif stanza and dummy_body and is_important(stanza) then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
334 form_data["last-message-body"] = tostring(dummy_body);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
335 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
336 push_publish:add_child(push_form:form(form_data));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
337 push_publish:up(); -- / notification
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
338 push_publish:up(); -- / publish
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
339 push_publish:up(); -- / pubsub
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
340 if push_info.options then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
341 push_publish:tag("publish-options"):add_child(st.deserialize(push_info.options));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
342 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
343 -- send out push
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
344 module:log("debug", "Sending%s push notification for %s@%s to %s (%s)", form_data["last-message-body"] and " important" or "", node, module.host, push_info.jid, tostring(push_info.node));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
345 -- module:log("debug", "PUSH STANZA: %s", tostring(push_publish));
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
346 -- handle push errors for this node
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
347 if push_errors[push_identifier] == nil then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
348 push_errors[push_identifier] = 0;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
349 module:hook("iq-error/host/"..stanza_id, handle_push_error);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
350 module:hook("iq-result/host/"..stanza_id, handle_push_success);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
351 id2node[stanza_id] = node;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
352 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
353 module:send(push_publish);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
354 pushes = pushes + 1;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
355 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
356 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
357 return pushes;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
358 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
359
3570
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
360 local function extract_reference(text, i, j)
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
361 -- COMPAT w/ pre-Lua 5.3
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
362 local c, pos, p1 = 0, 0, nil;
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
363 for char in text:gmatch("([%z\1-\127\194-\244][\128-\191]*)") do
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
364 c, pos = c + 1, pos + #char;
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
365 if not p1 and i < c then
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
366 p1 = pos;
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
367 end
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
368 if c == j then
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
369 return text:sub(p1, pos);
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
370 end
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
371 end
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
372 end
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
373
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
374 -- archive message added
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
375 local function archive_message_added(event)
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
376 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id }
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
377 local room = event.room;
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
378 local stanza = event.stanza;
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
379 local room_name = jid.split(room.jid);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
380
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
381 -- extract all real ocupant jids in room
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
382 occupants = {};
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
383 for nick, occupant in room:each_occupant() do
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
384 for jid in occupant:each_session() do
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
385 occupants[jid] = true;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
386 end
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
387 end
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
388
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
389 -- check all push registered users against occupants list
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
390 for _, user in pairs(push_store:get_room_users(room_name)) do
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
391 -- send push if not found in occupants list
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
392 if not occupants[user] then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
393 local push_service = push_store:get(room_name, user);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
394 handle_notify_request(event.stanza, user, push_service);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
395 end
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
396 end
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
397
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
398
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
399
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
400
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
401 liste der registrierten push user eines raumes durchgehen
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
402 jeder user der NICHT im muc ist, wird gepusht
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
403
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
404
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
405 handle_notify_request(event.stanza, jid, user_push_services, true);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
406
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
407
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
408
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
409 for reference in stanza:childtags("reference", "urn:xmpp:reference:0") do
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
410 if reference.attr['type'] == 'mention' and reference.attr['begin'] and reference.attr['end'] then
3570
8a93af85f319 mod_muc_cloud_notify: Count codepoints instead of bytes
Matthew Wild <mwild1@gmail.com>
parents: 3319
diff changeset
411 local nick = extract_reference(body, reference.attr['begin'], reference.attr['end']);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
412 local jid = room:get_registered_jid(nick);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
413
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
414 if room._occupants[room.jid..'/'..nick] then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
415 -- We only notify for members not currently in the room
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
416 module:log("debug", "Not notifying %s, because he's currently in the room", jid);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
417 else
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
418 -- We only need to notify once, even when there are multiple mentions.
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
419 local user_push_services = push_store:get(jid);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
420 handle_notify_request(event.stanza, jid, user_push_services, true);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
421 return
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
422 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
423 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
424 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
425 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
426
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
427 module:hook("muc-add-history", archive_message_added);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
428
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
429 local function send_ping(event)
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
430 local push_services = event.push_services;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
431 if not push_services then
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
432 local room = event.room;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
433 local user = event.user;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
434 push_services = push_store:get(room, user);
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
435 end
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
436 handle_notify_request(nil, user, push_services, true);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
437 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
438 -- can be used by other modules to ping one or more (or all) push endpoints
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
439 module:hook("muc-cloud-notify-ping", send_ping);
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
440
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
441 module:log("info", "Module loaded");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
442 function module.unload()
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
443 if module.unhook then
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
444 module:unhook("account-disco-info", account_dico_info);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
445 module:unhook("iq-set/host/"..xmlns_push..":enable", push_enable);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
446 module:unhook("iq-set/host/"..xmlns_push..":disable", push_disable);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
447
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
448 module:unhook("muc-add-history", archive_message_added);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
449 module:unhook("cloud-notify-ping", send_ping);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
450
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
451 for push_identifier, _ in pairs(push_errors) do
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
452 local stanza_id = hashes.sha256(push_identifier, true);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
453 module:unhook("iq-error/host/"..stanza_id, handle_push_error);
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
454 module:unhook("iq-result/host/"..stanza_id, handle_push_success);
3882
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
455 id2room[stanza_id] = nil;
3b8f4f3b1718 mod_reload_modules: Ignore removed hosts...
tmolitor <thilo@eightysoft.de>
parents: 3570
diff changeset
456 id2user[stanza_id] = nil;
3319
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
457 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
458 end
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
459
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
460 module:log("info", "Module unloaded");
408f92149774 mod_muc_cloud_notify: New module
JC Brand <jc@opkode.com>
parents:
diff changeset
461 end