annotate mod_compat_muc_admin/mod_compat_muc_admin.lua @ 2143:7cab309a26b2

mod_throttle_unsolicited: Remove unused local [luacheck]
author Kim Alvefur <zash@zash.se>
date Wed, 30 Mar 2016 11:12:01 +0200
parents 15a8b717597b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
1 local st = require "util.stanza";
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
2 local jid_split = require "util.jid".split;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
3 local jid_bare = require "util.jid".bare;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
4 local jid_prep = require "util.jid".prep;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
5 local log = require "util.logger".init("mod_muc");
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
6 local muc_host = module:get_host();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
7
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
8 if not hosts[muc_host].modules.muc then -- Not a MUC host
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
9 module:log("error", "this module can only be used on muc hosts."); return false;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
10 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
11
629
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
12 -- Constants and imported functions from muc.lib.lua
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
13 local xmlns_ma, xmlns_mo = "http://jabber.org/protocol/muc#admin", "http://jabber.org/protocol/muc#owner";
629
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
14 local kickable_error_conditions = {
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
15 ["gone"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
16 ["internal-server-error"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
17 ["item-not-found"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
18 ["jid-malformed"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
19 ["recipient-unavailable"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
20 ["redirect"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
21 ["remote-server-not-found"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
22 ["remote-server-timeout"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
23 ["service-unavailable"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
24 ["malformed error"] = true;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
25 };
731
15a8b717597b mod_compat_muc_admin: added missing import (thanke MattJ)
Marco Cirillo <maranda@lightwitch.org>
parents: 631
diff changeset
26 local function get_error_condition(stanza)
15a8b717597b mod_compat_muc_admin: added missing import (thanke MattJ)
Marco Cirillo <maranda@lightwitch.org>
parents: 631
diff changeset
27 local _, condition = stanza:get_error();
15a8b717597b mod_compat_muc_admin: added missing import (thanke MattJ)
Marco Cirillo <maranda@lightwitch.org>
parents: 631
diff changeset
28 return condition or "malformed error";
15a8b717597b mod_compat_muc_admin: added missing import (thanke MattJ)
Marco Cirillo <maranda@lightwitch.org>
parents: 631
diff changeset
29 end
629
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
30 local function is_kickable_error(stanza)
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
31 local cond = get_error_condition(stanza);
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
32 return kickable_error_conditions[cond] and cond;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
33 end
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
34 local function build_unavailable_presence_from_error(stanza)
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
35 local type, condition, text = stanza:get_error();
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
36 local error_message = "Kicked: "..(condition and condition:gsub("%-", " ") or "presence error");
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
37 if text then
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
38 error_message = error_message..": "..text;
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
39 end
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
40 return st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to})
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
41 :tag('status'):text(error_message);
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
42 end
630
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
43 local function getUsingPath(stanza, path, getText)
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
44 local tag = stanza;
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
45 for _, name in ipairs(path) do
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
46 if type(tag) ~= 'table' then return; end
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
47 tag = tag:child_with_name(name);
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
48 end
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
49 if tag and getText then tag = table.concat(tag); end
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
50 return tag;
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
51 end
629
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
52 local function getText(stanza, path) return getUsingPath(stanza, path, true); end
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
53
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
54 -- COMPAT: iq condensed function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
55 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["compat_iq"] = function (self, origin, stanza, xmlns)
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
56 local actor = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
57 local affiliation = self:get_affiliation(actor);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
58 local current_nick = self._jid_nick[actor];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
59 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
60 local item = stanza.tags[1].tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
61 if item and item.name == "item" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
62 if stanza.attr.type == "set" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
63 local callback = function() origin.send(st.reply(stanza)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
64 if item.attr.jid then -- Validate provided JID
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
65 item.attr.jid = jid_prep(item.attr.jid);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
66 if not item.attr.jid then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
67 origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
68 return;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
69 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
70 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
71 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
72 local occupant = self._occupants[self.jid.."/"..item.attr.nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
73 if occupant then item.attr.jid = occupant.jid; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
74 elseif not item.attr.nick and item.attr.jid then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
75 local nick = self._jid_nick[item.attr.jid];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
76 if nick then item.attr.nick = select(3, jid_split(nick)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
77 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
78 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
79 if item.attr.affiliation and item.attr.jid and not item.attr.role then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
80 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
81 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
82 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
83 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
84 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
85 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
86 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
87 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
88 elseif stanza.attr.type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
89 local _aff = item.attr.affiliation;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
90 local _rol = item.attr.role;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
91 if _aff and not _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
92 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
93 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
94 for jid, affiliation in pairs(self._affiliations) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
95 if affiliation == _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
96 reply:tag("item", {affiliation = _aff, jid = jid}):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
97 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
98 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
99 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
100 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
101 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
102 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
103 elseif _rol and not _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
104 if role == "moderator" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
105 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway?
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
106 if _rol == "none" then _rol = nil; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
107 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
108 for occupant_jid, occupant in pairs(self._occupants) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
109 if occupant.role == _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
110 reply:tag("item", {
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
111 nick = select(3, jid_split(occupant_jid)),
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
112 role = _rol or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
113 affiliation = occupant.affiliation or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
114 jid = occupant.jid
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
115 }):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
116 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
117 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
118 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
119 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
120 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
121 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
122 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
123 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
124 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
125 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
126 elseif stanza.attr.type == "set" or stanza.attr.type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
127 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
128 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
129 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
130
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
131 -- COMPAT: reworked handle_to_room function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
132 hosts[muc_host].modules.muc.stanza_handler.muc_new_room.room_mt["handle_to_room"] = function (self, origin, stanza)
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
133 local type = stanza.attr.type;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
134 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
135 if stanza.name == "iq" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
136 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
137 origin.send(self:get_disco_info(stanza));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
138 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
139 origin.send(self:get_disco_items(stanza));
629
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
140 elseif xmlns == xmlns_ma or xmlns == xmlns_mo then
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
141 if xmlns == xmlns_ma then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
142 self:compat_iq(origin, stanza, xmlns);
629
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
143 elseif xmlns == xmlns_mo and (type == "set" or type == "get") and stanza.tags[1].name == "query" then
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
144 local owner_err = st.error_reply(stanza, "auth", "forbidden", "Only owners can configure rooms");
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
145 if #stanza.tags[1].tags == 0 and stanza.attr.type == "get" then
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
146 if self:get_affiliation(stanza.attr.from) ~= "owner" then
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
147 origin.send(owner_err);
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
148 else self:send_form(origin, stanza); end
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
149 elseif stanza.attr.type == "set" and stanza.tags[1]:get_child("x", "jabber:x:data") then
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
150 if self:get_affiliation(stanza.attr.from) ~= "owner" then
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
151 origin.send(owner_err);
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
152 else self:process_form(origin, stanza); end
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
153 elseif stanza.tags[1].tags[1].name == "destroy" then
628
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
154 if self:get_affiliation(stanza.attr.from) == "owner" then
631
c9084b4c14f0 mod_compat_muc_admin: corrected variable leftovers.
Marco Cirillo <maranda@lightwitch.org>
parents: 630
diff changeset
155 local newjid = stanza.tags[1].tags[1].attr.jid;
628
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
156 local reason, password;
631
c9084b4c14f0 mod_compat_muc_admin: corrected variable leftovers.
Marco Cirillo <maranda@lightwitch.org>
parents: 630
diff changeset
157 for _,tag in ipairs(stanza.tags[1].tags[1].tags) do
628
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
158 if tag.name == "reason" then
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
159 reason = #tag.tags == 0 and tag[1];
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
160 elseif tag.name == "password" then
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
161 password = #tag.tags == 0 and tag[1];
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
162 end
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
163 end
628
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
164 self:destroy(newjid, reason, password);
c72be31941fa mod_compat_muc_admin: we shall make sure that only owners can destroy rooms and not everyone, isn't it?
Marco Cirillo <maranda@lightwitch.org>
parents: 627
diff changeset
165 origin.send(st.reply(stanza));
629
7d4cde86b12e mod_compat_muc_admin: general cleanup, adding missing locals from muc.lib.lua (since things aren't inflated enough already)
Marco Cirillo <maranda@lightwitch.org>
parents: 628
diff changeset
166 else origin.send(owner_err); end
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
167 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
168 self:compat_iq(origin, stanza, xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
169 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
170 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
171 origin.send(st.error_reply(stanza, "modify", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
172 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
173 elseif type == "set" or type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
174 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
175 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
176 elseif stanza.name == "message" and type == "groupchat" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
177 local from, to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
178 local room = jid_bare(to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
179 local current_nick = self._jid_nick[from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
180 local occupant = self._occupants[current_nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
181 if not occupant then -- not in room
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
182 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
183 elseif occupant.role == "visitor" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
184 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
185 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
186 local from = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
187 stanza.attr.from = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
188 local subject = getText(stanza, {"subject"});
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
189 if subject then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
190 if occupant.role == "moderator" or
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
191 ( self._data.changesubject and occupant.role == "participant" ) then -- and participant
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
192 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
193 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
194 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
195 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
196 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
197 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
198 self:broadcast_message(stanza, true);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
199 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
200 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
201 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
202 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
203 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
204 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
205 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
206 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
207 local to = stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
208 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
209 if current_nick then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
210 stanza.attr.to = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
211 self:handle_to_occupant(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
212 stanza.attr.to = to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
213 elseif type ~= "error" and type ~= "result" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
214 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
215 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
216 elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and self._jid_nick[stanza.attr.from]
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
217 and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
218 local x = stanza.tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
219 local payload = (#x.tags == 1 and x.tags[1]);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
220 if payload and payload.name == "invite" and payload.attr.to then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
221 local _from, _to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
222 local _invitee = jid_prep(payload.attr.to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
223 if _invitee then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
224 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
225 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
226 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
227 :tag('invite', {from=_from})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
228 :tag('reason'):text(_reason or ""):up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
229 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
230 if self:get_password() then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
231 invite:tag("password"):text(self:get_password()):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
232 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
233 invite:up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
234 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
235 :text(_reason or "")
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
236 :up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
237 :tag('body') -- Add a plain message for clients which don't support invites
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
238 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or ""))
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
239 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
240 if self:is_members_only() and not self:get_affiliation(_invitee) then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
241 log("debug", "%s invited %s into members only room %s, granting membership", _from, _invitee, _to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
242 self:set_affiliation(_from, _invitee, "member", nil, "Invited by " .. self._jid_nick[_from])
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
243 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
244 self:_route_stanza(invite);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
245 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
246 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
247 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
248 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
249 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
250 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
251 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
252 if type == "error" or type == "result" then return; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
253 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
254 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
255 end