comparison mod_muc_offline_delivery/mod_muc_offline_delivery.lua @ 4773:eb63890ae8fc

mod_muc_offline_delivery: Allow the module to be enabled by default for all users
author Matthew Wild <mwild1@gmail.com>
date Tue, 16 Nov 2021 15:09:52 +0000
parents 6ca2769da62a
children fd90925dc239
comparison
equal deleted inserted replaced
4772:85d4ab318d66 4773:eb63890ae8fc
1 local st = require "util.stanza"; 1 local st = require "util.stanza";
2
3 local default_enable = module:get_option_boolean("muc_offline_delivery_default", false);
2 4
3 module:add_item("muc-registration-field", { 5 module:add_item("muc-registration-field", {
4 name = "offline_delivery"; 6 name = "offline_delivery";
5 var = "{http://tigase.org/protocol/muc}offline"; 7 var = "{http://tigase.org/protocol/muc}offline";
6 type = "boolean"; 8 type = "boolean";
7 label = "Receive messages while not connected to the room"; 9 label = "Receive messages while not connected to the room";
8 value = false; 10 value = default_enable;
9 }); 11 });
10 12
11 module:hook("muc-registration-submitted", function (event) 13 module:hook("muc-registration-submitted", function (event)
12 local deliver_offline = event.submitted_data.offline_delivery or nil; 14 local deliver_offline = event.submitted_data.offline_delivery;
13 event.affiliation_data.offline_delivery = deliver_offline; 15 event.affiliation_data.offline_delivery = deliver_offline;
14 end); 16 end);
15 17
16 module:hook("muc-add-history", function (event) 18 module:hook("muc-add-history", function (event)
17 module:log("debug", "Broadcasting message to offline occupants..."); 19 module:log("debug", "Broadcasting message to offline occupants...");
18 local sent = 0; 20 local sent = 0;
19 local room = event.room; 21 local room = event.room;
20 for jid, affiliation, data in room:each_affiliation() do --luacheck: ignore 213/affiliation 22 for jid, affiliation, data in room:each_affiliation() do --luacheck: ignore 213/affiliation
21 local reserved_nickname = data and data.reserved_nickname; 23 local reserved_nickname = data and data.reserved_nickname;
22 if reserved_nickname and data.offline_delivery then 24 local user_setting = data.offline_delivery;
25 if reserved_nickname and user_setting or (user_setting == nil and default_enable) then
23 local is_absent = not room:get_occupant_by_nick(room.jid.."/"..reserved_nickname); 26 local is_absent = not room:get_occupant_by_nick(room.jid.."/"..reserved_nickname);
24 if is_absent then 27 if is_absent then
25 module:log("debug", "Forwarding message to offline member <%s>", jid); 28 module:log("debug", "Forwarding message to offline member <%s>", jid);
26 local msg = st.clone(event.stanza); 29 local msg = st.clone(event.stanza);
27 msg.attr.to = jid; 30 msg.attr.to = jid;