view mod_default_vcard/mod_default_vcard.lua @ 735:c1b0f0c33c6a

mod_archive: Fix hour offset in stored message date os.date expect a timestamp in local time, that is subject to daylight saving. But since we pass an UTC timestamp to os.date one hour is (wrongly) added in the summer. The only sensible thing is to call the os.date only once with the ! parametter. And then parsing this sting to get the utc_timestamp. Calling os.date with an UTC timestamp is not possible, and calling os.date twice without timestamp could give different results.
author Olivier Goffart <ogoffart@woboq.com>
date Wed, 04 Jul 2012 13:49:57 +0200
parents 52f2188ec47d
children 7236cdec3ea1
line wrap: on
line source

local datamanager = require "util.datamanager";
local st = require "util.stanza";
local host = module.host;

module:hook("user-registered", function(event)
	local username = event.username;
	local data = datamanager.load(username, host, "account_details");
	local vcard = datamanager.load(username, host, "vcard");
	--module:log("debug", "Has account details: %s", data and "yes" or "no");
	--module:log("debug", "Has vCard: %s", vcard and "yes" or "no");
	if data and not vcard then
		-- MAYBE
		-- first .. " " .. last
		-- first, last = name:match("^(%w+) (%w+)$")
		local vcard = st.stanza("vCard", { xmlns = "vcard-temp" })
			:tag("VERSION"):text("3.0"):up()
			:tag("N")
				:tag("FAMILY"):text(data.last or ""):up()
				:tag("GIVEN"):text(data.first or ""):up()
			:up()
			:tag("FN"):text(data.name or ""):up()
			:tag("NICKNAME"):text(data.nick or username):up();
		local ok, err = datamanager.store(username, host, "vcard", st.preserialize(vcard));
		if not ok then
			module:log("error", "Couldn't save vCard data, %s", err);
		end
	end
end);