aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-02-11 18:30:44 +0000
committerMatthew Wild <mwild1@gmail.com>2009-02-11 18:30:44 +0000
commit593f1c0a523ef586f3884057632eae8123066209 (patch)
treeb2b1a6350c4204f01039e31d234bf573c2ec31e7 /plugins
parent0a8bd35cebf8ee3772e1f9acd5740aea8db65d25 (diff)
parent5833e92990f5035f3b4b2c8f7c3c0651b28aa23f (diff)
downloadprosody-593f1c0a523ef586f3884057632eae8123066209.tar.gz
prosody-593f1c0a523ef586f3884057632eae8123066209.zip
Merge with waqas for MUC/routing fixes
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_muc.lua30
1 files changed, 22 insertions, 8 deletions
diff --git a/plugins/mod_muc.lua b/plugins/mod_muc.lua
index 602fb5bc..bd36bd8f 100644
--- a/plugins/mod_muc.lua
+++ b/plugins/mod_muc.lua
@@ -7,14 +7,15 @@ local jid_bare = require "util.jid".bare;
local st = require "util.stanza";
local log = require "util.logger".init("mod_muc");
local multitable_new = require "util.multitable".new;
+local t_insert, t_remove = table.insert, table.remove;
if module:get_host_type() ~= "component" then
error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0);
end
local muc_domain = module:get_host();
-
local muc_name = "MUCMUCMUC!!!";
+local history_length = 20;
-- room_name -> room
-- occupant_room_nick -> data
@@ -30,6 +31,7 @@ local jid_nick = multitable_new(); -- real jid -> room's jid -> room nick
-- subject - the room's subject
-- non-anonymous = true|nil
-- persistent = true|nil
+ -- history = {preserialized stanzas}
local rooms_info = multitable_new();
local persist_list = datamanager.load(nil, muc_domain, 'room_list') or {};
@@ -131,6 +133,15 @@ function broadcast_message(from, room, subject, body)
stanza.attr.to = o_data.jid;
core_route_stanza(component, stanza);
end
+ if not subject and body then -- add to history
+ local history = rooms_info:get(room, 'history');
+ if not history then history = {}; rooms_info:set(room, 'history', history); end
+ -- stanza = st.deserialize(st.preserialize(stanza));
+ stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203
+ stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
+ t_insert(history, st.preserialize(stanza));
+ while #history > history_length do t_remove(history, 1) end
+ end
end
end
@@ -200,7 +211,14 @@ function handle_to_occupant(origin, stanza) -- PM, vCards, etc
end
end
broadcast_presence(nil, to, room);
- -- TODO send discussion history
+ local history = rooms_info:get(room, 'history'); -- send discussion history
+ if history then
+ for _, msg in ipairs(history) do
+ msg = st.deserialize(msg);
+ msg.attr.to=from;
+ core_route_stanza(component, msg);
+ end
+ end
if rooms_info:get(room, 'subject') then
core_route_stanza(component, st.message({type='groupchat', from=room, to=from}):tag("subject"):text(rooms_info:get(room, 'subject')));
end
@@ -266,7 +284,7 @@ function handle_to_domain(origin, stanza)
end
end
-function handle_stanza(origin, stanza)
+register_component(muc_domain, function(origin, stanza)
local to_node, to_host, to_resource = jid_split(stanza.attr.to);
if stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then
if type == "error" or type == "result" then return; end
@@ -282,11 +300,7 @@ function handle_stanza(origin, stanza)
if type == "error" or type == "result" then return; end
handle_to_domain(origin, stanza);
end
-end
-
-module.load_component = function()
- return handle_stanza; -- Return the function that we want to handle incoming stanzas
-end
+end);
module.unload = function()
deregister_component(muc_domain);