Changeset

1425:9c894b56b4e4

mod_muc_intercom: Make compatible with new MUC API.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 30 May 2014 18:54:31 -0400
parents 1424:9892a537e7fc
children 1426:249c5447fed1
files mod_muc_intercom/mod_muc_intercom.lua
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_intercom/mod_muc_intercom.lua	Fri May 30 15:05:48 2014 +0200
+++ b/mod_muc_intercom/mod_muc_intercom.lua	Fri May 30 18:54:31 2014 -0400
@@ -6,12 +6,20 @@
 local jid = require "util.jid";
 local now = require "util.datetime".datetime;
 
+local function get_room_by_jid(mod_muc, jid)
+	if mod_muc.get_room_by_jid then
+		return mod_muc.get_room_by_jid(jid);
+	elseif mod_muc.rooms then
+		return mod_muc.rooms[jid]; -- COMPAT 0.9, 0.10
+	end
+end
+
 function check_message(data)
 	local origin, stanza = data.origin, data.stanza;
-	local muc_rooms = host_session.muc and host_session.muc.rooms;
-	if not muc_rooms then return; end
+	local mod_muc = host_session.muc;
+	if not mod_muc then return; end
 
-	local this_room = muc_rooms[stanza.attr.to];
+	local this_room = get_room_by_jid(mod_muc, stanza.attr.to);
 	if not this_room then return; end -- no such room
 
 	local from_room_jid = this_room._jid_nick[stanza.attr.from];
@@ -29,7 +37,8 @@
 	module:log("debug", "target room is %s", target_room);
 
 	local bare_room = jid.join(target_room, from_host);
-	if not muc_rooms[bare_room] then return; end -- TODO send a error
+	local dest_room = get_room_by_jid(mod_muc, bare_room);
+	if not dest_room then return; end -- TODO send a error
 	module:log("info", "message from %s in %s to %s", from_nick, from_room, target_room);
 
 	local sender = jid.join(target_room, module.host, from_room .. "/" .. from_nick);
@@ -37,7 +46,7 @@
 	forward_stanza:tag("delay", { xmlns = 'urn:xmpp:delay', from = from_room_jid, stamp = now() }):up();
 
 	module:log("debug", "broadcasting message to target room");
-	muc_rooms[bare_room]:broadcast_message(forward_stanza);
+	dest_room:broadcast_message(forward_stanza);
 end
 
 module:hook("message/bare", check_message, 10);