# HG changeset patch # User Matthew Wild # Date 1369126656 -3600 # Node ID 5404832d6f7a547529301d799204433e2b81818b # Parent e043d4d65423ca2559d26f8e010abbb6e1710724 mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions! diff -r e043d4d65423 -r 5404832d6f7a plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Tue May 21 09:48:59 2013 +0100 +++ b/plugins/muc/muc.lib.lua Tue May 21 09:57:36 2013 +0100 @@ -27,28 +27,16 @@ local default_history_length, max_history_length = 20, math.huge; ------------ -local function filter_xmlns_from_array(array, filters) - local count = 0; - for i=#array,1,-1 do - local attr = array[i].attr; - if filters[attr and attr.xmlns] then - t_remove(array, i); - count = count + 1; - end +local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; +local function presence_filter(tag) + if presence_filters[tag.attr.xmlns] then + return nil; end - return count; + return tag; end -local function filter_xmlns_from_stanza(stanza, filters) - if filters then - if filter_xmlns_from_array(stanza.tags, filters) ~= 0 then - return stanza, filter_xmlns_from_array(stanza, filters); - end - end - return stanza, 0; -end -local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; + local function get_filtered_presence(stanza) - return filter_xmlns_from_stanza(st.clone(stanza):reset(), presence_filters); + return st.clone(stanza):maptags(presence_filter); end local kickable_error_conditions = { ["gone"] = true;