Merge with Zash

Wed, 27 Aug 2014 10:34:58 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 27 Aug 2014 10:34:58 +0100
changeset 352
413e3f449865
parent 350
04049524fcd1 (diff)
parent 351
4455b07f77ed (current diff)
child 353
8cd05c3d0f1f

Merge with Zash

--- a/plugins/groupchat.lua	Wed Sep 04 13:40:55 2013 +0200
+++ b/plugins/groupchat.lua	Wed Aug 27 10:34:58 2014 +0100
@@ -43,12 +43,11 @@
 			return false, "no nickname supplied"
 		end
 		opts = opts or {};
-		local room = setmetatable({
+		local room = setmetatable(verse.eventable{
 			stream = stream, jid = jid, nick = nick,
 			subject = nil,
 			occupants = {},
 			opts = opts,
-			events = events.new()
 		}, room_mt);
 		if opts.source then
 			self.rooms[opts.source.." "..jid] = room;
@@ -176,12 +175,3 @@
 function room_mt:ban(nick, reason)
 	self:set_affiliation(nick, "outcast", reason);
 end
-
-function room_mt:event(name, arg)
-	self.stream:debug("Firing room event: %s", name);
-	return self.events.fire_event(name, arg);
-end
-
-function room_mt:hook(name, callback, priority)
-	return self.events.add_handler(name, callback, priority);
-end
--- a/plugins/smacks.lua	Wed Sep 04 13:40:55 2013 +0200
+++ b/plugins/smacks.lua	Wed Aug 27 10:34:58 2014 +0100
@@ -1,4 +1,5 @@
 local verse = require "verse";
+local now = socket.gettime;
 
 local xmlns_sm = "urn:xmpp:sm:2";
 
@@ -6,6 +7,8 @@
 	-- State for outgoing stanzas
 	local outgoing_queue = {};
 	local last_ack = 0;
+	local last_stanza_time = now();
+	local timer_active;
 	
 	-- State for incoming stanzas
 	local handled_stanza_count = 0;
@@ -24,11 +27,24 @@
 		if stanza.name and not stanza.attr.xmlns then
 			-- serialize stanzas in order to bypass this on resumption
 			outgoing_queue[#outgoing_queue+1] = tostring(stanza);
-			verse.add_task(1, function()
-				if #outgoing_queue > 0 then
+			last_stanza_time = now();
+			if not timer_active then
+				timer_active = true;
+				stream:debug("Waiting to send ack request...");
+				verse.add_task(1, function()
+					if #outgoing_queue == 0 then
+						timer_active = false;
+						return;
+					end
+					local time_since_last_stanza = now() - last_stanza_time;
+					if time_since_last_stanza < 1 and #outgoing_queue < 10 then
+						return 1 - time_since_last_stanza;
+					end
+					stream:debug("Time up, sending <r>...");
+					timer_active = false;
 					stream:send(verse.stanza("r", { xmlns = xmlns_sm }));
-				end
-			end);
+				end);
+			end
 		end
 	end
 

mercurial