Changeset

3636:afedc2430b0d

mod_muc_block_pm: Add support for Prosody 0.11
author JC Brand <jc@opkode.com>
date Fri, 02 Aug 2019 07:44:11 +0200
parents 3635:fd054689a64c
children 3637:ec3de4651306
files mod_muc_block_pm/README.markdown mod_muc_block_pm/mod_muc_block_pm.lua
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_block_pm/README.markdown	Wed Jul 31 18:55:06 2019 +0200
+++ b/mod_muc_block_pm/README.markdown	Fri Aug 02 07:44:11 2019 +0200
@@ -25,4 +25,4 @@
   -------- -----------------
        0.9 Works
       0.10 Should work
-     trunk *Does not work*
+      0.11 Should work
--- a/mod_muc_block_pm/mod_muc_block_pm.lua	Wed Jul 31 18:55:06 2019 +0200
+++ b/mod_muc_block_pm/mod_muc_block_pm.lua	Fri Aug 02 07:44:11 2019 +0200
@@ -1,12 +1,18 @@
 local bare_jid = require"util.jid".bare;
 local st = require"util.stanza";
 
-local muc_rooms = module:depends"muc".rooms;
+-- Support both old and new MUC code
+local mod_muc = module:depends"muc";
+local rooms = rawget(mod_muc, "rooms");
+local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
+	function (jid)
+		return rooms[jid];
+	end
 
 module:hook("message/full", function(event)
 	local stanza, origin = event.stanza, event.origin;
 	local to, from = stanza.attr.to, stanza.attr.from;
-	local room = muc_rooms[bare_jid(to)];
+	local room = get_room_from_jid(bare_jid(to));
 	local to_occupant = room and room._occupants[to];
 	local from_occupant = room and room._occupants[room._jid_nick[from]]
 	if not ( to_occupant and from_occupant ) then return end