Software /
code /
prosody-modules
Annotate
mod_muc_offline_delivery/mod_muc_offline_delivery.lua @ 4771:e227af629736
mod_smacks: Send <r> immediately from csi-flushing event
Using a timer serves no purpose in this case, only serves to increase
the number of write syscalls and TCP segments sent.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 16 Nov 2021 13:39:49 +0100 |
parent | 4770:6ca2769da62a |
child | 4773:eb63890ae8fc |
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 |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 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
|
4 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
|
5 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
|
6 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
|
7 label = "Receive messages while not connected to the room"; |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 value = false; |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 }); |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 module:hook("muc-registration-submitted", function (event) |
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
|
12 local deliver_offline = event.submitted_data.offline_delivery or nil; |
4339
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 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
|
14 end); |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 local reserved_nickname = data and data.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
|
22 if reserved_nickname and data.offline_delivery then |
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 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 end |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 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
|
34 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
|
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 end); |