Merge 0.10->trunk
[prosody.git] / plugins / muc / history.lib.lua
index 596f92da75cfa9720a7387249514c81f0cd9b2b7..d685abf2e11c0fcbad8c7cf6efcd7a8454e4c9f3 100644 (file)
@@ -11,7 +11,8 @@ local gettime = os.time;
 local datetime = require "util.datetime";
 local st = require "util.stanza";
 
-local default_history_length, max_history_length = 20, math.huge;
+local default_history_length = 20;
+local max_history_length = module:get_option_number("max_history_messages", math.huge);
 
 local function set_max_history_length(_max_history_length)
        max_history_length = _max_history_length or math.huge;
@@ -129,12 +130,12 @@ local function send_history(room, stanza)
 end
 
 -- Send history on join
-module:hook("muc-occupant-joined", function(event)
+module:hook("muc-occupant-session-new", function(event)
        send_history(event.room, event.stanza);
 end, 50); -- Before subject(20)
 
 -- add to history
-module:hook("muc-broadcast-message", function(event)
+module:hook("muc-add-history", function(event)
        local historic = event.stanza:get_child("body");
        if historic then
                local room = event.room
@@ -150,6 +151,13 @@ module:hook("muc-broadcast-message", function(event)
                table.insert(history, entry);
                while #history > get_historylength(room) do table.remove(history, 1) end
        end
+       return true;
+end, -1);
+
+-- Have a single muc-add-history event, so that plugins can mark it
+-- as handled without stopping other muc-broadcast-message handlers
+module:hook("muc-broadcast-message", function(event)
+       module:fire_event("muc-add-history", event);
 end);
 
 return {