Software /
code /
prosody
Comparison
plugins/mod_time.lua @ 9225:0ba963e82ac7
mod_time: Simplify iq handling by hooking on iq-get/ instead of iq/.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 24 Aug 2018 20:35:03 +0200 |
parent | 5776:bd0ff8ae98a8 |
child | 12632:70ae68bb0aa5 |
comparison
equal
deleted
inserted
replaced
9224:a84dbd2e08bc | 9225:0ba963e82ac7 |
---|---|
14 | 14 |
15 module:add_feature("urn:xmpp:time"); | 15 module:add_feature("urn:xmpp:time"); |
16 | 16 |
17 local function time_handler(event) | 17 local function time_handler(event) |
18 local origin, stanza = event.origin, event.stanza; | 18 local origin, stanza = event.origin, event.stanza; |
19 if stanza.attr.type == "get" then | 19 origin.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"}) |
20 origin.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"}) | 20 :tag("tzo"):text("+00:00"):up() -- TODO get the timezone in a platform independent fashion |
21 :tag("tzo"):text("+00:00"):up() -- TODO get the timezone in a platform independent fashion | 21 :tag("utc"):text(datetime())); |
22 :tag("utc"):text(datetime())); | 22 return true; |
23 return true; | |
24 end | |
25 end | 23 end |
26 | 24 |
27 module:hook("iq/bare/urn:xmpp:time:time", time_handler); | 25 module:hook("iq-get/bare/urn:xmpp:time:time", time_handler); |
28 module:hook("iq/host/urn:xmpp:time:time", time_handler); | 26 module:hook("iq-get/host/urn:xmpp:time:time", time_handler); |
29 | 27 |
30 -- XEP-0090: Entity Time (deprecated) | 28 -- XEP-0090: Entity Time (deprecated) |
31 | 29 |
32 module:add_feature("jabber:iq:time"); | 30 module:add_feature("jabber:iq:time"); |
33 | 31 |
34 local function legacy_time_handler(event) | 32 local function legacy_time_handler(event) |
35 local origin, stanza = event.origin, event.stanza; | 33 local origin, stanza = event.origin, event.stanza; |
36 if stanza.attr.type == "get" then | 34 origin.send(st.reply(stanza):tag("query", {xmlns="jabber:iq:time"}) |
37 origin.send(st.reply(stanza):tag("query", {xmlns="jabber:iq:time"}) | 35 :tag("utc"):text(legacy())); |
38 :tag("utc"):text(legacy())); | 36 return true; |
39 return true; | |
40 end | |
41 end | 37 end |
42 | 38 |
43 module:hook("iq/bare/jabber:iq:time:query", legacy_time_handler); | 39 module:hook("iq-get/bare/jabber:iq:time:query", legacy_time_handler); |
44 module:hook("iq/host/jabber:iq:time:query", legacy_time_handler); | 40 module:hook("iq-get/host/jabber:iq:time:query", legacy_time_handler); |