Software /
code /
verse
Comparison
plugins/carbons.lua @ 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 |
parent | 285:99737531734c |
child | 318:598552fc085b |
comparison
equal
deleted
inserted
replaced
285:99737531734c | 286:04b6c060ff01 |
---|---|
1 local verse = require "verse"; | 1 local verse = require "verse"; |
2 | 2 |
3 local xmlns_carbons = "urn:xmpp:carbons:1"; | 3 local xmlns_carbons = "urn:xmpp:carbons:1"; |
4 local xmlns_forward = "urn:xmpp:forward:0"; | 4 local xmlns_forward = "urn:xmpp:forward:0"; |
5 local os_date = os.date; | 5 local os_time = os.time; |
6 local datetime = function(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end | 6 local parse_datetime = require "util.datetime".parse; |
7 local bare_jid = require "util.jid".bare; | 7 local bare_jid = require "util.jid".bare; |
8 | 8 |
9 -- TODO Check disco for support | 9 -- TODO Check disco for support |
10 | 10 |
11 function verse.plugins.carbons(stream) | 11 function verse.plugins.carbons(stream) |
50 local carbon_dir = stanza:get_child(nil, xmlns_carbons); | 50 local carbon_dir = stanza:get_child(nil, xmlns_carbons); |
51 if stanza.attr.from == my_bare and carbon_dir then | 51 if stanza.attr.from == my_bare and carbon_dir then |
52 carbon_dir = carbon_dir.name; | 52 carbon_dir = carbon_dir.name; |
53 local fwd = stanza:get_child("forwarded", xmlns_forward); | 53 local fwd = stanza:get_child("forwarded", xmlns_forward); |
54 local fwd_stanza = fwd and fwd:get_child("message", "jabber:client"); | 54 local fwd_stanza = fwd and fwd:get_child("message", "jabber:client"); |
55 local delay = fwd:get_child("delay", "urn:xmpp:delay"); | |
56 local stamp = delay and delay.attr.stamp; | |
57 stamp = stamp and parse_datetime(stamp); | |
55 if fwd_stanza then | 58 if fwd_stanza then |
56 return stream:event("carbon", { | 59 return stream:event("carbon", { |
57 dir = carbon_dir, | 60 dir = carbon_dir, |
58 stanza = fwd_stanza, | 61 stanza = fwd_stanza, |
59 timestamp = nil or datetime(), -- TODO check for delay tag | 62 timestamp = stamp or os_time(), |
60 }); | 63 }); |
61 end | 64 end |
62 end | 65 end |
63 end, 1); | 66 end, 1); |
64 end | 67 end |