changeset 3939:a6b3b41a116c

Merge commit
author tmolitor <thilo@eightysoft.de>
date Sun, 08 Mar 2020 19:59:49 +0100
parents 3f4df08dce14 (diff) 469408682152 (current diff)
children 675726ab06d3
files
diffstat 5 files changed, 59 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua	Sun Mar 08 13:42:55 2020 +0100
+++ b/mod_smacks/mod_smacks.lua	Sun Mar 08 19:59:49 2020 +0100
@@ -45,7 +45,7 @@
 local sessionmanager = require"core.sessionmanager";
 
 assert(max_hibernated_sessions > 0, "smacks_max_hibernated_sessions must be greater than 0");
-assert(max_old_sessions > 0, "smacks_old_sessions must be greater than 0");
+assert(max_old_sessions > 0, "smacks_max_old_sessions must be greater than 0");
 
 local c2s_sessions = module:shared("/*/c2s/sessions");
 
@@ -110,7 +110,7 @@
 	end);
 	if timer and timer.stop then return timer; end		-- new prosody api includes stop() function
 	return {
-		stop = function () stopped = true end;
+		stop = function(self) stopped = true end;
 		timer;
 	};
 end
@@ -393,7 +393,7 @@
 -- and won't slow non-198 sessions). We can also then remove the .handled flag
 -- on stanzas
 
-function handle_unacked_stanzas(session)
+local function handle_unacked_stanzas(session)
 	local queue = session.outgoing_stanza_queue;
 	local error_attr = { type = "cancel" };
 	if #queue > 0 then
@@ -412,6 +412,38 @@
 	end
 end
 
