Mercurial > prosody-modules
annotate mod_muc_offline_delivery/mod_muc_offline_delivery.lua @ 4738:5aee8d86629a
mod_bookmarks2: Fix handling of nick and password elements
This form of child retrieval fails when the stanza elements internally
don't have an 'xmlns' attribute, which can happen sometimes for some
reason, including when they have been constructed via the stanza builder
API. When that is the case then the explicit namespace arguemnt does not
match the nil value of the internal attribute. Calling `:get_child()`
without the namespace argument does the right thing here, with both nil
and the parent namespace as valid values for the internal attribute.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 03 Nov 2021 21:11:55 +0100 |
parents | 3b7847c9bd26 |
children | 8bd36bba2292 |
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", { |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 name = "{http://tigase.org/protocol/muc}offline"; |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 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
|
6 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
|
7 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
|
8 }); |
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 module:hook("muc-registration-submitted", 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
|
11 local deliver_offline = event.submitted_data["{http://tigase.org/protocol/muc}offline"] or nil; |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 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
|
13 end); |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 module:log("debug", "Affiliated: %s, %s: %s", jid, reserved_nickname, data and data.offline_delivery); |
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 |
3b7847c9bd26
mod_muc_deliver_offline: New module for delivery of MUC messages to offline users
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 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
|
29 end |
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 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
|
33 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
|
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); |