plugins/muc/hats.lib.lua
changeset 13472 98806cac64c3
parent 12981 74b9e05af71e
child 13473 f9171624fd03
equal deleted inserted replaced
13471:c2a476f4712a 13472:98806cac64c3
     1 local st = require "prosody.util.stanza";
     1 local st = require "prosody.util.stanza";
     2 local muc_util = module:require "muc/util";
     2 local muc_util = module:require "muc/util";
     3 
     3 
     4 local xmlns_hats = "xmpp:prosody.im/protocol/hats:1";
     4 local hats_compat = module:get_option_boolean("muc_hats_compat", true); -- COMPAT for pre-XEP namespace, TODO reconsider default for next release
       
     5 
       
     6 local xmlns_hats_legacy = "xmpp:prosody.im/protocol/hats:1";
       
     7 local xmlns_hats = "urn:xmpp:hats:0";
     5 
     8 
     6 -- Strip any hats claimed by the client (to prevent spoofing)
     9 -- Strip any hats claimed by the client (to prevent spoofing)
     7 muc_util.add_filtered_namespace(xmlns_hats);
    10 muc_util.add_filtered_namespace(xmlns_hats);
     8 
    11 
     9 
    12 
    17 		if hat_data.active then
    20 		if hat_data.active then
    18 			if not hats_el then
    21 			if not hats_el then
    19 				hats_el = st.stanza("hats", { xmlns = xmlns_hats });
    22 				hats_el = st.stanza("hats", { xmlns = xmlns_hats });
    20 			end
    23 			end
    21 			hats_el:tag("hat", { uri = hat_id, title = hat_data.title }):up();
    24 			hats_el:tag("hat", { uri = hat_id, title = hat_data.title }):up();
       
    25 			if hats_compat then
       
    26 				if not hats_el then
       
    27 					hats_el = st.stanza("hats", { xmlns = xmlns_hats_legacy });
       
    28 				end
       
    29 				hats_el:tag("hat", { uri = hat_id, title = hat_data.title }):up();
       
    30 			end
    22 		end
    31 		end
    23 	end
    32 	end
    24 	if not hats_el then return; end
    33 	if not hats_el then return; end
    25 	event.stanza:add_direct_child(hats_el);
    34 	event.stanza:add_direct_child(hats_el);
    26 end);
    35 end);