# HG changeset patch # User Matthew Wild # Date 1610737032 0 # Node ID 3b7847c9bd2601349a4d7de3665bce3a70d45a37 # Parent 0227fb4d1b40f0ae4870123b6a2ae0758f9afc9c mod_muc_deliver_offline: New module for delivery of MUC messages to offline users diff -r 0227fb4d1b40 -r 3b7847c9bd26 mod_muc_offline_delivery/.mod_muc_offline_delivery.lua.swp Binary file mod_muc_offline_delivery/.mod_muc_offline_delivery.lua.swp has changed diff -r 0227fb4d1b40 -r 3b7847c9bd26 mod_muc_offline_delivery/README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_muc_offline_delivery/README.md Fri Jan 15 18:57:12 2021 +0000 @@ -0,0 +1,42 @@ +--- +labels: +- 'Stage-Alpha' +summary: 'Support for sending MUC messages to offline users' +... + +Introduction +============ + +This module implements support for sending messages in a MUC to affiliated users +who are not in the room. This is a custom extension by Tigase to allow push notifications +from MUCs to users who are not currently connected. + +It is planned that this will evolve to a XEP in the near future. + +The protocol is described below. It is implemented in the Siskin client for iOS. + +Details +======= + +Add to modules_enabled under your MUC component (i.e. **not** the global modules_enabled +list). There are no configuration options. + +Compatibility +============= + +Requires Prosody trunk (0.12) for the API introduced in commit 336cba957c88. + +Protocol +======== + +To enable this feature, a client must fetch the registration form from a MUC, +as per XEP-0045. The form will include the usual field for nickname (this is +required), and also a boolean field named `{http://tigase.org/protocol/muc}offline`. + +Submit the form with that field set to true, and the MUC will forward messages +to your bare JID when you are not connected to the room. Two things to note: + +1. This will achieve nothing unless your server is capable of handling these + messages correctly. +2. Messages are only sent when you are not in the room. This includes other + resources of the same account. diff -r 0227fb4d1b40 -r 3b7847c9bd26 mod_muc_offline_delivery/mod_muc_offline_delivery.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_muc_offline_delivery/mod_muc_offline_delivery.lua Fri Jan 15 18:57:12 2021 +0000 @@ -0,0 +1,35 @@ +local st = require "util.stanza"; + +module:add_item("muc-registration-field", { + name = "{http://tigase.org/protocol/muc}offline"; + type = "boolean"; + label = "Receive messages while not connected to the room"; + value = false; +}); + +module:hook("muc-registration-submitted", function (event) + local deliver_offline = event.submitted_data["{http://tigase.org/protocol/muc}offline"] or nil; + event.affiliation_data.offline_delivery = deliver_offline; +end); + +module:hook("muc-add-history", function (event) + module:log("debug", "Broadcasting message to offline occupants..."); + local sent = 0; + local room = event.room; + for jid, affiliation, data in room:each_affiliation() do --luacheck: ignore 213/affiliation + local reserved_nickname = data and data.reserved_nickname; + module:log("debug", "Affiliated: %s, %s: %s", jid, reserved_nickname, data and data.offline_delivery); + if reserved_nickname and data.offline_delivery then + local is_absent = not room:get_occupant_by_nick(room.jid.."/"..reserved_nickname); + if is_absent then + local msg = st.clone(event.stanza); + msg.attr.to = jid; + module:send(msg); + sent = sent + 1; + end + end + end + if sent > 0 then + module:log("debug", "Sent message to %d offline occupants", sent); + end +end);