Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
5611:e043d4d65423 | 5612:5404832d6f7a |
---|---|
25 | 25 |
26 local muc_domain = nil; --module:get_host(); | 26 local muc_domain = nil; --module:get_host(); |
27 local default_history_length, max_history_length = 20, math.huge; | 27 local default_history_length, max_history_length = 20, math.huge; |
28 | 28 |
29 ------------ | 29 ------------ |
30 local function filter_xmlns_from_array(array, filters) | |
31 local count = 0; | |
32 for i=#array,1,-1 do | |
33 local attr = array[i].attr; | |
34 if filters[attr and attr.xmlns] then | |
35 t_remove(array, i); | |
36 count = count + 1; | |
37 end | |
38 end | |
39 return count; | |
40 end | |
41 local function filter_xmlns_from_stanza(stanza, filters) | |
42 if filters then | |
43 if filter_xmlns_from_array(stanza.tags, filters) ~= 0 then | |
44 return stanza, filter_xmlns_from_array(stanza, filters); | |
45 end | |
46 end | |
47 return stanza, 0; | |
48 end | |
49 local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; | 30 local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; |
31 local function presence_filter(tag) | |
32 if presence_filters[tag.attr.xmlns] then | |
33 return nil; | |
34 end | |
35 return tag; | |
36 end | |
37 | |
50 local function get_filtered_presence(stanza) | 38 local function get_filtered_presence(stanza) |
51 return filter_xmlns_from_stanza(st.clone(stanza):reset(), presence_filters); | 39 return st.clone(stanza):maptags(presence_filter); |
52 end | 40 end |
53 local kickable_error_conditions = { | 41 local kickable_error_conditions = { |
54 ["gone"] = true; | 42 ["gone"] = true; |
55 ["internal-server-error"] = true; | 43 ["internal-server-error"] = true; |
56 ["item-not-found"] = true; | 44 ["item-not-found"] = true; |