File

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
line wrap: on
line source

local verse = require "verse";
local dt = require "prosody.util.datetime";

local xmlns_time = "urn:xmpp:time";

function verse.plugins.time(stream)
	function stream:query_time(target_jid, callback)
		callback = callback or function (time) return self:event("time/response", time); end
		self:send_iq(verse.iq({ type = "get", to = target_jid })
			:tag("time", { xmlns = xmlns_time }),
			function (reply)
				if reply.attr.type == "result" then
					local query = reply:get_child("time", xmlns_time);
					local resp = {
						tzo = query:get_child_text("tzo");
						utc = query:get_child_text("utc");
					};
					if resp.utc then
						resp.timestamp = dt.parse(resp.utc);
					end
					callback(resp);
				else
					local type, condition, text = reply:get_error();
					callback({
						error = true;
						condition = condition;
						text = text;
						type = type;
					});
				end
			end);
	end
	return true;
end