Mercurial > prosody-modules
comparison mod_vcard_muc/mod_vcard_muc.lua @ 3656:3e0f4d727825
mod_vcard_muc: Add an alternative method of signaling avatar change
When the avatar has been changed, a signal is sent that the room
configuration has changed. Clients then do a disco#info query to find
the SHA-1 of the new avatar. They can then fetch it as before, or not if
they have it cached already.
This is meant to be less disruptive than signaling via presence, which
caused problems for some clients.
If clients transition to the new method, the old one can eventually be removed.
The namespace is made up while waiting for standardization.
Otherwise it is very close to what's described in
https://xmpp.org/extensions/inbox/muc-avatars.html
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 25 Aug 2019 20:46:43 +0200 |
parents | d7b589dec591 |
children | a533abe6ffd0 |
comparison
equal
deleted
inserted
replaced
3655:d7b589dec591 | 3656:3e0f4d727825 |
---|---|
40 end | 40 end |
41 | 41 |
42 local function broadcast_presence(room_jid, to) | 42 local function broadcast_presence(room_jid, to) |
43 local room = get_room_from_jid(room_jid); | 43 local room = get_room_from_jid(room_jid); |
44 | 44 |
45 local photo_hash = get_photo_hash(room) | 45 local photo_hash = get_photo_hash(room); |
46 local presence_vcard = st.presence({to = to, from = room_jid}) | 46 local presence_vcard = st.presence({to = to, from = room_jid}) |
47 :tag("x", { xmlns = "vcard-temp:x:update" }) | 47 :tag("x", { xmlns = "vcard-temp:x:update" }) |
48 :tag("photo"):text(photo_hash):up(); | 48 :tag("photo"):text(photo_hash):up(); |
49 | 49 |
50 if to == nil then | 50 if to == nil then |
76 else | 76 else |
77 if from_affiliation == "owner" then | 77 if from_affiliation == "owner" then |
78 if vcards:set(room_node, st.preserialize(stanza.tags[1])) then | 78 if vcards:set(room_node, st.preserialize(stanza.tags[1])) then |
79 session.send(st.reply(stanza):tag("vCard", { xmlns = "vcard-temp" })); | 79 session.send(st.reply(stanza):tag("vCard", { xmlns = "vcard-temp" })); |
80 broadcast_presence(room_jid, nil) | 80 broadcast_presence(room_jid, nil) |
81 | |
82 room:broadcast_message(st.message({ from = room.jid, type = "groupchat" }) | |
83 :tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }) | |
84 :tag("status", { code = "104" })); | |
81 else | 85 else |
82 -- TODO unable to write file, file may be locked, etc, what's the correct error? | 86 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
83 session.send(st.error_reply(stanza, "wait", "internal-server-error")); | 87 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
84 end | 88 end |
85 else | 89 else |
93 module:hook("iq/bare/vcard-temp:vCard", handle_vcard); | 97 module:hook("iq/bare/vcard-temp:vCard", handle_vcard); |
94 module:hook("iq/host/vcard-temp:vCard", handle_vcard); | 98 module:hook("iq/host/vcard-temp:vCard", handle_vcard); |
95 | 99 |
96 module:hook("muc-disco#info", function(event) | 100 module:hook("muc-disco#info", function(event) |
97 event.reply:tag("feature", { var = "vcard-temp" }):up(); | 101 event.reply:tag("feature", { var = "vcard-temp" }):up(); |
102 | |
103 table.insert(event.form, { | |
104 name = "{http://modules.prosody.im/mod_vcard_muc}avatar#sha1", | |
105 type = "text-single", | |
106 }); | |
107 event.formdata["{http://modules.prosody.im/mod_vcard_muc}avatar#sha1"] = get_photo_hash(event.room); | |
98 end); | 108 end); |
99 | 109 |
100 module:hook("muc-occupant-session-new", function(event) | 110 module:hook("muc-occupant-session-new", function(event) |
101 broadcast_presence(event.room.jid, event.jid); | 111 broadcast_presence(event.room.jid, event.jid); |
102 end) | 112 end) |