Comparison

plugins/muc/muc.lib.lua @ 6115:b8b68d09c9d8

plugins/muc/muc.lib: Tidy up is_kickable_error: it didn't need to return the condition. Also removes `get_error_condition`; it was a one liner used in one place
author daurnimator <quae@daurnimator.com>
date Wed, 19 Mar 2014 13:59:59 -0400
parent 6114:055efbb6d10c
child 6116:9147e566fde0
comparison
equal deleted inserted replaced
6114:055efbb6d10c 6115:b8b68d09c9d8
25 local base64 = require "util.encodings".base64; 25 local base64 = require "util.encodings".base64;
26 local md5 = require "util.hashes".md5; 26 local md5 = require "util.hashes".md5;
27 27
28 local default_history_length, max_history_length = 20, math.huge; 28 local default_history_length, max_history_length = 20, math.huge;
29 29
30 ------------
31 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};
32 local function presence_filter(tag) 31 local function presence_filter(tag)
33 if presence_filters[tag.attr.xmlns] then 32 if presence_filters[tag.attr.xmlns] then
34 return nil; 33 return nil;
35 end 34 end
36 return tag; 35 return tag;
37 end 36 end
38
39 local function get_filtered_presence(stanza) 37 local function get_filtered_presence(stanza)
40 return st.clone(stanza):maptags(presence_filter); 38 return st.clone(stanza):maptags(presence_filter);
41 end 39 end
42 local kickable_error_conditions = { 40
43 ["gone"] = true; 41 local is_kickable_error do
44 ["internal-server-error"] = true; 42 local kickable_error_conditions = {
45 ["item-not-found"] = true; 43 ["gone"] = true;
46 ["jid-malformed"] = true; 44 ["internal-server-error"] = true;
47 ["recipient-unavailable"] = true; 45 ["item-not-found"] = true;
48 ["redirect"] = true; 46 ["jid-malformed"] = true;
49 ["remote-server-not-found"] = true; 47 ["recipient-unavailable"] = true;
50 ["remote-server-timeout"] = true; 48 ["redirect"] = true;
51 ["service-unavailable"] = true; 49 ["remote-server-not-found"] = true;
52 ["malformed error"] = true; 50 ["remote-server-timeout"] = true;
53 }; 51 ["service-unavailable"] = true;
54 52 ["malformed error"] = true;
55 local function get_error_condition(stanza) 53 };
56 local _, condition = stanza:get_error(); 54 function is_kickable_error(stanza)
57 return condition or "malformed error"; 55 local cond = select(2, stanza:get_error()) or "malformed error";
58 end 56 return kickable_error_conditions[cond];
59 57 end
60 local function is_kickable_error(stanza) 58 end
61 local cond = get_error_condition(stanza);
62 return kickable_error_conditions[cond] and cond;
63 end
64 -----------
65 59
66 local room_mt = {}; 60 local room_mt = {};
67 room_mt.__index = room_mt; 61 room_mt.__index = room_mt;
68 62
69 function room_mt:__tostring() 63 function room_mt:__tostring()