Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 5024:d25e1b9332cc
Merge with Florob
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 28 Jul 2012 01:14:31 +0100 |
parent | 5016:56a0b13a3d42 |
child | 5058:433cc9a4c7e9 |
comparison
equal
deleted
inserted
replaced
5023:dcc8e789df36 | 5024:d25e1b9332cc |
---|---|
27 local jid_bare = require "util.jid".bare; | 27 local jid_bare = require "util.jid".bare; |
28 local st = require "util.stanza"; | 28 local st = require "util.stanza"; |
29 local uuid_gen = require "util.uuid".generate; | 29 local uuid_gen = require "util.uuid".generate; |
30 local datamanager = require "util.datamanager"; | 30 local datamanager = require "util.datamanager"; |
31 local um_is_admin = require "core.usermanager".is_admin; | 31 local um_is_admin = require "core.usermanager".is_admin; |
32 local hosts = hosts; | |
32 | 33 |
33 rooms = {}; | 34 rooms = {}; |
34 local rooms = rooms; | 35 local rooms = rooms; |
35 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; | 36 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; |
36 local component = hosts[module.host]; | |
37 | 37 |
38 -- Configurable options | 38 -- Configurable options |
39 local max_history_messages = module:get_option_number("max_history_messages"); | 39 local max_history_messages = module:get_option_number("max_history_messages"); |
40 | 40 |
41 local function is_admin(jid) | 41 local function is_admin(jid) |
42 return um_is_admin(jid, module.host); | 42 return um_is_admin(jid, module.host); |
43 end | 43 end |
44 | 44 |
45 local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end | 45 local function room_route_stanza(room, stanza) module:send(stanza); end |
46 local function room_save(room, forced) | 46 local function room_save(room, forced) |
47 local node = jid_split(room.jid); | 47 local node = jid_split(room.jid); |
48 persistent_rooms[room.jid] = room._data.persistent; | 48 persistent_rooms[room.jid] = room._data.persistent; |
49 if room._data.persistent then | 49 if room._data.persistent then |
50 local history = room._data.history; | 50 local history = room._data.history; |
63 end | 63 end |
64 end | 64 end |
65 if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end | 65 if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end |
66 end | 66 end |
67 | 67 |
68 local persistent_errors = false; | |
68 for jid in pairs(persistent_rooms) do | 69 for jid in pairs(persistent_rooms) do |
69 local node = jid_split(jid); | 70 local node = jid_split(jid); |
70 local data = datamanager.load(node, muc_host, "config") or {}; | 71 local data = datamanager.load(node, muc_host, "config"); |
71 local room = muc_new_room(jid, { | 72 if data then |
72 max_history_length = max_history_messages; | 73 local room = muc_new_room(jid, { |
73 }); | 74 max_history_length = max_history_messages; |
74 room._data = data._data; | 75 }); |
75 room._data.max_history_length = max_history_messages; -- Overwrite old max_history_length in data with current settings | 76 room._data = data._data; |
76 room._affiliations = data._affiliations; | 77 room._data.max_history_length = max_history_messages; -- Overwrite old max_history_length in data with current settings |
77 room.route_stanza = room_route_stanza; | 78 room._affiliations = data._affiliations; |
78 room.save = room_save; | 79 room.route_stanza = room_route_stanza; |
79 rooms[jid] = room; | 80 room.save = room_save; |
81 rooms[jid] = room; | |
82 else -- missing room data | |
83 persistent_rooms[jid] = nil; | |
84 module:log("error", "Missing data for room '%s', removing from persistent room list", jid); | |
85 persistent_errors = true; | |
86 end | |
80 end | 87 end |
88 if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end | |
81 | 89 |
82 local host_room = muc_new_room(muc_host, { | 90 local host_room = muc_new_room(muc_host, { |
83 max_history_length = max_history_messages; | 91 max_history_length = max_history_messages; |
84 }); | 92 }); |
85 host_room.route_stanza = room_route_stanza; | 93 host_room.route_stanza = room_route_stanza; |
158 module:hook("message/host", handle_to_domain, -1); | 166 module:hook("message/host", handle_to_domain, -1); |
159 module:hook("presence/host", handle_to_domain, -1); | 167 module:hook("presence/host", handle_to_domain, -1); |
160 | 168 |
161 hosts[module.host].send = function(stanza) -- FIXME do a generic fix | 169 hosts[module.host].send = function(stanza) -- FIXME do a generic fix |
162 if stanza.attr.type == "result" or stanza.attr.type == "error" then | 170 if stanza.attr.type == "result" or stanza.attr.type == "error" then |
163 core_post_stanza(component, stanza); | 171 module:send(stanza); |
164 else error("component.send only supports result and error stanzas at the moment"); end | 172 else error("component.send only supports result and error stanzas at the moment"); end |
165 end | 173 end |
166 | 174 |
167 prosody.hosts[module:get_host()].muc = { rooms = rooms }; | 175 hosts[module:get_host()].muc = { rooms = rooms }; |
168 | 176 |
169 module.save = function() | 177 module.save = function() |
170 return {rooms = rooms}; | 178 return {rooms = rooms}; |
171 end | 179 end |
172 module.restore = function(data) | 180 module.restore = function(data) |
178 room._affiliations = oldroom._affiliations; | 186 room._affiliations = oldroom._affiliations; |
179 room.route_stanza = room_route_stanza; | 187 room.route_stanza = room_route_stanza; |
180 room.save = room_save; | 188 room.save = room_save; |
181 rooms[jid] = room; | 189 rooms[jid] = room; |
182 end | 190 end |
183 prosody.hosts[module:get_host()].muc = { rooms = rooms }; | 191 hosts[module:get_host()].muc = { rooms = rooms }; |
184 end | 192 end |