Changeset

6137:7db24f237a83

plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
author daurnimator <quae@daurnimator.com>
date Mon, 24 Mar 2014 13:10:54 -0400
parents 6136:2068242028ff
children 6138:fa746d834424
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Mon Mar 24 12:44:31 2014 -0400
+++ b/plugins/muc/muc.lib.lua	Mon Mar 24 13:10:54 2014 -0400
@@ -119,25 +119,29 @@
 	self:_route_stanza(stanza);
 end
 function room_mt:broadcast_message(stanza, historic)
+	module:fire_event("muc-broadcast-message", {room = self, stanza = stanza, historic = historic});
 	for occupant_jid, o_data in pairs(self._occupants) do
 		self:route_to_occupant(o_data, stanza)
 	end
-	if historic then -- add to history
-		return self:save_to_history(stanza)
+end
+
+-- add to history
+module:hook("muc-broadcast-message", function(event)
+	if event.historic then
+		local room = event.room
+		local history = room._data['history'];
+		if not history then history = {}; room._data['history'] = history; end
+		local stanza = st.clone(event.stanza);
+		stanza.attr.to = "";
+		local stamp = datetime.datetime();
+		stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203
+		stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
+		local entry = { stanza = stanza, stamp = stamp };
+		t_insert(history, entry);
+		while #history > room:get_historylength() do t_remove(history, 1) end
 	end
-end
-function room_mt:save_to_history(stanza)
-	local history = self._data['history'];
-	if not history then history = {}; self._data['history'] = history; end
-	stanza = st.clone(stanza);
-	stanza.attr.to = "";
-	local stamp = datetime.datetime();
-	stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203
-	stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
-	local entry = { stanza = stanza, stamp = stamp };
-	t_insert(history, entry);
-	while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end
-end
+end)
+
 function room_mt:broadcast_except_nick(stanza, nick)
 	for rnick, occupant in pairs(self._occupants) do
 		if rnick ~= nick then