comparison plugins/muc/util.lib.lua @ 10713:38159b9adf9f

MUC: Add API for adding 'filtered namespaces' to be stripped from inbound presence
author Matthew Wild <mwild1@gmail.com>
date Sat, 11 Apr 2020 16:43:57 +0100
parents 4897bd63f624
children
comparison
equal deleted inserted replaced
10712:dc24a8783c5d 10713:38159b9adf9f
39 function _M.is_kickable_error(stanza) 39 function _M.is_kickable_error(stanza)
40 local cond = select(2, stanza:get_error()) or "malformed error"; 40 local cond = select(2, stanza:get_error()) or "malformed error";
41 return kickable_error_conditions[cond]; 41 return kickable_error_conditions[cond];
42 end 42 end
43 43
44 local muc_x_filters = { 44 local filtered_namespaces = module:shared("filtered-namespaces");
45 ["http://jabber.org/protocol/muc"] = true; 45 filtered_namespaces["http://jabber.org/protocol/muc"] = true;
46 ["http://jabber.org/protocol/muc#user"] = true; 46 filtered_namespaces["http://jabber.org/protocol/muc#user"] = true;
47 } 47
48 local function muc_x_filter(tag) 48 local function muc_ns_filter(tag)
49 if muc_x_filters[tag.attr.xmlns] then 49 if filtered_namespaces[tag.attr.xmlns] then
50 return nil; 50 return nil;
51 end 51 end
52 return tag; 52 return tag;
53 end 53 end
54 function _M.filter_muc_x(stanza) 54 function _M.filter_muc_x(stanza)
55 return stanza:maptags(muc_x_filter); 55 return stanza:maptags(muc_ns_filter);
56 end
57
58 function _M.add_filtered_namespace(xmlns)
59 filtered_namespaces[xmlns] = true;
56 end 60 end
57 61
58 function _M.only_with_min_role(role) 62 function _M.only_with_min_role(role)
59 local min_role_value = _M.valid_roles[role]; 63 local min_role_value = _M.valid_roles[role];
60 return function (nick, occupant) --luacheck: ignore 212/nick 64 return function (nick, occupant) --luacheck: ignore 212/nick