Diff

mod_muc_limits/mod_muc_limits.lua @ 3417:1534d0715d35

mod_muc_limits: Add support for new MUC API in Prosody 0.11
author Kim Alvefur <zash@zash.se>
date Sun, 23 Dec 2018 21:46:06 +0100
parent 3402:6a3060d5e85d
child 3418:9be9dd434813
line wrap: on
line diff
--- a/mod_muc_limits/mod_muc_limits.lua	Sun Dec 23 18:33:32 2018 +0100
+++ b/mod_muc_limits/mod_muc_limits.lua	Sun Dec 23 21:46:06 2018 +0100
@@ -1,9 +1,6 @@
 
 local mod_muc = module:depends"muc";
 local rooms = rawget(mod_muc, "rooms"); -- Old MUC API
-if not rooms then
-	error "Not compatible with 0.11 MUC API"
-end
 
 local jid_split, jid_bare = require "util.jid".split, require "util.jid".bare;
 local st = require "util.stanza";
@@ -31,7 +28,7 @@
 		return;
 	end
 	local dest_room, dest_host, dest_nick = jid_split(stanza.attr.to);
-	local room = rooms[dest_room.."@"..dest_host];
+	local room = event.room or rooms[dest_room.."@"..dest_host];
 	if not room then return; end
 	local from_jid = stanza.attr.from;
 	local occupant = room._occupants[room._jid_nick[from_jid]];
@@ -82,7 +79,13 @@
 	end
 end
 
-module:hook("message/bare", handle_stanza, 501);
-module:hook("message/full", handle_stanza, 501);
-module:hook("presence/bare", handle_stanza, 501);
-module:hook("presence/full", handle_stanza, 501);
+if rooms then
+	module:hook("message/bare", handle_stanza, 501);
+	module:hook("message/full", handle_stanza, 501);
+	module:hook("presence/bare", handle_stanza, 501);
+	module:hook("presence/full", handle_stanza, 501);
+else
+	module:hook("muc-occupant-pre-join", handle_stanza);
+	module:hook("muc-occupant-pre-change", handle_stanza);
+	module:hook("muc-occupant-groupchat", handle_stanza);
+end