Annotate

plugins/muc/muc.lib.lua @ 3446:9c0b3cd890e9

MUC: Fixed: Unavilable presence was not being broadcasted for banned users in some cases (thanks Zash).
author Waqas Hussain <waqas20@gmail.com>
date Tue, 03 Aug 2010 21:37:06 +0500
parent 3445:2fde9cb97f76
child 3506:0f46acca11cc
child 3507:b639042bb0d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2864
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2864
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 --
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 --
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8
3281
fd6ab269ecc2 MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents: 3280
diff changeset
9 local select = select;
fd6ab269ecc2 MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents: 3280
diff changeset
10 local pairs, ipairs = pairs, ipairs;
fd6ab269ecc2 MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents: 3280
diff changeset
11
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local datamanager = require "util.datamanager";
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local datetime = require "util.datetime";
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 local jid_split = require "util.jid".split;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 local jid_bare = require "util.jid".bare;
1862
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
17 local jid_prep = require "util.jid".prep;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 local st = require "util.stanza";
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 local log = require "util.logger".init("mod_muc");
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 local multitable_new = require "util.multitable".new;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 local t_insert, t_remove = table.insert, table.remove;
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
22 local setmetatable = setmetatable;
1778
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
23 local base64 = require "util.encodings".base64;
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
24 local md5 = require "util.hashes".md5;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 local muc_domain = nil; --module:get_host();
3330
bdc325ce9fbc MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
Matthew Wild <mwild1@gmail.com>
parents: 3281
diff changeset
27 local default_history_length = 20;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 ------------
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 local function filter_xmlns_from_array(array, filters)
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 local count = 0;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 for i=#array,1,-1 do
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 local attr = array[i].attr;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 if filters[attr and attr.xmlns] then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 t_remove(array, i);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 count = count + 1;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 return count;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 local function filter_xmlns_from_stanza(stanza, filters)
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 if filters then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 if filter_xmlns_from_array(stanza.tags, filters) ~= 0 then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 return stanza, filter_xmlns_from_array(stanza, filters);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 return stanza, 0;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true};
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 local function get_filtered_presence(stanza)
1999
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
51 return filter_xmlns_from_stanza(st.clone(stanza):reset(), presence_filters);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 local kickable_error_conditions = {
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 ["gone"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 ["internal-server-error"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 ["item-not-found"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 ["jid-malformed"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 ["recipient-unavailable"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 ["redirect"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 ["remote-server-not-found"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 ["remote-server-timeout"] = true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 ["service-unavailable"] = true;
1999
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
63 ["malformed error"] = true;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 };
2527
3fe3dbb27b6f MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents: 2504
diff changeset
65
1999
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
66 local function get_error_condition(stanza)
2527
3fe3dbb27b6f MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents: 2504
diff changeset
67 local _, condition = stanza:get_error();
3fe3dbb27b6f MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents: 2504
diff changeset
68 return condition or "malformed error";
1999
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
69 end
2527
3fe3dbb27b6f MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents: 2504
diff changeset
70
1999
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
71 local function is_kickable_error(stanza)
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
72 local cond = get_error_condition(stanza);
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
73 return kickable_error_conditions[cond] and cond;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 local function getUsingPath(stanza, path, getText)
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 local tag = stanza;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 for _, name in ipairs(path) do
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 if type(tag) ~= 'table' then return; end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 tag = tag:child_with_name(name);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81 if tag and getText then tag = table.concat(tag); end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 return tag;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 local function getTag(stanza, path) return getUsingPath(stanza, path); end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
85 local function getText(stanza, path) return getUsingPath(stanza, path, true); end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
86 -----------
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
88 local room_mt = {};
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
89 room_mt.__index = room_mt;
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
90
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
91 function room_mt:get_default_role(affiliation)
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
92 if affiliation == "owner" or affiliation == "admin" then
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
93 return "moderator";
3251
f2f9fe088f6e MUC: Updated room:get_default_role() to assign unaffiliated occupants a "visitor" role in moderated rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3250
diff changeset
94 elseif affiliation == "member" then
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
95 return "participant";
3251
f2f9fe088f6e MUC: Updated room:get_default_role() to assign unaffiliated occupants a "visitor" role in moderated rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3250
diff changeset
96 elseif not affiliation then
3255
6bffb5c63131 MUC: Updated room:get_default_role() to not assign unaffiliated occupants a role in members-only rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3254
diff changeset
97 if not self:is_members_only() then
6bffb5c63131 MUC: Updated room:get_default_role() to not assign unaffiliated occupants a role in members-only rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3254
diff changeset
98 return self:is_moderated() and "visitor" or "participant";
6bffb5c63131 MUC: Updated room:get_default_role() to not assign unaffiliated occupants a role in members-only rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3254
diff changeset
99 end
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
100 end
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
101 end
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
102
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
103 function room_mt:broadcast_presence(stanza, sid, code, nick)
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 stanza = get_filtered_presence(stanza);
1825
f67e4bfc62f1 MUC: Renamed a variable name.
Waqas Hussain <waqas20@gmail.com>
parents: 1824
diff changeset
105 local occupant = self._occupants[stanza.attr.from];
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
2053
f5a198127dd3 MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents: 2051
diff changeset
107 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none", nick=nick}):up();
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108 if code then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 stanza:tag("status", {code=code}):up();
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 end
1824
8e66c9d09f81 MUC: Refactored to remove some duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 1819
diff changeset
111 self:broadcast_except_nick(stanza, stanza.attr.from);
8e66c9d09f81 MUC: Refactored to remove some duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents: 1819
diff changeset
112 local me = self._occupants[stanza.attr.from];
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
113 if me then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
114 stanza:tag("status", {code='110'});
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
115 stanza.attr.to = sid;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
116 self:_route_stanza(stanza);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 end
1736
98f833669d7f MUC: Fixed function declarations.
Waqas Hussain <waqas20@gmail.com>
parents: 1735
diff changeset
119 function room_mt:broadcast_message(stanza, historic)
2172
84dd0fada45b MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents: 2064
diff changeset
120 local to = stanza.attr.to;
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
121 for occupant, o_data in pairs(self._occupants) do
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
122 for jid in pairs(o_data.sessions) do
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
123 stanza.attr.to = jid;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
124 self:_route_stanza(stanza);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
125 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
126 end
2172
84dd0fada45b MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents: 2064
diff changeset
127 stanza.attr.to = to;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
128 if historic then -- add to history
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
129 local history = self._data['history'];
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
130 if not history then history = {}; self._data['history'] = history; end
2172
84dd0fada45b MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents: 2064
diff changeset
131 stanza = st.clone(stanza);
2880
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
132 stanza.attr.to = "";
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
133 local stamp = datetime.datetime();
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
134 local chars = #tostring(stanza);
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
135 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
2880
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
137 local entry = { stanza = stanza, stamp = stamp };
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
138 t_insert(history, entry);
3361
8d4e7c231d3e MUC: Fixed a traceback introduced in hg:bdc325ce9fbc.
Waqas Hussain <waqas20@gmail.com>
parents: 3330
diff changeset
139 while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 end
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
142 function room_mt:broadcast_except_nick(stanza, nick)
1751
55ee6e792e3e MUC: Fixed a variable scoping bug causing problems with presence routing on affiliation/role change.
Waqas Hussain <waqas20@gmail.com>
parents: 1750
diff changeset
143 for rnick, occupant in pairs(self._occupants) do
55ee6e792e3e MUC: Fixed a variable scoping bug causing problems with presence routing on affiliation/role change.
Waqas Hussain <waqas20@gmail.com>
parents: 1750
diff changeset
144 if rnick ~= nick then
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
145 for jid in pairs(occupant.sessions) do
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
146 stanza.attr.to = jid;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
147 self:_route_stanza(stanza);
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
148 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
149 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
150 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
151 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
152
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
153 function room_mt:send_occupant_list(to)
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
154 local current_nick = self._jid_nick[to];
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
155 for occupant, o_data in pairs(self._occupants) do
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
156 if occupant ~= current_nick then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
157 local pres = get_filtered_presence(o_data.sessions[o_data.jid]);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
158 pres.attr.to, pres.attr.from = to, occupant;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
159 pres:tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
2053
f5a198127dd3 MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents: 2051
diff changeset
160 :tag("item", {affiliation=o_data.affiliation or "none", role=o_data.role or "none"}):up();
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
161 self:_route_stanza(pres);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
162 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
163 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
164 end
2880
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
165 function room_mt:send_history(to, stanza)
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
166 local history = self._data['history']; -- send discussion history
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
167 if history then
2880
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
168 local x_tag = stanza and stanza:get_child("x", "http://jabber.org/protocol/muc");
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
169 local history_tag = x_tag and x_tag:get_child("history", "http://jabber.org/protocol/muc");
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
170
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
171 local maxchars = history_tag and tonumber(history_tag.attr.maxchars);
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
172 if maxchars then maxchars = math.floor(maxchars); end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
173
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
174 local maxstanzas = math.floor(history_tag and tonumber(history_tag.attr.maxstanzas) or #history);
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
175 if not history_tag then maxstanzas = 20; end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
176
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
177 local seconds = history_tag and tonumber(history_tag.attr.seconds);
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
178 if seconds then seconds = datetime.datetime(os.time() - math.floor(seconds)); end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
179
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
180 local since = history_tag and history_tag.attr.since;
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
181 if since and not since:match("^%d%d%d%d%-%d%d%-%d%dT%d%d:%d%d:%d%dZ$") then since = nil; end -- FIXME timezone support
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
182 if seconds and (not since or since < seconds) then since = seconds; end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
183
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
184 local n = 0;
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
185 local charcount = 0;
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
186 local stanzacount = 0;
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
187
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
188 for i=#history,1,-1 do
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
189 local entry = history[i];
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
190 if maxchars then
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
191 if not entry.chars then
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
192 entry.stanza.attr.to = "";
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
193 entry.chars = #tostring(entry.stanza);
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
194 end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
195 charcount = charcount + entry.chars + #to;
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
196 if charcount > maxchars then break; end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
197 end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
198 if since and since > entry.stamp then break; end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
199 if n + 1 > maxstanzas then break; end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
200 n = n + 1;
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
201 end
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
202 for i=#history-n+1,#history do
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
203 local msg = history[i].stanza;
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
204 msg.attr.to = to;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
205 self:_route_stanza(msg);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
206 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
207 end
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
208 if self._data['subject'] then
3393
5b8de0731c4d MUC: Store the nick (full room JID) which set the subject, and send subject to occupants from that JID.
Waqas Hussain <waqas20@gmail.com>
parents: 3361
diff changeset
209 self:_route_stanza(st.message({type='groupchat', from=self._data['subject_from'] or self.jid, to=to}):tag("subject"):text(self._data['subject']));
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
210 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
211 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
212
2503
bb6b0bd7f2cf MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents: 2416
diff changeset
213 function room_mt:get_disco_info(stanza)
1808
e164fdb2d18f MUC: Added MUC feature to the disco#info replies of rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1778
diff changeset
214 return st.reply(stanza):query("http://jabber.org/protocol/disco#info")
e164fdb2d18f MUC: Added MUC feature to the disco#info replies of rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1778
diff changeset
215 :tag("identity", {category="conference", type="text"}):up()
3246
3371419eb0e1 MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents: 3245
diff changeset
216 :tag("feature", {var="http://jabber.org/protocol/muc"}):up()
3371419eb0e1 MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents: 3245
diff changeset
217 :tag("feature", {var=self:get_password() and "muc_passwordprotected" or "muc_unsecured"}):up()
3253
23a30abcc76e MUC: Added disco#info features to advertise room's moderation status (muc_moderated or muc_unmoderated).
Waqas Hussain <waqas20@gmail.com>
parents: 3252
diff changeset
218 :tag("feature", {var=self:is_moderated() and "muc_moderated" or "muc_unmoderated"}):up()
3257
fae054e15e03 MUC: Added disco#info features to advertise room's members-only status (muc_membersonly or muc_open).
Waqas Hussain <waqas20@gmail.com>
parents: 3256
diff changeset
219 :tag("feature", {var=self:is_members_only() and "muc_membersonly" or "muc_open"}):up()
3260
19b655a8671c MUC: Added disco#info features to advertise room's persistence status (muc_persistent or muc_temporary).
Waqas Hussain <waqas20@gmail.com>
parents: 3259
diff changeset
220 :tag("feature", {var=self:is_persistent() and "muc_persistent" or "muc_temporary"}):up()
3263
4973b737d4c7 MUC: Added disco#info features to advertise room's public status (muc_public or muc_hidden).
Waqas Hussain <waqas20@gmail.com>
parents: 3262
diff changeset
221 :tag("feature", {var=self:is_hidden() and "muc_hidden" or "muc_public"}):up()
3264
e1c787c6f86e MUC: Added disco#info features to advertise room's anonymity status (muc_semianonymous or muc_nonanonymous).
Waqas Hussain <waqas20@gmail.com>
parents: 3263
diff changeset
222 :tag("feature", {var=self._data.whois ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up()
3246
3371419eb0e1 MUC: Added disco#info features to advertise room's password protection (muc_passwordprotected or muc_unsecured, depending on whether a password is set).
Waqas Hussain <waqas20@gmail.com>
parents: 3245
diff changeset
223 ;
1756
b2291156a9c2 MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1755
diff changeset
224 end
2503
bb6b0bd7f2cf MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents: 2416
diff changeset
225 function room_mt:get_disco_items(stanza)
2035
b8c3dbf76a2e MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents: 2008
diff changeset
226 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items");
b8c3dbf76a2e MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents: 2008
diff changeset
227 for room_jid in pairs(self._occupants) do
b8c3dbf76a2e MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents: 2008
diff changeset
228 reply:tag("item", {jid = room_jid, name = room_jid:match("/(.*)")}):up();
b8c3dbf76a2e MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents: 2008
diff changeset
229 end
b8c3dbf76a2e MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents: 2008
diff changeset
230 return reply;
1756
b2291156a9c2 MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1755
diff changeset
231 end
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
232 function room_mt:set_subject(current_nick, subject)
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
233 -- TODO check nick's authority
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
234 if subject == "" then subject = nil; end
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
235 self._data['subject'] = subject;
3393
5b8de0731c4d MUC: Store the nick (full room JID) which set the subject, and send subject to occupants from that JID.
Waqas Hussain <waqas20@gmail.com>
parents: 3361
diff changeset
236 self._data['subject_from'] = current_nick;
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
237 if self.save then self:save(); end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
238 local msg = st.message({type='groupchat', from=current_nick})
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
239 :tag('subject'):text(subject):up();
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
240 self:broadcast_message(msg, false);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
241 return true;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
242 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
243
2529
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
244 local function build_unavailable_presence_from_error(stanza)
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
245 local type, condition, text = stanza:get_error();
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
246 local error_message = "Kicked: "..condition:gsub("%-", " ");
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
247 if text then
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
248 error_message = error_message..": "..text;
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
249 end
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
250 return st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to})
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
251 :tag('status'):text(error_message);
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
252 end
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
253
3244
616a3bb2bad9 MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents: 2985
diff changeset
254 function room_mt:set_password(password)
616a3bb2bad9 MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents: 2985
diff changeset
255 if password == "" or type(password) ~= "string" then password = nil; end
3249
95daf6398dbb MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents: 3248
diff changeset
256 if self._data.password ~= password then
95daf6398dbb MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents: 3248
diff changeset
257 self._data.password = password;
95daf6398dbb MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents: 3248
diff changeset
258 if self.save then self:save(true); end
95daf6398dbb MUC: Persist data in room:set_password() when called programmatically.
Waqas Hussain <waqas20@gmail.com>
parents: 3248
diff changeset
259 end
3244
616a3bb2bad9 MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents: 2985
diff changeset
260 end
616a3bb2bad9 MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents: 2985
diff changeset
261 function room_mt:get_password()
616a3bb2bad9 MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents: 2985
diff changeset
262 return self._data.password;
616a3bb2bad9 MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents: 2985
diff changeset
263 end
3250
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
264 function room_mt:set_moderated(moderated)
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
265 moderated = moderated and true or nil;
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
266 if self._data.moderated ~= moderated then
3252
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
267 self._data.moderated = moderated;
3250
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
268 if self.save then self:save(true); end
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
269 end
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
270 end
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
271 function room_mt:is_moderated()
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
272 return self._data.moderated;
38402e874b45 MUC: Added room:set_moderated(boolean) and room:is_moderated().
Waqas Hussain <waqas20@gmail.com>
parents: 3249
diff changeset
273 end
3254
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
274 function room_mt:set_members_only(members_only)
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
275 members_only = members_only and true or nil;
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
276 if self._data.members_only ~= members_only then
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
277 self._data.members_only = members_only;
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
278 if self.save then self:save(true); end
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
279 end
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
280 end
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
281 function room_mt:is_members_only()
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
282 return self._data.members_only;
a01c6411fdfb MUC: Added room:set_members_only(boolean) and room:is_members_only().
Waqas Hussain <waqas20@gmail.com>
parents: 3253
diff changeset
283 end
3258
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
284 function room_mt:set_persistent(persistent)
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
285 persistent = persistent and true or nil;
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
286 if self._data.persistent ~= persistent then
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
287 self._data.persistent = persistent;
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
288 if self.save then self:save(true); end
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
289 end
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
290 end
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
291 function room_mt:is_persistent()
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
292 return self._data.persistent;
bc07564bec6d MUC: Added room:set_persistent(boolean) and room:is_persistent().
Waqas Hussain <waqas20@gmail.com>
parents: 3257
diff changeset
293 end
3261
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
294 function room_mt:set_hidden(hidden)
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
295 hidden = hidden and true or nil;
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
296 if self._data.hidden ~= hidden then
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
297 self._data.hidden = hidden;
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
298 if self.save then self:save(true); end
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
299 end
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
300 end
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
301 function room_mt:is_hidden()
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
302 return self._data.hidden;
fe1c93296abd MUC: Added room:set_hidden(boolean) and room:is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3260
diff changeset
303 end
3244
616a3bb2bad9 MUC: Added room:get_password() and room:set_password().
Waqas Hussain <waqas20@gmail.com>
parents: 2985
diff changeset
304
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
305 function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
306 local from, to = stanza.attr.from, stanza.attr.to;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
307 local room = jid_bare(to);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
308 local current_nick = self._jid_nick[from];
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
309 local type = stanza.attr.type;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
310 log("debug", "room: %s, current_nick: %s, stanza: %s", room or "nil", current_nick or "nil", stanza:top_tag());
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
311 if (select(2, jid_split(from)) == muc_domain) then error("Presence from the MUC itself!!!"); end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
312 if stanza.name == "presence" then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
313 local pr = get_filtered_presence(stanza);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
314 pr.attr.from = current_nick;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
315 if type == "error" then -- error, kick em out!
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
316 if current_nick then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
317 log("debug", "kicking %s from %s", current_nick, room);
2529
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
318 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza));
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
319 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
320 elseif type == "unavailable" then -- unavailable
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
321 if current_nick then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
322 log("debug", "%s leaving %s", current_nick, room);
1826
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
323 local occupant = self._occupants[current_nick];
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
324 local new_jid = next(occupant.sessions);
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
325 if new_jid == from then new_jid = next(occupant.sessions, new_jid); end
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
326 if new_jid then
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
327 local jid = occupant.jid;
1826
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
328 occupant.jid = new_jid;
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
329 occupant.sessions[from] = nil;
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
330 pr.attr.to = from;
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
331 pr:tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
2053
f5a198127dd3 MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents: 2051
diff changeset
332 :tag("item", {affiliation=occupant.affiliation or "none", role='none'}):up()
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
333 :tag("status", {code='110'});
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
334 self:_route_stanza(pr);
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
335 if jid ~= new_jid then
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
336 pr = st.clone(occupant.sessions[new_jid])
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
337 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
2053
f5a198127dd3 MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents: 2051
diff changeset
338 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none"});
2051
2567f4bf0085 MUC: Fixed an issue with multi-session nicks where the 'from' attribute in a presence broadcast was not being properly set.
Waqas Hussain <waqas20@gmail.com>
parents: 2035
diff changeset
339 pr.attr.from = current_nick;
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
340 self:broadcast_except_nick(pr, current_nick);
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
341 end
1826
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
342 else
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
343 occupant.role = 'none';
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
344 self:broadcast_presence(pr, from);
1826
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
345 self._occupants[current_nick] = nil;
de165b5de254 MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents: 1825
diff changeset
346 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
347 self._jid_nick[from] = nil;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
348 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
349 elseif not type then -- available
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
350 if current_nick then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
351 --if #pr == #stanza or current_nick ~= to then -- commented because google keeps resending directed presence
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
352 if current_nick == to then -- simple presence
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
353 log("debug", "%s broadcasted presence", current_nick);
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
354 self._occupants[current_nick].sessions[from] = pr;
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
355 self:broadcast_presence(pr, from);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
356 else -- change nick
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
357 local occupant = self._occupants[current_nick];
2008
6b6b924ee558 MUC: Re-enable nick changes for non-multisession nicks.
Waqas Hussain <waqas20@gmail.com>
parents: 2006
diff changeset
358 local is_multisession = next(occupant.sessions, next(occupant.sessions));
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
359 if self._occupants[to] or is_multisession then
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
360 log("debug", "%s couldn't change nick", current_nick);
1818
a394e0bd4847 MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents: 1808
diff changeset
361 local reply = st.error_reply(stanza, "cancel", "conflict"):up();
a394e0bd4847 MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents: 1808
diff changeset
362 reply.tags[1].attr.code = "409";
a394e0bd4847 MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents: 1808
diff changeset
363 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
364 else
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
365 local data = self._occupants[current_nick];
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
366 local to_nick = select(3, jid_split(to));
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
367 if to_nick then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
368 log("debug", "%s (%s) changing nick to %s", current_nick, data.jid, to);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
369 local p = st.presence({type='unavailable', from=current_nick});
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
370 self:broadcast_presence(p, from, '303', to_nick);
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
371 self._occupants[current_nick] = nil;
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
372 self._occupants[to] = data;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
373 self._jid_nick[from] = to;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
374 pr.attr.from = to;
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
375 self._occupants[to].sessions[from] = pr;
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
376 self:broadcast_presence(pr, from);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
377 else
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
378 --TODO malformed-jid
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
379 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
380 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
381 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
382 --else -- possible rejoin
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
383 -- log("debug", "%s had connection replaced", current_nick);
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
384 -- self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to})
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
385 -- :tag('status'):text('Replaced by new connection'):up()); -- send unavailable
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
386 -- self:handle_to_occupant(origin, stanza); -- resend available
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
387 --end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
388 else -- enter room
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
389 local new_nick = to;
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
390 local is_merge;
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
391 if self._occupants[to] then
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
392 if jid_bare(from) ~= jid_bare(self._occupants[to].jid) then
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
393 new_nick = nil;
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
394 end
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
395 is_merge = true;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
396 end
3245
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
397 local password = stanza:get_child("x", "http://jabber.org/protocol/muc");
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
398 password = password and password:get_child("password", "http://jabber.org/protocol/muc");
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
399 password = password and password[1] ~= "" and password[1];
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
400 if self:get_password() and self:get_password() ~= password then
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
401 log("debug", "%s couldn't join due to invalid password: %s", from, to);
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
402 local reply = st.error_reply(stanza, "auth", "not-authorized"):up();
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
403 reply.tags[1].attr.code = "401";
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
404 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
a8a4c87a4fbf MUC: Added password checking on room join.
Waqas Hussain <waqas20@gmail.com>
parents: 3244
diff changeset
405 elseif not new_nick then
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
406 log("debug", "%s couldn't join due to nick conflict: %s", from, to);
1818
a394e0bd4847 MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents: 1808
diff changeset
407 local reply = st.error_reply(stanza, "cancel", "conflict"):up();
a394e0bd4847 MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents: 1808
diff changeset
408 reply.tags[1].attr.code = "409";
a394e0bd4847 MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents: 1808
diff changeset
409 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
410 else
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
411 log("debug", "%s joining as %s", from, to);
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
412 if not next(self._affiliations) then -- new room, no owners
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
413 self._affiliations[jid_bare(from)] = "owner";
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
414 end
1740
b37ccf9bec89 MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents: 1739
diff changeset
415 local affiliation = self:get_affiliation(from);
b37ccf9bec89 MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents: 1739
diff changeset
416 local role = self:get_default_role(affiliation)
b37ccf9bec89 MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents: 1739
diff changeset
417 if role then -- new occupant
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
418 if not is_merge then
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
419 self._occupants[to] = {affiliation=affiliation, role=role, jid=from, sessions={[from]=get_filtered_presence(stanza)}};
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
420 else
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
421 self._occupants[to].sessions[from] = get_filtered_presence(stanza);
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
422 end
1740
b37ccf9bec89 MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents: 1739
diff changeset
423 self._jid_nick[from] = to;
b37ccf9bec89 MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents: 1739
diff changeset
424 self:send_occupant_list(from);
b37ccf9bec89 MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents: 1739
diff changeset
425 pr.attr.from = to;
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
426 if not is_merge then
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
427 self:broadcast_presence(pr, from);
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
428 else
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
429 pr.attr.to = from;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
430 self:_route_stanza(pr:tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
2053
f5a198127dd3 MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents: 2051
diff changeset
431 :tag("item", {affiliation=affiliation or "none", role=role or "none"}):up()
1989
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
432 :tag("status", {code='110'}));
97c3236cc4ac MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents: 1862
diff changeset
433 end
2880
a3f6cc3417f2 MUC: Added support for letting clients manage discussion history.
Waqas Hussain <waqas20@gmail.com>
parents: 2658
diff changeset
434 self:send_history(from, stanza);
3445
2fde9cb97f76 MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents: 3393
diff changeset
435 elseif not affiliation then -- registration required for entering members-only room
2fde9cb97f76 MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents: 3393
diff changeset
436 local reply = st.error_reply(stanza, "auth", "registration-required"):up();
2fde9cb97f76 MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents: 3393
diff changeset
437 reply.tags[1].attr.code = "407";
2fde9cb97f76 MUC: Return correct error to non-members attempting to enter a members-only room.
Waqas Hussain <waqas20@gmail.com>
parents: 3393
diff changeset
438 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
1740
b37ccf9bec89 MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents: 1739
diff changeset
439 else -- banned
1819
ed1911be26c7 MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents: 1818
diff changeset
440 local reply = st.error_reply(stanza, "auth", "forbidden"):up();
ed1911be26c7 MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents: 1818
diff changeset
441 reply.tags[1].attr.code = "403";
ed1911be26c7 MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents: 1818
diff changeset
442 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
443 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
444 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
445 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
446 elseif type ~= 'result' then -- bad type
1998
40792c18a8e4 MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents: 1997
diff changeset
447 if type ~= 'visible' and type ~= 'invisible' then -- COMPAT ejabberd can broadcast or forward XEP-0018 presences
40792c18a8e4 MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents: 1997
diff changeset
448 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error?
40792c18a8e4 MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents: 1997
diff changeset
449 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
450 end
1778
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
451 elseif not current_nick then -- not in room
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
452 if type == "error" or type == "result" then
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
453 local id = stanza.name == "iq" and stanza.attr.id and base64.decode(stanza.attr.id);
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
454 local _nick, _id, _hash = (id or ""):match("^(.+)%z(.*)%z(.+)$");
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
455 local occupant = self._occupants[stanza.attr.to];
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
456 if occupant and _nick and self._jid_nick[_nick] and _id and _hash then
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
457 local id, _to = stanza.attr.id;
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
458 for jid in pairs(occupant.sessions) do
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
459 if md5(jid) == _hash then
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
460 _to = jid;
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
461 break;
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
462 end
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
463 end
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
464 if _to then
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
465 stanza.attr.to, stanza.attr.from, stanza.attr.id = _to, self._jid_nick[_nick], _id;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
466 self:_route_stanza(stanza);
1778
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
467 stanza.attr.to, stanza.attr.from, stanza.attr.id = to, from, id;
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
468 end
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
469 end
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
470 else
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
471 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
472 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
473 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
474 origin.send(st.error_reply(stanza, "modify", "bad-request"));
1999
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
475 elseif current_nick and stanza.name == "message" and type == "error" and is_kickable_error(stanza) then
1996
3e6b36c6d7b7 MUC: Kick occupants on sending error messages to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents: 1989
diff changeset
476 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid);
2529
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
477 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
478 else -- private stanza
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
479 local o_data = self._occupants[to];
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
480 if o_data then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
481 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
482 local jid = o_data.jid;
1778
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
483 local bare = jid_bare(jid);
1769
39865fbbb2f7 MUC: Preserve stanza attributes for private messages.
Waqas Hussain <waqas20@gmail.com>
parents: 1768
diff changeset
484 stanza.attr.to, stanza.attr.from = jid, current_nick;
1778
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
485 local id = stanza.attr.id;
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
486 if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' and bare ~= jid then
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
487 stanza.attr.to = bare;
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
488 stanza.attr.id = base64.encode(jid.."\0"..id.."\0"..md5(from));
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
489 end
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
490 self:_route_stanza(stanza);
1778
f4213d84ba8a MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents: 1769
diff changeset
491 stanza.attr.to, stanza.attr.from, stanza.attr.id = to, from, id;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
492 elseif type ~= "error" and type ~= "result" then -- recipient not in room
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
493 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room"));
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
494 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
495 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
496 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
497
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
498 function room_mt:send_form(origin, stanza)
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
499 local title = "Configuration for "..self.jid;
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
500 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner")
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
501 :tag("x", {xmlns='jabber:x:data', type='form'})
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
502 :tag("title"):text(title):up()
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
503 :tag("instructions"):text(title):up()
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
504 :tag("field", {type='hidden', var='FORM_TYPE'}):tag("value"):text("http://jabber.org/protocol/muc#roomconfig"):up():up()
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
505 :tag("field", {type='boolean', label='Make Room Persistent?', var='muc#roomconfig_persistentroom'})
3259
a5b9209efb23 MUC: Replaced direct access of room's internal persistence state with :set_persistent(boolean) and :is_persistent() in various functions.
Waqas Hussain <waqas20@gmail.com>
parents: 3258
diff changeset
506 :tag("value"):text(self:is_persistent() and "1" or "0"):up()
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
507 :up()
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
508 :tag("field", {type='boolean', label='Make Room Publicly Searchable?', var='muc#roomconfig_publicroom'})
3262
330010ef078f MUC: Updated code to use :set_hidden() and :is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3261
diff changeset
509 :tag("value"):text(self:is_hidden() and "0" or "1"):up()
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
510 :up()
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
511 :tag("field", {type='list-single', label='Who May Discover Real JIDs?', var='muc#roomconfig_whois'})
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
512 :tag("value"):text(self._data.whois or 'moderators'):up()
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
513 :tag("option", {label = 'Moderators Only'})
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
514 :tag("value"):text('moderators'):up()
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
515 :up()
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
516 :tag("option", {label = 'Anyone'})
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
517 :tag("value"):text('anyone'):up()
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
518 :up()
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
519 :up()
3248
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
520 :tag("field", {type='text-private', label='Password', var='muc#roomconfig_roomsecret'})
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
521 :tag("value"):text(self:get_password() or ""):up()
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
522 :up()
3252
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
523 :tag("field", {type='boolean', label='Make Room Moderated?', var='muc#roomconfig_moderatedroom'})
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
524 :tag("value"):text(self:is_moderated() and "1" or "0"):up()
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
525 :up()
3256
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
526 :tag("field", {type='boolean', label='Make Room Members-Only?', var='muc#roomconfig_membersonly'})
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
527 :tag("value"):text(self:is_members_only() and "1" or "0"):up()
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
528 :up()
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
529 );
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
530 end
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
531
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
532 local valid_whois = {
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
533 moderators = true,
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
534 anyone = true,
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
535 }
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
536
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
537 function room_mt:process_form(origin, stanza)
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
538 local query = stanza.tags[1];
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
539 local form;
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
540 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
541 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
542 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
543 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
544 local fields = {};
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
545 for _, field in pairs(form.tags) do
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
546 if field.name == "field" and field.attr.var and field.tags[1].name == "value" and #field.tags[1].tags == 0 then
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
547 fields[field.attr.var] = field.tags[1][1] or "";
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
548 end
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
549 end
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
550 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
551
2412
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
552 local dirty = false
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
553
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
554 local persistent = fields['muc#roomconfig_persistentroom'];
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
555 if persistent == "0" or persistent == "false" then persistent = nil; elseif persistent == "1" or persistent == "true" then persistent = true;
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
556 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
3259
a5b9209efb23 MUC: Replaced direct access of room's internal persistence state with :set_persistent(boolean) and :is_persistent() in various functions.
Waqas Hussain <waqas20@gmail.com>
parents: 3258
diff changeset
557 dirty = dirty or (self:is_persistent() ~= persistent)
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
558 module:log("debug", "persistent=%s", tostring(persistent));
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
559
3252
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
560 local moderated = fields['muc#roomconfig_moderatedroom'];
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
561 if moderated == "0" or moderated == "false" then moderated = nil; elseif moderated == "1" or moderated == "true" then moderated = true;
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
562 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
563 dirty = dirty or (self:is_moderated() ~= moderated)
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
564 module:log("debug", "moderated=%s", tostring(moderated));
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
565
3256
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
566 local membersonly = fields['muc#roomconfig_membersonly'];
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
567 if membersonly == "0" or membersonly == "false" then membersonly = nil; elseif membersonly == "1" or membersonly == "true" then membersonly = true;
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
568 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
569 dirty = dirty or (self:is_members_only() ~= membersonly)
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
570 module:log("debug", "membersonly=%s", tostring(membersonly));
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
571
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
572 local public = fields['muc#roomconfig_publicroom'];
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
573 if public == "0" or public == "false" then public = nil; elseif public == "1" or public == "true" then public = true;
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
574 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
3262
330010ef078f MUC: Updated code to use :set_hidden() and :is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3261
diff changeset
575 dirty = dirty or (self:is_hidden() ~= (not public and true or nil))
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
576
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
577 local whois = fields['muc#roomconfig_whois'];
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
578 if not valid_whois[whois] then
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
579 origin.send(st.error_reply(stanza, 'cancel', 'bad-request'));
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
580 return;
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
581 end
2412
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
582 local whois_changed = self._data.whois ~= whois
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
583 self._data.whois = whois
3281
fd6ab269ecc2 MUC: A little modification to improve code analysis.
Waqas Hussain <waqas20@gmail.com>
parents: 3280
diff changeset
584 module:log('debug', 'whois=%s', whois)
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
585
3248
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
586 local password = fields['muc#roomconfig_roomsecret'];
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
587 if password then
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
588 self:set_password(password);
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
589 end
3252
22062c50eabe MUC: Added a 'Make Room Moderated?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3251
diff changeset
590 self:set_moderated(moderated);
3256
d96172f78ec2 MUC: Added a 'Make Room Members-Only?' field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3255
diff changeset
591 self:set_members_only(membersonly);
3259
a5b9209efb23 MUC: Replaced direct access of room's internal persistence state with :set_persistent(boolean) and :is_persistent() in various functions.
Waqas Hussain <waqas20@gmail.com>
parents: 3258
diff changeset
592 self:set_persistent(persistent);
3262
330010ef078f MUC: Updated code to use :set_hidden() and :is_hidden().
Waqas Hussain <waqas20@gmail.com>
parents: 3261
diff changeset
593 self:set_hidden(not public);
3248
f8d14ea3ad0e MUC: Added a password field to the room config dialog.
Waqas Hussain <waqas20@gmail.com>
parents: 3247
diff changeset
594
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
595 if self.save then self:save(true); end
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
596 origin.send(st.reply(stanza));
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
597
2412
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
598 if dirty or whois_changed then
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
599 local msg = st.message({type='groupchat', from=self.jid})
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
600 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}):up()
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
601
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
602 if dirty then
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
603 msg.tags[1]:tag('status', {code = '104'})
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
604 end
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
605 if whois_changed then
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
606 local code = (whois == 'moderators') and 173 or 172
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
607 msg.tags[1]:tag('status', {code = code})
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
608 end
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
609
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
610 self:broadcast_message(msg, false)
e243b7c81de6 Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents: 2411
diff changeset
611 end
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
612 end
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
613
2217
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
614 function room_mt:destroy(newjid, reason, password)
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
615 local pr = st.presence({type = "unavailable"})
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
616 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
617 :tag("item", { affiliation='none', role='none' }):up()
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
618 :tag("destroy", {jid=newjid})
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
619 if reason then pr:tag("reason"):text(reason):up(); end
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
620 if password then pr:tag("password"):text(password):up(); end
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
621 for nick, occupant in pairs(self._occupants) do
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
622 pr.attr.from = nick;
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
623 for jid in pairs(occupant.sessions) do
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
624 pr.attr.to = jid;
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
625 self:_route_stanza(pr);
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
626 self._jid_nick[jid] = nil;
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
627 end
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
628 self._occupants[nick] = nil;
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
629 end
3259
a5b9209efb23 MUC: Replaced direct access of room's internal persistence state with :set_persistent(boolean) and :is_persistent() in various functions.
Waqas Hussain <waqas20@gmail.com>
parents: 3258
diff changeset
630 self:set_persistent(false);
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
631 end
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
632
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
633 function room_mt:handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
634 local type = stanza.attr.type;
1745
15039fac3693 MUC: Some fixes for minor bugs in IQ handling.
Waqas Hussain <waqas20@gmail.com>
parents: 1744
diff changeset
635 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
636 if stanza.name == "iq" then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
637 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
2503
bb6b0bd7f2cf MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents: 2416
diff changeset
638 origin.send(self:get_disco_info(stanza));
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
639 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then
2503
bb6b0bd7f2cf MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents: 2416
diff changeset
640 origin.send(self:get_disco_items(stanza));
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
641 elseif xmlns == "http://jabber.org/protocol/muc#admin" then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
642 local actor = stanza.attr.from;
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
643 local affiliation = self:get_affiliation(actor);
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
644 local current_nick = self._jid_nick[actor];
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
645 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation);
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
646 local item = stanza.tags[1].tags[1];
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
647 if item and item.name == "item" then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
648 if type == "set" then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
649 local callback = function() origin.send(st.reply(stanza)); end
1862
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
650 if item.attr.jid then -- Validate provided JID
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
651 item.attr.jid = jid_prep(item.attr.jid);
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
652 if not item.attr.jid then
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
653 origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
654 return;
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
655 end
115f274dd17f MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents: 1826
diff changeset
656 end
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
657 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
658 local occupant = self._occupants[self.jid.."/"..item.attr.nick];
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
659 if occupant then item.attr.jid = occupant.jid; end
2864
1ce0e2ceb419 MUC: Allow role changes based on JIDs.
Waqas Hussain <waqas20@gmail.com>
parents: 2845
diff changeset
660 elseif not item.attr.nick and item.attr.jid then
1ce0e2ceb419 MUC: Allow role changes based on JIDs.
Waqas Hussain <waqas20@gmail.com>
parents: 2845
diff changeset
661 local nick = self._jid_nick[item.attr.jid];
1ce0e2ceb419 MUC: Allow role changes based on JIDs.
Waqas Hussain <waqas20@gmail.com>
parents: 2845
diff changeset
662 if nick then item.attr.nick = select(3, jid_split(nick)); end
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
663 end
2006
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
664 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1];
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
665 if item.attr.affiliation and item.attr.jid and not item.attr.role then
2006
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
666 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason);
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
667 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
668 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
2006
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
669 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason);
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
670 if not success then origin.send(st.error_reply(stanza, errtype, err)); end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
671 else
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
672 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
673 end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
674 elseif type == "get" then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
675 local _aff = item.attr.affiliation;
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
676 local _rol = item.attr.role;
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
677 if _aff and not _rol then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
678 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
679 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin");
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
680 for jid, affiliation in pairs(self._affiliations) do
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
681 if affiliation == _aff then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
682 reply:tag("item", {affiliation = _aff, jid = jid}):up();
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
683 end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
684 end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
685 origin.send(reply);
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
686 else
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
687 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
688 end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
689 elseif _rol and not _aff then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
690 if role == "moderator" then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
691 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway?
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
692 if _rol == "none" then _rol = nil; end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
693 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin");
2845
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
694 for occupant_jid, occupant in pairs(self._occupants) do
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
695 if occupant.role == _rol then
2845
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
696 reply:tag("item", {
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
697 nick = select(3, jid_split(occupant_jid)),
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
698 role = _rol or "none",
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
699 affiliation = occupant.affiliation or "none",
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
700 jid = occupant.jid
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
701 }):up();
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
702 end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
703 end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
704 origin.send(reply);
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
705 else
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
706 origin.send(st.error_reply(stanza, "auth", "forbidden"));
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
707 end
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
708 else
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
709 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
710 end
1744
265863a5612b MUC: Added support for requesting various lists (owner, admin, voice, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 1743
diff changeset
711 end
1753
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
712 elseif type == "set" or type == "get" then
a84901db4085 MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents: 1752
diff changeset
713 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
714 end
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
715 elseif xmlns == "http://jabber.org/protocol/muc#owner" and (type == "get" or type == "set") and stanza.tags[1].name == "query" then
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
716 if self:get_affiliation(stanza.attr.from) ~= "owner" then
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
717 origin.send(st.error_reply(stanza, "auth", "forbidden"));
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
718 elseif stanza.attr.type == "get" then
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
719 self:send_form(origin, stanza);
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
720 elseif stanza.attr.type == "set" then
2217
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
721 local child = stanza.tags[1].tags[1];
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
722 if not child then
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
723 origin.send(st.error_reply(stanza, "auth", "bad-request"));
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
724 elseif child.name == "destroy" then
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
725 local newjid = child.attr.jid;
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
726 local reason, password;
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
727 for _,tag in ipairs(child.tags) do
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
728 if tag.name == "reason" then
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
729 reason = #tag.tags == 0 and tag[1];
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
730 elseif tag.name == "password" then
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
731 password = #tag.tags == 0 and tag[1];
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
732 end
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
733 end
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
734 self:destroy(newjid, reason, password);
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
735 origin.send(st.reply(stanza));
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
736 else
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
737 self:process_form(origin, stanza);
838f6d546177 MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents: 2216
diff changeset
738 end
2216
dbbb5ed41365 MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents: 2174
diff changeset
739 end
1754
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
740 elseif type == "set" or type == "get" then
67b66eec9777 MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 1753
diff changeset
741 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
742 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
743 elseif stanza.name == "message" and type == "groupchat" then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
744 local from, to = stanza.attr.from, stanza.attr.to;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
745 local room = jid_bare(to);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
746 local current_nick = self._jid_nick[from];
2173
f9af31dbfeb8 MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents: 2172
diff changeset
747 local occupant = self._occupants[current_nick];
f9af31dbfeb8 MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents: 2172
diff changeset
748 if not occupant then -- not in room
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
749 origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
2173
f9af31dbfeb8 MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents: 2172
diff changeset
750 elseif occupant.role == "visitor" then
f9af31dbfeb8 MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents: 2172
diff changeset
751 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
752 else
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
753 local from = stanza.attr.from;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
754 stanza.attr.from = current_nick;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
755 local subject = getText(stanza, {"subject"});
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
756 if subject then
2174
13375e6c4ecb MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents: 2173
diff changeset
757 if occupant.role == "moderator" then
13375e6c4ecb MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents: 2173
diff changeset
758 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza
13375e6c4ecb MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents: 2173
diff changeset
759 else
13375e6c4ecb MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents: 2173
diff changeset
760 stanza.attr.from = from;
13375e6c4ecb MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents: 2173
diff changeset
761 origin.send(st.error_reply(stanza, "cancel", "forbidden"));
13375e6c4ecb MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents: 2173
diff changeset
762 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
763 else
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
764 self:broadcast_message(stanza, true);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
765 end
2172
84dd0fada45b MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents: 2064
diff changeset
766 stanza.attr.from = from;
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
767 end
1999
05054e360d89 MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents: 1998
diff changeset
768 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then
1768
802c40384dd0 MUC: Don't kick on errors in private messages.
Waqas Hussain <waqas20@gmail.com>
parents: 1764
diff changeset
769 local current_nick = self._jid_nick[stanza.attr.from];
802c40384dd0 MUC: Don't kick on errors in private messages.
Waqas Hussain <waqas20@gmail.com>
parents: 1764
diff changeset
770 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid);
2529
7968e8b3ecf9 MUC: Fixes and refactoring for the previous commit to work in all cases, text of error stanzas is now broadcast
Matthew Wild <mwild1@gmail.com>
parents: 2528
diff changeset
771 self:handle_to_occupant(origin, build_unavailable_presence_from_error(stanza)); -- send unavailable
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
772 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
773 local to = stanza.attr.to;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
774 local current_nick = self._jid_nick[stanza.attr.from];
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
775 if current_nick then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
776 stanza.attr.to = current_nick;
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
777 self:handle_to_occupant(origin, stanza);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
778 stanza.attr.to = to;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
779 elseif type ~= "error" and type ~= "result" then
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
780 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
781 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
782 elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and self._jid_nick[stanza.attr.from]
2005
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
783 and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
784 local x = stanza.tags[1];
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
785 local payload = (#x.tags == 1 and x.tags[1]);
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
786 if payload and payload.name == "invite" and payload.attr.to then
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
787 local _from, _to = stanza.attr.from, stanza.attr.to;
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
788 local _invitee = jid_prep(payload.attr.to);
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
789 if _invitee then
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
790 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1];
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
791 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id})
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
792 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
793 :tag('invite', {from=_from})
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
794 :tag('reason'):text(_reason or ""):up()
3247
ee8aaca3226c MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3246
diff changeset
795 :up();
ee8aaca3226c MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3246
diff changeset
796 if self:get_password() then
ee8aaca3226c MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3246
diff changeset
797 invite:tag("password"):text(self:get_password()):up();
ee8aaca3226c MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3246
diff changeset
798 end
ee8aaca3226c MUC: Include a <password/> element in invites from password protected rooms.
Waqas Hussain <waqas20@gmail.com>
parents: 3246
diff changeset
799 invite:up()
2005
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
800 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
801 :text(_reason or "")
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
802 :up()
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
803 :tag('body') -- Add a plain message for clients which don't support invites
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
804 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or ""))
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
805 :up();
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
806 self:_route_stanza(invite);
2005
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
807 else
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
808 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
809 end
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
810 else
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
811 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
478ba7e85862 MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents: 1999
diff changeset
812 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
813 else
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
814 if type == "error" or type == "result" then return; end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
815 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
816 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
817 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
818
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
819 function room_mt:handle_stanza(origin, stanza)
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
820 local to_node, to_host, to_resource = jid_split(stanza.attr.to);
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
821 if to_resource then
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
822 self:handle_to_occupant(origin, stanza);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
823 else
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
824 self:handle_to_room(origin, stanza);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
825 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
826 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
827
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
828 function room_mt:route_stanza(stanza) end -- Replace with a routing function, e.g., function(room, stanza) core_route_stanza(origin, stanza); end
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
829
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
830 function room_mt:get_affiliation(jid)
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
831 local node, host, resource = jid_split(jid);
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
832 local bare = node and node.."@"..host or host;
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
833 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID.
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
834 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
835 return result;
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
836 end
2006
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
837 function room_mt:set_affiliation(actor, jid, affiliation, callback, reason)
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
838 jid = jid_bare(jid);
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
839 if affiliation == "none" then affiliation = nil; end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
840 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
841 return nil, "modify", "not-acceptable";
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
842 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
843 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
844 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
845 self._affiliations[jid] = affiliation;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
846 local role = self:get_default_role(affiliation);
1750
a1c18470eeee MUC: Fixed: Unavailable presence was being sent for all role and affiliation changes. Now sent only for kicked occupants.
Waqas Hussain <waqas20@gmail.com>
parents: 1749
diff changeset
847 local p = st.presence()
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
848 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
2006
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
849 :tag("item", {affiliation=affiliation or "none", role=role or "none"})
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
850 :tag("reason"):text(reason or ""):up()
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
851 :up();
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
852 local x = p.tags[1];
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
853 local item = x.tags[1];
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
854 if not role then -- getting kicked
1750
a1c18470eeee MUC: Fixed: Unavailable presence was being sent for all role and affiliation changes. Now sent only for kicked occupants.
Waqas Hussain <waqas20@gmail.com>
parents: 1749
diff changeset
855 p.attr.type = "unavailable";
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
856 if affiliation == "outcast" then
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
857 x:tag("status", {code="301"}):up(); -- banned
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
858 else
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
859 x:tag("status", {code="321"}):up(); -- affiliation change
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
860 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
861 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
862 local modified_nicks = {};
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
863 for nick, occupant in pairs(self._occupants) do
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
864 if jid_bare(occupant.jid) == jid then
3446
9c0b3cd890e9 MUC: Fixed: Unavilable presence was not being broadcasted for banned users in some cases (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents: 3445
diff changeset
865 t_insert(modified_nicks, nick);
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
866 if not role then -- getting kicked
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
867 self._occupants[nick] = nil;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
868 else
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
869 occupant.affiliation, occupant.role = affiliation, role;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
870 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
871 p.attr.from = nick;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
872 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
873 if not role then self._jid_nick[jid] = nil; end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
874 p.attr.to = jid;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
875 self:_route_stanza(p);
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
876 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
877 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
878 end
1755
1614e8e62ad5 MUC: Fixed an undefined global access.
Waqas Hussain <waqas20@gmail.com>
parents: 1754
diff changeset
879 if self.save then self:save(); end
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
880 if callback then callback(); end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
881 for _, nick in ipairs(modified_nicks) do
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
882 p.attr.from = nick;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
883 self:broadcast_except_nick(p, nick);
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
884 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
885 return true;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
886 end
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
887
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
888 function room_mt:get_role(nick)
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
889 local session = self._occupants[nick];
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
890 return session and session.role or nil;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
891 end
3279
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
892 function room_mt:can_set_role(actor_jid, occupant_jid, role)
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
893 local actor = self._occupants[self._jid_nick[actor_jid]];
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
894 local occupant = self._occupants[occupant_jid];
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
895
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
896 if not occupant or not actor then return nil, "modify", "not-acceptable"; end
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
897
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
898 if actor.role == "moderator" then
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
899 if occupant.affiliation ~= "owner" and occupant.affiliation ~= "admin" then
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
900 if actor.affiliation == "owner" or actor.affiliation == "admin" then
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
901 return true;
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
902 elseif occupant.role ~= "moderator" and role ~= "moderator" then
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
903 return true;
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
904 end
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
905 end
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
906 end
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
907 return nil, "cancel", "not-allowed";
8b0a4a7d2c6e MUC: Added room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3264
diff changeset
908 end
2845
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
909 function room_mt:set_role(actor, occupant_jid, role, callback, reason)
1752
4db786919805 MUC: Added kicking support.
Waqas Hussain <waqas20@gmail.com>
parents: 1751
diff changeset
910 if role == "none" then role = nil; end
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
911 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end
3280
eef4f31f2d7b MUC: Updated room:set_role() to use room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3279
diff changeset
912 local allowed, err_type, err_condition = self:can_set_role(actor, occupant_jid, role);
eef4f31f2d7b MUC: Updated room:set_role() to use room:can_set_role().
Waqas Hussain <waqas20@gmail.com>
parents: 3279
diff changeset
913 if not allowed then return allowed, err_type, err_condition; end
2845
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
914 local occupant = self._occupants[occupant_jid];
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
915 local p = st.presence({from = occupant_jid})
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
916 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
2845
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
917 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"})
2006
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
918 :tag("reason"):text(reason or ""):up()
0c62bed9d338 MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents: 2005
diff changeset
919 :up();
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
920 if not role then -- kick
1750
a1c18470eeee MUC: Fixed: Unavailable presence was being sent for all role and affiliation changes. Now sent only for kicked occupants.
Waqas Hussain <waqas20@gmail.com>
parents: 1749
diff changeset
921 p.attr.type = "unavailable";
2845
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
922 self._occupants[occupant_jid] = nil;
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
923 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
924 self._jid_nick[jid] = nil;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
925 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
926 p:tag("status", {code = "307"}):up();
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
927 else
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
928 occupant.role = role;
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
929 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
930 for jid in pairs(occupant.sessions) do -- send to all sessions of the nick
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
931 p.attr.to = jid;
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
932 self:_route_stanza(p);
1742
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
933 end
1483a62d69bb MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1740
diff changeset
934 if callback then callback(); end
2845
f76139aa7cd5 MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 2174
diff changeset
935 self:broadcast_except_nick(p, occupant_jid);
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
936 return true;
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
937 end
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
938
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
939 function room_mt:_route_stanza(stanza)
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
940 local muc_child;
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
941 local to_occupant = self._occupants[self._jid_nick[stanza.attr.to]];
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
942 local from_occupant = self._occupants[stanza.attr.from];
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
943 if stanza.name == "presence" then
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
944 if to_occupant and from_occupant then
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
945 if self._data.whois == 'anyone' then
2416
89be536aae25 mod_muc/muc.lib: Use stanza:get_child() to locate MUC child element
Matthew Wild <mwild1@gmail.com>
parents: 2412
diff changeset
946 muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
947 else
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
948 if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then
2416
89be536aae25 mod_muc/muc.lib: Use stanza:get_child() to locate MUC child element
Matthew Wild <mwild1@gmail.com>
parents: 2412
diff changeset
949 muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
950 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
951 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
952 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
953 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
954 if muc_child then
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
955 for _, item in pairs(muc_child.tags) do
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
956 if item.name == "item" then
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
957 if from_occupant == to_occupant then
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
958 item.attr.jid = stanza.attr.to;
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
959 else
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
960 item.attr.jid = from_occupant.jid;
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
961 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
962 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
963 end
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
964 if self._data.whois == 'anyone' then
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
965 muc_child:tag('status', { code = '100' });
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
966 end
2064
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
967 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
968 self:route_stanza(stanza);
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
969 if muc_child then
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
970 for _, item in pairs(muc_child.tags) do
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
971 if item.name == "item" then
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
972 item.attr.jid = nil;
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
973 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
974 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
975 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
976 end
1ee862fd1afe MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents: 2053
diff changeset
977
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
978 local _M = {}; -- module "muc"
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
979
3330
bdc325ce9fbc MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
Matthew Wild <mwild1@gmail.com>
parents: 3281
diff changeset
980 function _M.new_room(jid, config)
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
981 return setmetatable({
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
982 jid = jid;
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
983 _jid_nick = {};
1739
393abf245322 MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents: 1737
diff changeset
984 _occupants = {};
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
985 _data = {
3330
bdc325ce9fbc MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
Matthew Wild <mwild1@gmail.com>
parents: 3281
diff changeset
986 whois = 'moderators';
3361
8d4e7c231d3e MUC: Fixed a traceback introduced in hg:bdc325ce9fbc.
Waqas Hussain <waqas20@gmail.com>
parents: 3330
diff changeset
987 history_length = (config and config.history_length);
2411
c2b6c55201af Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents: 2217
diff changeset
988 };
1737
31c3eb5797c7 MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents: 1736
diff changeset
989 _affiliations = {};
1735
81406277279e MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents: 1734
diff changeset
990 }, room_mt);
1734
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
991 end
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
992
34ac9ba0aad6 MUC: Added initial MUC lib
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
993 return _M;