annotate mod_muc_offline_delivery/mod_muc_offline_delivery.lua @ 5714:c77010f25b14

mod_audit: Replace argument parsing debug print() with debug logging prosodyctl -v to view
author Kim Alvefur <zash@zash.se>
date Tue, 14 Nov 2023 16:01:33 +0100
parents 4abb33a15897
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4339
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local st = require "util.stanza";
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
4773
eb63890ae8fc mod_muc_offline_delivery: Allow the module to be enabled by default for all users
Matthew Wild <mwild1@gmail.com>
parents: 4770
diff changeset
3 local default_enable = module:get_option_boolean("muc_offline_delivery_default", false);
eb63890ae8fc mod_muc_offline_delivery: Allow the module to be enabled by default for all users
Matthew Wild <mwild1@gmail.com>
parents: 4770
diff changeset
4
4339
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 module:add_item("muc-registration-field", {
4770
6ca2769da62a mod_muc_offline_delivery: split name/var so that retrieval of form data works
Matthew Wild <mwild1@gmail.com>
parents: 4768
diff changeset
6 name = "offline_delivery";
6ca2769da62a mod_muc_offline_delivery: split name/var so that retrieval of form data works
Matthew Wild <mwild1@gmail.com>
parents: 4768
diff changeset
7 var = "{http://tigase.org/protocol/muc}offline";
4339
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 type = "boolean";
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 label = "Receive messages while not connected to the room";
4773
eb63890ae8fc mod_muc_offline_delivery: Allow the module to be enabled by default for all users
Matthew Wild <mwild1@gmail.com>
parents: 4770
diff changeset
10 value = default_enable;
4339
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 });
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 module:hook("muc-registration-submitted", function (event)
4773
eb63890ae8fc mod_muc_offline_delivery: Allow the module to be enabled by default for all users
Matthew Wild <mwild1@gmail.com>
parents: 4770
diff changeset
14 local deliver_offline = event.submitted_data.offline_delivery;
4339
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 event.affiliation_data.offline_delivery = deliver_offline;
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end);
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 module:hook("muc-add-history", function (event)
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 module:log("debug", "Broadcasting message to offline occupants...");
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local sent = 0;
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local room = event.room;
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 for jid, affiliation, data in room:each_affiliation() do --luacheck: ignore 213/affiliation
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 local reserved_nickname = data and data.reserved_nickname;
4775
fd90925dc239 mod_muc_offline_delivery: Handle the user not having any affiliation data (thanks Martin)
Matthew Wild <mwild1@gmail.com>
parents: 4773
diff changeset
24 local user_setting = data and data.offline_delivery or nil;
4780
4abb33a15897 mod_muc_offline_delivery: Fix logic bug causing traceback when no reserved_nick (thanks Hund)
Matthew Wild <mwild1@gmail.com>
parents: 4775
diff changeset
25 if reserved_nickname and (user_setting or (user_setting == nil and default_enable)) then
4339
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 local is_absent = not room:get_occupant_by_nick(room.jid.."/"..reserved_nickname);
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 if is_absent then
4768
8bd36bba2292 mod_muc_offline_delivery: Less noisy, clearer, debug logging for notifications
Matthew Wild <mwild1@gmail.com>
parents: 4339
diff changeset
28 module:log("debug", "Forwarding message to offline member <%s>", jid);
4339
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 local msg = st.clone(event.stanza);
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 msg.attr.to = jid;
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 module:send(msg);
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 sent = sent + 1;
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 end
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 end
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 if sent > 0 then
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 module:log("debug", "Sent message to %d offline occupants", sent);
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end
3b7847c9bd26 mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end);