Mercurial > prosody-hg
comparison plugins/muc/gc3.lib.lua @ 13908:356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
RSM version currently held back until a planned restructuring of how we
store affiliations in MUC. This is because RSM needs a stable ordered list,
which we don't currently have.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 26 Jun 2025 15:17:57 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 13907:827a4cfd3fad | 13908:356c8ec22e9a |
|---|---|
| 1 | |
| 2 local jid_bare = require "prosody.util.jid".bare; | |
| 3 | |
| 4 local st = require "prosody.util.stanza"; | |
| 5 | |
| 6 local muc_util = module:require "muc/util"; | |
| 7 local valid_affiliations = muc_util.valid_affiliations; | |
| 8 | |
| 9 local xmlns_gc3 = "urn:xmpp:gc3:tmp" | |
| 10 | |
| 11 --luacheck: ignore 113/get_room_from_jid | |
| 12 | |
| 13 function fetch_participant_list(room, stanza, origin) | |
| 14 local from_jid = stanza.attr.from; | |
| 15 local from_aff = room:get_affiliation(from_jid); | |
| 16 local from_rank = valid_affiliations[from_aff or "none"]; | |
| 17 | |
| 18 local required_aff_rank = valid_affiliations[room:get_members_only() and "member" or "none"]; | |
| 19 if from_rank < required_aff_rank then | |
| 20 origin.send(st.error_reply(stanza, "auth", "forbidden")); | |
| 21 return true; | |
| 22 end | |
| 23 | |
| 24 local can_see_real_jids = not room:is_anonymous_for(from_jid); | |
| 25 | |
| 26 local reply = st.reply(stanza) | |
| 27 :tag("participants", { xmlns = xmlns_gc3 }); | |
| 28 | |
| 29 for jid, aff in room:each_affiliation() do | |
| 30 local nick = room:get_registered_nick(jid); | |
| 31 local visible_jid = can_see_real_jids and jid or nil; | |
| 32 reply:text_tag("item", nil, { | |
| 33 affiliation = aff; | |
| 34 jid = visible_jid; | |
| 35 nick = nick; | |
| 36 id = room:get_occupant_id_from_jid(jid); | |
| 37 }); | |
| 38 end | |
| 39 | |
| 40 origin.send(reply); | |
| 41 return true; | |
| 42 end | |
| 43 | |
| 44 local function room_event_handler(handler, allow_nonexistent) | |
| 45 return function (event) | |
| 46 local origin, stanza = event.origin, event.stanza; | |
| 47 local room_jid = jid_bare(stanza.attr.to); | |
| 48 local room = get_room_from_jid(room_jid); | |
| 49 if not room and allow_nonexistent ~= true then | |
| 50 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); | |
| 51 return true; | |
| 52 end | |
| 53 return handler(room, stanza, origin); | |
| 54 end; | |
| 55 end | |
| 56 | |
| 57 module:hook("iq-get/bare/"..xmlns_gc3..":participants", room_event_handler(fetch_participant_list)); |
