Software /
code /
prosody-modules
Annotate
mod_default_vcard/mod_default_vcard.lua @ 737:e4ea03b060ed
mod_archive: switch from/to
The XEP-0136 is not very explicit about the meening of <from> and <to>
elements, but the examples are clear: <from> means it comes from the user in
the 'with' attribute of the collection.
That is the opposite of what is currently implemented in that module.
So for better compatibility with complient clients, this switch the 'from' and
'to' fields
author | Olivier Goffart <ogoffart@woboq.com> |
---|---|
date | Wed, 04 Jul 2012 14:08:43 +0200 |
parent | 455:52f2188ec47d |
child | 936:7236cdec3ea1 |
rev | line source |
---|---|
455
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local datamanager = require "util.datamanager"; |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local host = module.host; |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 module:hook("user-registered", function(event) |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local username = event.username; |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local data = datamanager.load(username, host, "account_details"); |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local vcard = datamanager.load(username, host, "vcard"); |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 --module:log("debug", "Has account details: %s", data and "yes" or "no"); |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 --module:log("debug", "Has vCard: %s", vcard and "yes" or "no"); |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 if data and not vcard then |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 -- MAYBE |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 -- first .. " " .. last |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 -- first, last = name:match("^(%w+) (%w+)$") |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local vcard = st.stanza("vCard", { xmlns = "vcard-temp" }) |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 :tag("VERSION"):text("3.0"):up() |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 :tag("N") |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 :tag("FAMILY"):text(data.last or ""):up() |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 :tag("GIVEN"):text(data.first or ""):up() |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 :up() |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 :tag("FN"):text(data.name or ""):up() |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 :tag("NICKNAME"):text(data.nick or username):up(); |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local ok, err = datamanager.store(username, host, "vcard", st.preserialize(vcard)); |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 if not ok then |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 module:log("error", "Couldn't save vCard data, %s", err); |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 end |
52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 end); |