Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 1754:67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 07 Sep 2009 20:51:59 +0500 |
parent | 1748:f4c50c75af6f |
child | 1767:649dd3439809 |
comparison
equal
deleted
inserted
replaced
1753:a84901db4085 | 1754:67b66eec9777 |
---|---|
19 local register_component = require "core.componentmanager".register_component; | 19 local register_component = require "core.componentmanager".register_component; |
20 local deregister_component = require "core.componentmanager".deregister_component; | 20 local deregister_component = require "core.componentmanager".deregister_component; |
21 local jid_split = require "util.jid".split; | 21 local jid_split = require "util.jid".split; |
22 local st = require "util.stanza"; | 22 local st = require "util.stanza"; |
23 local uuid_gen = require "util.uuid".generate; | 23 local uuid_gen = require "util.uuid".generate; |
24 local datamanager = require "util.datamanager"; | |
24 | 25 |
25 local rooms = {}; | 26 local rooms = {}; |
27 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; | |
26 local component; | 28 local component; |
29 | |
30 local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end | |
31 local function room_save(room, forced) | |
32 local node = jid_split(room.jid); | |
33 persistent_rooms[room.jid] = room._data.persistent; | |
34 module:log("debug", "1, %s, %s", room.jid, tostring(room._data.persistent)); | |
35 if room._data.persistent then | |
36 module:log("debug", "2"); | |
37 local history = room._data.history; | |
38 room._data.history = nil; | |
39 local data = { | |
40 jid = room.jid; | |
41 _data = room._data; | |
42 _affiliations = room._affiliations; | |
43 }; | |
44 datamanager.store(node, muc_host, "config", data); | |
45 room._data.history = history; | |
46 elseif forced then | |
47 module:log("debug", "3"); | |
48 datamanager.store(node, muc_host, "config", nil); | |
49 end | |
50 module:log("debug", "4"); | |
51 if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end | |
52 end | |
53 | |
54 for jid in pairs(persistent_rooms) do | |
55 local node = jid_split(jid); | |
56 local data = datamanager.load(node, muc_host, "config") or {}; | |
57 local room = muc_new_room(jid); | |
58 room._data = data._data; | |
59 room._affiliations = data._affiliations; | |
60 room.route_stanza = room_route_stanza; | |
61 room.save = room_save; | |
62 rooms[jid] = room; | |
63 end | |
64 | |
27 local host_room = muc_new_room(muc_host); | 65 local host_room = muc_new_room(muc_host); |
28 host_room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; | 66 host_room.route_stanza = room_route_stanza; |
67 host_room.save = room_save; | |
29 | 68 |
30 local function get_disco_info(stanza) | 69 local function get_disco_info(stanza) |
31 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") | 70 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") |
32 :tag("identity", {category='conference', type='text', name=muc_name}):up() | 71 :tag("identity", {category='conference', type='text', name=muc_name}):up() |
33 :tag("feature", {var="http://jabber.org/protocol/muc"}); -- TODO cache disco reply | 72 :tag("feature", {var="http://jabber.org/protocol/muc"}); -- TODO cache disco reply |
34 end | 73 end |
35 local function get_disco_items(stanza) | 74 local function get_disco_items(stanza) |
36 local reply = st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); | 75 local reply = st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); |
37 for jid, room in pairs(rooms) do | 76 for jid, room in pairs(rooms) do |
38 reply:tag("item", {jid=jid, name=jid}):up(); | 77 if not room._data.hidden then |
78 reply:tag("item", {jid=jid, name=jid}):up(); | |
79 end | |
39 end | 80 end |
40 return reply; -- TODO cache disco reply | 81 return reply; -- TODO cache disco reply |
41 end | 82 end |
42 | 83 |
43 local function handle_to_domain(origin, stanza) | 84 local function handle_to_domain(origin, stanza) |
66 local bare = to_node.."@"..to_host; | 107 local bare = to_node.."@"..to_host; |
67 if to_host == muc_host or bare == muc_host then | 108 if to_host == muc_host or bare == muc_host then |
68 local room = rooms[bare]; | 109 local room = rooms[bare]; |
69 if not room then | 110 if not room then |
70 room = muc_new_room(bare); | 111 room = muc_new_room(bare); |
71 room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; | 112 room.route_stanza = room_route_stanza; |
113 room.save = room_save; | |
72 rooms[bare] = room; | 114 rooms[bare] = room; |
73 end | 115 end |
74 room:handle_stanza(origin, stanza); | 116 room:handle_stanza(origin, stanza); |
75 else --[[not for us?]] end | 117 else --[[not for us?]] end |
76 return; | 118 return; |
93 local room = muc_new_room(jid); | 135 local room = muc_new_room(jid); |
94 room._jid_nick = oldroom._jid_nick; | 136 room._jid_nick = oldroom._jid_nick; |
95 room._occupants = oldroom._occupants; | 137 room._occupants = oldroom._occupants; |
96 room._data = oldroom._data; | 138 room._data = oldroom._data; |
97 room._affiliations = oldroom._affiliations; | 139 room._affiliations = oldroom._affiliations; |
98 room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; | 140 room.route_stanza = room_route_stanza; |
141 room.save = room_save; | |
99 rooms[jid] = room; | 142 rooms[jid] = room; |
100 end | 143 end |
101 prosody.hosts[module:get_host()].muc = { rooms = rooms }; | 144 prosody.hosts[module:get_host()].muc = { rooms = rooms }; |
102 end | 145 end |