annotate mod_compat_muc_admin/mod_compat_muc_admin.lua @ 654:7e444de959bb

mod_pastebin: Update to the new HTTP API
author Kim Alvefur <zash@zash.se>
date Sun, 29 Apr 2012 21:07:04 +0200
parents c9084b4c14f0
children 15a8b717597b
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 };
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
26 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
27 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
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 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
37 :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
38 end
630
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
39 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
40 local tag = stanza;
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
41 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
42 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
43 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
44 end
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
45 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
46 return tag;
ab2a1564da9b mod_compat_muc_admin: adding last missing local (getUsingPath).
Marco Cirillo <maranda@lightwitch.org>
parents: 629
diff changeset
47 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
48 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
49
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
50 -- COMPAT: iq condensed function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
51 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
52 local actor = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
53 local affiliation = self:get_affiliation(actor);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
54 local current_nick = self._jid_nick[actor];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
55 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
56 local item = stanza.tags[1].tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
57 if item and item.name == "item" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
58 if stanza.attr.type == "set" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
59 local callback = function() origin.send(st.reply(stanza)); end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
60 if item.attr.jid then -- Validate provided JID
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
61 item.attr.jid = jid_prep(item.attr.jid);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
62 if not item.attr.jid then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
63 origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
64 return;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
65 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
66 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
67 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
68 local occupant = self._occupants[self.jid.."/"..item.attr.nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
69 if occupant then item.attr.jid = occupant.jid; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
70 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
71 local nick = self._jid_nick[item.attr.jid];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
72 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
73 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
82 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
83 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
84 elseif stanza.attr.type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
85 local _aff = item.attr.affiliation;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
86 local _rol = item.attr.role;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
87 if _aff and not _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
88 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
89 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
90 for jid, affiliation in pairs(self._affiliations) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
91 if affiliation == _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
92 reply:tag("item", {affiliation = _aff, jid = jid}):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
93 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
94 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
95 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
96 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
97 origin.send(st.error_reply(stanza, "auth", "forbidden"));
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 elseif _rol and not _aff then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
100 if role == "moderator" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
101 -- 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
102 if _rol == "none" then _rol = nil; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
103 local reply = st.reply(stanza):query(xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
104 for occupant_jid, occupant in pairs(self._occupants) do
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
105 if occupant.role == _rol then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
106 reply:tag("item", {
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
107 nick = select(3, jid_split(occupant_jid)),
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
108 role = _rol or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
109 affiliation = occupant.affiliation or "none",
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
110 jid = occupant.jid
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
111 }):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
112 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
113 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
114 origin.send(reply);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
115 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
116 origin.send(st.error_reply(stanza, "auth", "forbidden"));
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 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
119 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
120 end
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 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
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
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
127 -- COMPAT: reworked handle_to_room function
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
128 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
129 local type = stanza.attr.type;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
130 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
131 if stanza.name == "iq" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
132 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
133 origin.send(self:get_disco_info(stanza));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
134 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
135 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
136 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
137 if xmlns == xmlns_ma then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
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: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
149 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
150 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
151 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
152 local reason, password;
631
c9084b4c14f0 mod_compat_muc_admin: corrected variable leftovers.
Marco Cirillo <maranda@lightwitch.org>
parents: 630
diff changeset
153 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
154 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
155 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
156 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
157 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
158 end
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
159 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
160 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
161 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
162 else origin.send(owner_err); end
627
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
163 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
164 self:compat_iq(origin, stanza, xmlns);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
165 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
166 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
167 origin.send(st.error_reply(stanza, "modify", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
168 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
169 elseif type == "set" or type == "get" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
170 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
171 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
172 elseif stanza.name == "message" and type == "groupchat" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
173 local from, to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
174 local room = jid_bare(to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
175 local current_nick = self._jid_nick[from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
176 local occupant = self._occupants[current_nick];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
177 if not occupant then -- not in room
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
178 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
179 elseif occupant.role == "visitor" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
180 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
181 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
182 local from = stanza.attr.from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
183 stanza.attr.from = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
184 local subject = getText(stanza, {"subject"});
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
185 if subject then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
186 if occupant.role == "moderator" or
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
187 ( 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
188 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
189 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
190 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
191 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
192 end
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 self:broadcast_message(stanza, true);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
195 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
196 stanza.attr.from = from;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
197 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
198 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
199 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
200 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
201 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
202 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
203 local to = stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
204 local current_nick = self._jid_nick[stanza.attr.from];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
205 if current_nick then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
206 stanza.attr.to = current_nick;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
207 self:handle_to_occupant(origin, stanza);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
208 stanza.attr.to = to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
209 elseif type ~= "error" and type ~= "result" then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
210 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
211 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
212 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
213 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
214 local x = stanza.tags[1];
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
215 local payload = (#x.tags == 1 and x.tags[1]);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
216 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
217 local _from, _to = stanza.attr.from, stanza.attr.to;
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
218 local _invitee = jid_prep(payload.attr.to);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
219 if _invitee then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
220 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
221 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
222 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
223 :tag('invite', {from=_from})
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
224 :tag('reason'):text(_reason or ""):up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
225 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
226 if self:get_password() then
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
227 invite:tag("password"):text(self:get_password()):up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
228 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
229 invite:up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
230 :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
231 :text(_reason or "")
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
232 :up()
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
233 :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
234 :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
235 :up();
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
236 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
237 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
238 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
239 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
240 self:_route_stanza(invite);
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
241 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
242 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
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 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
245 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
246 end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
247 else
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
248 if type == "error" or type == "result" then return; end
a8ff69c9b498 mod_compat_muc_admin: first commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
249 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
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 end