changeset 2395:2e641ab995b3

mod_cloud_notify: added code to respond to the new event "smacks-ack-delayed" issued by mod_smacks when acks are delayed for a certain amount of time. This allows to send out notification requests before the read timeout or connection close event really happens, thus allowing conversations to be smoother.
author tmolitor <thilo@eightysoft.de>
date Thu, 24 Nov 2016 01:15:08 +0100
parents 4c27ebcf4cbd
children 544ee057a23f
files mod_cloud_notify/README.markdown mod_cloud_notify/mod_cloud_notify.lua
diffstat 2 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mod_cloud_notify/README.markdown	Thu Nov 24 00:47:32 2016 +0100
+++ b/mod_cloud_notify/README.markdown	Thu Nov 24 01:15:08 2016 +0100
@@ -9,13 +9,28 @@
 
 This is an implementation of the server bits of [XEP-0357: Push Notifications].
 It allows clients to register an "app server" which is notified about new
-messages while the user is offline or disconnected.  Implementation of the
-"app server" is not included[^1].
+messages while the user is offline, disconnected or the session is hibernated
+by [mod_smacks]. 
+Implementation of the "app server" is not included[^1].
 
 Details
 =======
 
-App servers are notified about offline messages.
+App servers are notified about offline messages or messages waiting
+in the smacks queue.
+
+To cooperate with [mod_smacks] this module consumes some events:
+"smacks-ack-delayed", "smacks-hibernation-start" and "smacks-hibernation-end".
+These events allow this module to send out notifications for messages received
+while the session is hibernated by [mod_smacks] or even when smacks
+acknowledgements for messages are delayed by a certain amount of seconds
+configurable with the [mod_smacks] setting "smacks_max_ack_delay".
+
+The "smacks_max_ack_delay" setting allows to send out notifications to clients
+which aren't already in smacks hibernation state (because the read timeout or
+connection close didn't happen already) but also aren't responding to acknowledgement
+request in a timely manner, thus allowing conversations to be smoother under such
+circumstances.
 
 Configuration
 =============
@@ -46,3 +61,4 @@
 
 [^1]: The service which is expected to forward notifications to
     something like Google Cloud Messaging or Apple Notification Service
+[mod_smacks]: //modules.prosody.im/mod_smacks
--- a/mod_cloud_notify/mod_cloud_notify.lua	Thu Nov 24 00:47:32 2016 +0100
+++ b/mod_cloud_notify/mod_cloud_notify.lua	Thu Nov 24 01:15:08 2016 +0100
@@ -160,7 +160,7 @@
 local function hibernate_session(event)
 	local session = event.origin;
 	local queue = event.queue;
-	-- process already unacked stanzas
+	-- process unacked stanzas
 	for i=1,#queue do
 		process_new_stanza(queue[i], session);
 	end
@@ -174,8 +174,19 @@
 	filters.remove_filter(session, "stanzas/out", process_new_stanza);
 end
 
+-- smacks ack is delayed
+local function ack_delayed(event)
+	local session = event.origin;
+	local queue = event.queue;
+	-- process unacked stanzas (process_new_stanza will only send push requests for new messages)
+	for i=1,#queue do
+		process_new_stanza(queue[i], session);
+	end
+end
+
 module:hook("smacks-hibernation-start", hibernate_session);
 module:hook("smacks-hibernation-end", restore_session);
+module:hook("smacks-ack-delayed", ack_delayed);
 
 
 module:hook("message/offline/broadcast", function(event)