diff mod_muc_rai/mod_muc_rai.lua @ 4277:10dc4527574f

mod_muc_rai: Subscribe/unsubscribe users when leaving/joining
author Seve Ferrer <seve@delape.net>
date Tue, 01 Dec 2020 16:45:20 +0100
parents 4b84beb48ba0
children 3c80e46e26f2
line wrap: on
line diff
--- a/mod_muc_rai/mod_muc_rai.lua	Sat Nov 28 21:22:16 2020 +0100
+++ b/mod_muc_rai/mod_muc_rai.lua	Tue Dec 01 16:45:20 2020 +0100
@@ -186,6 +186,22 @@
 	return rooms_with_activity;
 end
 
+module:hook("muc-occupant-joined", function(event)
+	local room_jid, user_jid = event.room.jid, event.stanza.attr.from;
+	local ok, err = unsubscribe_room(user_jid, room_jid);
+	if ok then
+		module:log("debug", "Unsubscribed " .. user_jid .. " from " .. room_jid .. " Reason: muc-occupant-joined")
+	end
+end);
+
+module:hook("muc-occupant-left", function(event)
+	local room_jid, user_jid = event.room.jid, event.stanza.attr.from;
+	local ok, err = subscribe_room(user_jid, room_jid);
+	if ok then
+		module:log("debug", "Subscribed " .. user_jid .. " to " .. room_jid .. " Reason: muc-occupant-left")
+	end
+end);
+
 module:hook("presence/host", function (event)
 	local origin, stanza = event.origin, event.stanza;
 	local user_jid = stanza.attr.from;