+-- don't send delivery errors for messages which will be delivered by mam later on
+module:hook("delivery/failure", function(event)
+	local session, stanza = event.session, event.stanza;
+	-- Only deal with authenticated (c2s) sessions
+	if session.username then
+		if stanza.name == "message" and stanza.attr.xmlns == nil and
+				( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then
+			-- do nothing here for normal messages and don't send out "message delivery errors",
+			-- because messages are already in MAM at this point (no need to frighten users)
+			if session.mam_requested and stanza._was_archived then
+				return true;		-- stanza handled, don't send an error
+			end
+			-- store message in offline store, if this client does not use mam *and* was the last client online
+			local sessions = prosody.hosts[module.host].sessions[session.username] and
+					prosody.hosts[module.host].sessions[session.username].sessions or nil;
+			if sessions and next(sessions) == session.resource and next(sessions, session.resource) == nil then
+				module:fire_event("message/offline/handle", { origin = session, stanza = stanza } );
+				return true;		-- stanza handled, don't send an error
+			end
+		end
+	end
+end);
+
+-- mark stanzas as archived --> this will allow us to send back errors for stanzas not archived
+-- because the user configured the server to do so ("no-archive"-setting for one special contact for example)
+module:hook("archive-message-added", function(event)
+	local session, stanza, for_user, stanza_id  = event.origin, event.stanza, event.for_user, event.id;
+	if session then session.log("debug", "Marking stanza as archived, archive_id: %s, stanza: %s", tostring(stanza_id), tostring(stanza:top_tag())); end
+	if not session then module:log("debug", "Marking stanza as archived in unknown session, archive_id: %s, stanza: %s", tostring(stanza_id), tostring(stanza:top_tag())); end
+	stanza._was_archived = true;
+end);
+
 module:hook("pre-resource-unbind", function (event)
 	local session, err = event.session, event.error;
 	if session.smacks then
@@ -531,6 +563,7 @@
 			c2s_sessions[conn] = nil;
 			conn:close();
 		end
+		local migrated_session_log = session.log;
 		original_session.ip = session.ip;
 		original_session.conn = session.conn;
 		original_session.send = session.send;
@@ -565,9 +598,9 @@
 		for i=1,#queue do
 			session.send(queue[i]);
 		end
-		session.log("debug", "all stanzas resent, now disabling send() in this session, #queue = %d", #queue);
+		session.log("debug", "all stanzas resent, now disabling send() in this migrated session, #queue = %d", #queue);
 		function session.send(stanza)
-			session.log("warn", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza));
+			migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza));
 			return false;
 		end
 		module:fire_event("smacks-hibernation-end", {origin = session, resumed = original_session, queue = queue});
--- a/mod_smacks_noerror/README.markdown	Sun Mar 08 13:42:55 2020 +0100
+++ b/mod_smacks_noerror/README.markdown	Sun Mar 08 19:59:49 2020 +0100
@@ -1,43 +1,12 @@
 ---
 labels:
 - 'Stage-Alpha'
-summary: Monkeypatch mod_smacks to silently discard unacked message stanzas when a hibernation times out
+summary: Module deprecated, just use mod_smacks and mod_nooffline_noerror
 ...
 
 Introduction
 ============
 
-By default mod_smacks sends back error stanzas for every unacked message
-stanza when the hibernation times out.
-This leads to "message not delivered" errors displayed in clients.
-
-When you are certain that *all* your clients use MAM, this is unnecessary and
-confuses users (the message will eventually be delivered via MAM).
-
-This module therefore monkeypatches mod_smacks to silently drop those
-unacked message stanzas instead of sending error replies.
-Unacked iq stanzas are still answered with an error reply though.
-
-If you disable mod_offline, this module will also silence "message not delivered"
-error messages that will otherwise be generated when prosody would normally
-store offline message but can't do this because of disabled mod_offline.  
-If mod_offline is *not* disabled this module will not change offline storage
-behaviour at all.
-
-Warning
-=======
-
-You most certainly *should not* use this module if you cannot be certain
-that *all* your clients support and use MAM!
-
-Compatibility
-=============
-
-  ----- -------------------------------------------------------------------
-  trunk Untested
-  0.10  Works
-  0.9   Untested but should work
-  0.8   Untested but should work, use version [7693724881b3] of mod_smacks
-  ----- -------------------------------------------------------------------
-
-[7693724881b3]: //hg.prosody.im/prosody-modules/raw-file/7693724881b3/mod_smacks/mod_smacks.lua
+This module is deprecated and superseded by mod_smacks.
+If you explicitly disabled mod_offline you need the new module
+mod_nooffline_noerror to regain all features of this deprecated module.
--- a/mod_smacks_noerror/mod_smacks_noerror.lua	Sun Mar 08 13:42:55 2020 +0100
+++ b/mod_smacks_noerror/mod_smacks_noerror.lua	Sun Mar 08 19:59:49 2020 +0100
@@ -1,40 +1,5 @@
-local t_insert = table.insert;
-
-local mod_smacks = module:depends"smacks"
-
--- ignore offline messages and don't return any error (the message will be already in MAM at this point)
--- this is *only* triggered if mod_offline is *not* loaded and completely ignored otherwise
-module:hook("message/offline/handle", function(event)
-	event.origin.log("debug", "Ignoring offline message (mod_offline seems to be *not* loaded)...");
-	return true;
-end, -100);
-
-local function discard_unacked_messages(session)
-	local queue = session.outgoing_stanza_queue;
-	local replacement_queue = {};
-	session.outgoing_stanza_queue = replacement_queue;
+-- this module is deprecated, log an error and load the superseding modules instead
+module:depends"smacks"
+module:depends"nooffline_noerror"
 
-	for _, stanza in ipairs(queue) do
-		if stanza.name == "message" and stanza.attr.xmlns == nil and
-				( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then
-			-- do nothing here for normal messages and don't send out "message delivery errors",
-			-- because messages are already in MAM at this point (no need to frighten users)
-		else
-			t_insert(replacement_queue, stanza);
-		end
-	end
-end
-
-local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas;
-
-mod_smacks.handle_unacked_stanzas = function (session)
-	-- Only deal with authenticated (c2s) sessions
-	if session.username then
-		discard_unacked_messages(session)
-	end
-	return handle_unacked_stanzas(session);
-end
-
-function module.unload()
-	mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas;
-end
+module:log("error", "mod_smacks_noerror is deprecated! Just use mod_smacks and load mod_nooffline_noerror if you explicitly disabled offline storage (mod_offline)");
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_smacks_offline/README.markdown	Sun Mar 08 19:59:49 2020 +0100
@@ -0,0 +1,10 @@
+---
+labels:
+- 'Stage-Alpha'
+summary: Module deprecated, just use mod_smacks
+...
+
+Introduction
+============
+
+This module is deprecated and superseded by mod_smacks.
--- a/mod_smacks_offline/mod_smacks_offline.lua	Sun Mar 08 13:42:55 2020 +0100
+++ b/mod_smacks_offline/mod_smacks_offline.lua	Sun Mar 08 19:59:49 2020 +0100
@@ -1,35 +1,4 @@
-local t_insert = table.insert;
-
-local mod_smacks = module:depends"smacks"
-
-local function store_unacked_stanzas(session)
-	local queue = session.outgoing_stanza_queue;
-	local replacement_queue = {};
-	session.outgoing_stanza_queue = replacement_queue;
+-- this module is deprecated, log an error and load the superseding module instead
+module:depends"smacks"
 
-	for _, stanza in ipairs(queue) do
-		if stanza.name == "message" and stanza.attr.xmlns == nil and
-				( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) then
-			module:fire_event("message/offline/handle", { origin = session, stanza = stanza } )
-		else
-			t_insert(replacement_queue, stanza);
-		end
-	end
-end
-
-local handle_unacked_stanzas = mod_smacks.handle_unacked_stanzas;
-
-local host_sessions = prosody.hosts[module.host].sessions;
-mod_smacks.handle_unacked_stanzas = function (session)
-	if session.username then
-		local sessions = host_sessions[session.username].sessions;
-		if next(sessions) == session.resource and next(sessions, session.resource) == nil then
-			store_unacked_stanzas(session)
-		end
-	end
-	return handle_unacked_stanzas(session);
-end
-
-function module.unload()
-	mod_smacks.handle_unacked_stanzas = handle_unacked_stanzas;
-end
+module:log("error", "mod_smacks_offline is deprecated! Just use mod_smacks!");
\ No newline at end of file