Diff

plugins/muc/muc.lib.lua @ 5612:5404832d6f7a

mod_muc: Use stanza:maptags() instead of custom filtering functions, 7 insertions, 19 deletions!
author Matthew Wild <mwild1@gmail.com>
date Tue, 21 May 2013 09:57:36 +0100
parent 5611:e043d4d65423
child 5613:f3166adab512
line wrap: on
line diff
--- 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;