diff options
Diffstat (limited to 'plugins/muc')
-rw-r--r-- | plugins/muc/hats.lib.lua | 2 | ||||
-rw-r--r-- | plugins/muc/mod_muc.lua | 4 | ||||
-rw-r--r-- | plugins/muc/occupant_id.lib.lua | 2 | ||||
-rw-r--r-- | plugins/muc/restrict_pm.lib.lua | 2 | ||||
-rw-r--r-- | plugins/muc/vcard.lib.lua | 82 |
5 files changed, 89 insertions, 3 deletions
diff --git a/plugins/muc/hats.lib.lua b/plugins/muc/hats.lib.lua index 7eb71eb4..7ccf194e 100644 --- a/plugins/muc/hats.lib.lua +++ b/plugins/muc/hats.lib.lua @@ -1,7 +1,7 @@ local st = require "prosody.util.stanza"; local muc_util = module:require "muc/util"; -local hats_compat = module:get_option_boolean("muc_hats_compat", true); -- COMPAT for pre-XEP namespace, TODO reconsider default for next release +local hats_compat = module:get_option_boolean("muc_hats_compat", false); -- COMPAT for pre-XEP namespace local xmlns_hats_legacy = "xmpp:prosody.im/protocol/hats:1"; local xmlns_hats = "urn:xmpp:hats:0"; diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua index 1dc99f07..2ce6e19a 100644 --- a/plugins/muc/mod_muc.lua +++ b/plugins/muc/mod_muc.lua @@ -116,6 +116,10 @@ module:depends "muc_unique" module:require "muc/hats"; module:require "muc/lock"; +if module:get_option_boolean("muc_vcard", true) ~= false then + module:require "muc/vcard"; +end + module:default_permissions("prosody:admin", { ":automatic-ownership"; ":create-room"; diff --git a/plugins/muc/occupant_id.lib.lua b/plugins/muc/occupant_id.lib.lua index b1081c9b..2252799d 100644 --- a/plugins/muc/occupant_id.lib.lua +++ b/plugins/muc/occupant_id.lib.lua @@ -1,4 +1,4 @@ --- Implementation of https://xmpp.org/extensions/inbox/occupant-id.html +-- Implementation of https://xmpp.org/extensions/xep-0421.html -- XEP-0421: Anonymous unique occupant identifiers for MUCs -- (C) 2020 Maxime “pep” Buquet <pep@bouah.net> diff --git a/plugins/muc/restrict_pm.lib.lua b/plugins/muc/restrict_pm.lib.lua index e0b25cc8..3c91b921 100644 --- a/plugins/muc/restrict_pm.lib.lua +++ b/plugins/muc/restrict_pm.lib.lua @@ -1,7 +1,7 @@ -- Based on code from mod_muc_restrict_pm in prosody-modules@d82c0383106a -- by Nicholas George <wirlaburla@worlio.com> -local st = require "util.stanza"; +local st = require "prosody.util.stanza"; local muc_util = module:require "muc/util"; local valid_roles = muc_util.valid_roles; diff --git a/plugins/muc/vcard.lib.lua b/plugins/muc/vcard.lib.lua new file mode 100644 index 00000000..f9f97721 --- /dev/null +++ b/plugins/muc/vcard.lib.lua @@ -0,0 +1,82 @@ +local mod_vcard = module:depends("vcard"); + +local jid = require "prosody.util.jid"; +local st = require "prosody.util.stanza"; + +-- This must be the same event that mod_vcard hooks +local vcard_event = "iq/bare/vcard-temp:vCard"; +local advertise_hashes = module:get_option("muc_avatar_advertise_hashes"); + +--luacheck: ignore 113/get_room_from_jid + +local function get_avatar_hash(room) + if room.avatar_hash then return room.avatar_hash; end + + local room_node = jid.split(room.jid); + local hash = mod_vcard.get_avatar_hash(room_node); + room.avatar_hash = hash; + + return hash; +end + +local function send_avatar_hash(room, to) + local hash = get_avatar_hash(room); + if not hash and to then return; end -- Don't announce when no avatar + + local presence_vcard = st.presence({to = to, from = room.jid}) + :tag("x", { xmlns = "vcard-temp:x:update" }) + :tag("photo"):text(hash):up(); + + if to == nil then + if not advertise_hashes or advertise_hashes == "presence" then + room:broadcast_message(presence_vcard); + end + if not advertise_hashes or advertise_hashes == "message" then + room:broadcast_message(st.message({ from = room.jid, type = "groupchat" }) + :tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }) + :tag("status", { code = "104" })); + end + + else + module:send(presence_vcard); + end +end + +module:hook(vcard_event, function (event) + local stanza = event.stanza; + local to = stanza.attr.to; + + if stanza.attr.type ~= "set" then + return; + end + + local room = get_room_from_jid(to); + if not room then + return; + end + + local sender_affiliation = room:get_affiliation(stanza.attr.from); + if sender_affiliation == "owner" then + event.allow_vcard_modification = true; + end +end, 10); + +if advertise_hashes ~= "none" then + module:hook("muc-occupant-joined", function (event) + send_avatar_hash(event.room, event.stanza.attr.from); + end); + module:hook("vcard-updated", function (event) + local room = get_room_from_jid(event.stanza.attr.to); + send_avatar_hash(room, nil); + end); +end + +module:hook("muc-disco#info", function (event) + event.reply:tag("feature", { var = "vcard-temp" }):up(); + + table.insert(event.form, { + name = "muc#roominfo_avatarhash", + type = "text-multi", + }); + event.formdata["muc#roominfo_avatarhash"] = get_avatar_hash(event.room); +end); |