Add README, csi_on_away, message_fake_id
authornorly <ny-git@enpas.org>
Tue, 5 Feb 2019 02:37:47 +0000 (03:37 +0100)
committernorly <ny-git@enpas.org>
Tue, 5 Feb 2019 02:41:46 +0000 (03:41 +0100)
README.md [new file with mode: 0644]
modules/mod_csi_on_away.lua [new file with mode: 0644]
modules/mod_message_fake_id.lua [new file with mode: 0644]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..1e5ed23
--- /dev/null
+++ b/README.md
@@ -0,0 +1,27 @@
+My hacks for the [Prosody XMPP server](https://prosody.im/)
+============================================================
+
+Modules
+--------
+
+### `mod_csi_on_away`
+
+This implements CSI for legacy clients that report idleness via 'Away'
+presence.
+
+Just about any old client such as Pidgin can be set to report the user's
+presence as 'Away' after a few minutes of inactivity, or when the
+computer is locked, etc.
+
+With this plugin, these clients will save network traffic and thus power
+when they go 'Away'.
+
+
+### `mod_message_fake_id`
+
+[Monal on iOS](https://monal.im) used to (or still does?) get confused and
+drop messages with the same message ID, or no message ID at all.
+
+To avoid silent message loss at the receiving end when sending
+messages to a Monal user, this plugin generates a random message ID
+(a UUID) for every message stanza.
diff --git a/modules/mod_csi_on_away.lua b/modules/mod_csi_on_away.lua
new file mode 100644 (file)
index 0000000..90a76a0
--- /dev/null
@@ -0,0 +1,29 @@
+local st = require "util.stanza";
+
+
+-- Make sure we only load this module when CSI itself is deployed
+module:depends("csi");
+
+
+local function on_presence(event)
+       if not event.origin.username then
+               return nil;
+       end
+
+       local child = event.stanza:get_child("show");
+
+       if child and child:get_text() == "away" then
+               module:log("debug", "User is now away, simulating CSI.");
+               module:fire_event("csi-client-inactive", event);
+       else
+               module:log("debug", "User is no longer away, ending simulated CSI.");
+               module:fire_event("csi-client-active", event);
+       end
+end
+
+
+-- outgoing
+module:hook("pre-presence/bare", on_presence);
+module:hook("pre-presence/full", on_presence);
+module:hook("pre-presence/host", on_presence);
+
diff --git a/modules/mod_message_fake_id.lua b/modules/mod_message_fake_id.lua
new file mode 100644 (file)
index 0000000..ed6e2b4
--- /dev/null
@@ -0,0 +1,21 @@
+local st = require "util.stanza";
+local uuid_generate = require "util.uuid".generate;
+
+
+local function on_message(event)
+       if not event.origin.username then
+               return nil;
+       end
+
+       if not event.stanza.attr.id then
+               module:log("debug", "Faking message ID.");
+               event.stanza.attr.id = uuid_generate();
+       end
+end
+
+
+-- outgoing
+module:hook("pre-message/bare", on_message, 5432);
+module:hook("pre-message/full", on_message, 5432);
+module:hook("pre-message/host", on_message, 5432);
+