Annotate

plugins/time.lua @ 501:419c248919e8

util.dataforms: Remove local copy The main difference was the from_stanza() function, which was used in by 'clix adhoc', so moving it there seems sensible. Maybe reconsider upstreaming it to Prosody, but it's not used anywhere there.
author Kim Alvefur <zash@zash.se>
date Fri, 23 Jun 2023 12:38:58 +0200
parent 490:6b2f31da9610
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
480
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local verse = require "verse";
490
6b2f31da9610 Update for new Prosody module namespace
Kim Alvefur <zash@zash.se>
parents: 480
diff changeset
2 local dt = require "prosody.util.datetime";
480
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local xmlns_time = "urn:xmpp:time";
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 function verse.plugins.time(stream)
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 function stream:query_time(target_jid, callback)
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 callback = callback or function (time) return self:event("time/response", time); end
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 self:send_iq(verse.iq({ type = "get", to = target_jid })
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 :tag("time", { xmlns = xmlns_time }),
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 function (reply)
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 if reply.attr.type == "result" then
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local query = reply:get_child("time", xmlns_time);
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local resp = {
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 tzo = query:get_child_text("tzo");
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 utc = query:get_child_text("utc");
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 };
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 if resp.utc then
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 resp.timestamp = dt.parse(resp.utc);
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 callback(resp);
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 else
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 local type, condition, text = reply:get_error();
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 callback({
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 error = true;
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 condition = condition;
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 text = text;
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 type = type;
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 });
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end);
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 return true;
a48a4723aa2a Add time query plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end