mod_csi_muc_priorities/mod_csi_muc_priorities.lua
author Kim Alvefur <zash@zash.se>
Mon, 01 Apr 2019 00:15:13 +0200
changeset 3536 85c357b69eec
child 3537 d8c4543f1b19
permissions -rw-r--r--
mod_csi_muc_priorities: Reduce importance of group chat messages This helps if you are in more noisy public channels than small private group chats. The short term plan is to give users the ability to set MUC JIDs as either high or low priority and use that. Long term it would be great to be able to automatically classify MUCs as public channels vs private group chats.

local jid = require "util.jid";

module:depends"track_muc_joins"

module:hook("csi-is-stanza-important", function (event)
	local stanza, session = event.stanza, event.session;
	if stanza.name == "message" then
		if stanza.attr.type == "groupchat" then
			local body = stanza:get_child_text("body");
			if not body then return end

			local rooms = session.rooms_joined;
			if not rooms then return false; end

			-- TODO optional?
			local room_nick = rooms[jid.bare(stanza.attr.from)];
			if room_nick and body:find(room_nick, 1, true) then return true; end

			return false;
		end
	end
end);