Changeset

286:04b6c060ff01

plugins.carbons: Get and parse timestamp from carbon into a number.
author Kim Alvefur <zash@zash.se>
date Sat, 17 Mar 2012 15:59:43 +0100
parents 285:99737531734c
children 287:762511350532
files plugins/carbons.lua
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/carbons.lua	Sat Mar 17 15:44:16 2012 +0100
+++ b/plugins/carbons.lua	Sat Mar 17 15:59:43 2012 +0100
@@ -2,8 +2,8 @@
 
 local xmlns_carbons = "urn:xmpp:carbons:1";
 local xmlns_forward = "urn:xmpp:forward:0";
-local os_date = os.date;
-local datetime = function(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end
+local os_time = os.time;
+local parse_datetime = require "util.datetime".parse;
 local bare_jid = require "util.jid".bare;
 
 -- TODO Check disco for support
@@ -52,11 +52,14 @@
 			carbon_dir = carbon_dir.name;
 			local fwd = stanza:get_child("forwarded", xmlns_forward);
 			local fwd_stanza = fwd and fwd:get_child("message", "jabber:client");
+			local delay = fwd:get_child("delay", "urn:xmpp:delay");
+			local stamp = delay and delay.attr.stamp;
+			stamp = stamp and parse_datetime(stamp);
 			if fwd_stanza then
 				return stream:event("carbon", {
 					dir = carbon_dir,
 					stanza = fwd_stanza,
-					timestamp = nil or datetime(), -- TODO check for delay tag
+					timestamp = stamp or os_time(),
 				});
 			end
 		end