changeset 3036:f7ebf8fcd602

mod_mam_muc: Remove support for Prosody trunk/0.11
author Kim Alvefur <zash@zash.se>
date Mon, 02 Apr 2018 16:20:36 +0200
parents 60ca0d03f3e3
children bae7b0a002ef
files mod_mam_muc/README.markdown mod_mam_muc/mod_mam_muc.lua
diffstat 2 files changed, 19 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/mod_mam_muc/README.markdown	Wed May 23 00:34:46 2018 +0200
+++ b/mod_mam_muc/README.markdown	Mon Apr 02 16:20:36 2018 +0200
@@ -9,8 +9,8 @@
 
 This module logs the conversation of chatrooms running on the server to
 Prosody's archive storage. To access them you will need a client with
-support for [XEP-0313: Message Archive Management] or a module such
-as [mod\_http\_muc\_log].
+support for [XEP-0313: Message Archive Management] **version 0.5** or
+a module such as [mod_http_muc_log].
 
 Usage
 =====
@@ -48,13 +48,13 @@
 Compatibility
 =============
 
-  ------- --------------------------------------------
-  trunk   Works best
+  ------- -------------------
+  trunk   Use mod\_muc\_mam instead
   0.10    Works partially, only XEP-0313 version 0.5
   0.9     Does not work
   0.8     Does not work
-  ------- --------------------------------------------
+  ------- -------------------
 
 Prosody trunk (after April 2014) has a major rewrite of the MUC module,
-allowing easier integration. Without this (0.10), some features do not
-work, such as correct advertising and join/part logging.
+allowing easier integration, but this module is not compatible with
+that.
--- a/mod_mam_muc/mod_mam_muc.lua	Wed May 23 00:34:46 2018 +0200
+++ b/mod_mam_muc/mod_mam_muc.lua	Mon Apr 02 16:20:36 2018 +0200
@@ -8,7 +8,10 @@
 	return;
 end
 
-local xmlns_mam     = "urn:xmpp:mam:2";
+-- Note: Can't implement urn:xmpp:mam:2 because we catch messages after
+-- they have already been broadcast, so they can no longer be modified.
+
+local xmlns_mam     = "urn:xmpp:mam:1";
 local xmlns_delay   = "urn:xmpp:delay";
 local xmlns_forward = "urn:xmpp:forward:0";
 local xmlns_st_id   = "urn:xmpp:sid:0";
@@ -26,19 +29,13 @@
 -- Support both old and new MUC code
 local mod_muc = module:depends"muc";
 local rooms = rawget(mod_muc, "rooms");
-local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end;
-local new_muc = not rooms;
-if new_muc then
-	rooms = module:shared"muc/rooms";
-else
-	-- COMPAT: We don't (currently?) support injecting stanza-id
-	-- on Prosody 0.10 and prior, which is required by mam:2
-	xmlns_mam = "urn:xmpp:mam:1";
+if not rooms then
+	module:log("warn", "mod_mam_muc is compatible with Prosody up to 0.10.x, use mod_muc_mam with later versions");
+	module:depends("muc_mam");
+	return;
 end
-local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
-	function (jid)
-		return rooms[jid];
-	end
+local each_room = function() return it.values(rooms); end;
+local get_room_from_jid = function (jid) return rooms[jid]; end
 
 local is_stanza = st.is_stanza;
 local tostring = tostring;
@@ -86,7 +83,7 @@
 local send_history, save_to_history;
 
 	-- Override history methods for all rooms.
-if not new_muc then -- 0.10 or older
+do -- 0.10 or older
 	module:hook("muc-room-created", function (event)
 		local room = event.room;
 		if archiving_enabled(room) then
@@ -377,8 +374,6 @@
 		next_stanza = function() end; -- events should define this iterator
 	};
 
-	module:fire_event("muc-get-history", event);
-
 	for msg in event.next_stanza, event do
 		self:_route_stanza(msg);
 	end
@@ -420,27 +415,7 @@
 		with = with .. "<" .. stanza.attr.type
 	end
 
-	local id = archive:append(room_node, nil, stored_stanza, time_now(), with);
-
-	if id then
-		stanza:add_direct_child(st.stanza("stanza-id", { xmlns = xmlns_st_id, by = self.jid, id = id }));
-	end
-end
-
-module:hook("muc-broadcast-message", function (event)
-	local room, stanza = event.room, event.stanza;
-	if stanza:get_child("body") then
-		save_to_history(room, stanza);
-	end
-end);
-
-if module:get_option_boolean("muc_log_presences", true) then
-	module:hook("muc-occupant-joined", function (event)
-		save_to_history(event.room, st.stanza("presence", { from = event.nick }));
-	end);
-	module:hook("muc-occupant-left", function (event)
-		save_to_history(event.room, st.stanza("presence", { type = "unavailable", from = event.nick }));
-	end);
+	archive:append(room_node, nil, stored_stanza, time_now(), with);
 end
 
 if not archive.delete then