Changeset

2766:314cebb3071e

mod_pastebin: Check for MUC presence before handling a message. Fixes #955.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 19 Sep 2017 18:47:18 +0200
parents 2765:85cf9a8b4020
children 2767:e1edf643fbb1
files mod_pastebin/mod_pastebin.lua
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pastebin/mod_pastebin.lua	Mon Sep 18 16:39:02 2017 +0100
+++ b/mod_pastebin/mod_pastebin.lua	Tue Sep 19 18:47:18 2017 +0200
@@ -5,6 +5,8 @@
 local os_time = os.time;
 local t_insert, t_remove = table.insert, table.remove;
 local add_task = require "util.timer".add_task;
+local jid_bare = require "util.jid".bare;
+local muc_rooms = module:depends "muc".rooms;
 
 local utf8_pattern = "[\194-\244][\128-\191]*$";
 local function drop_invalid_utf8(seq)
@@ -68,6 +70,15 @@
 function check_message(data)
 	local origin, stanza = data.origin, data.stanza;
 
+	-- Only check for MUC presence when loaded on a component.
+	if module:get_host_type() == "component" then
+		local room = muc_rooms[jid_bare(stanza.attr.to)];
+		if not room then return; end
+
+		local nick = room._jid_nick[stanza.attr.from];
+		if not nick then return; end
+	end
+
 	local body, bodyindex, htmlindex;
 	for k,v in ipairs(stanza) do
 		if v.name == "body" then