Mercurial > prosody-hg
annotate plugins/muc/gc3.lib.lua @ 13966:e7c52d0b0e0d
util.sql: Add API to start an explicit write transaction
This will be used in SQLite3 to BEGIN IMMEDIATE, which attempts to
acquire write locks immediately instead of when the first write
statement is started. Thus it would fail faster if the write lock is
already taken. Normally that should not occur but e.g. prosodyctl could
take it.
Investigating whether something similar is sensible in PostgreSQL, MySQL
is a future task.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 19 Aug 2024 00:06:45 +0200 |
| parents | 356c8ec22e9a |
| children |
| rev | line source |
|---|---|
|
13908
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid_bare = require "prosody.util.jid".bare; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local st = require "prosody.util.stanza"; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local muc_util = module:require "muc/util"; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local valid_affiliations = muc_util.valid_affiliations; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local xmlns_gc3 = "urn:xmpp:gc3:tmp" |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 --luacheck: ignore 113/get_room_from_jid |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 function fetch_participant_list(room, stanza, origin) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local from_jid = stanza.attr.from; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local from_aff = room:get_affiliation(from_jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local from_rank = valid_affiliations[from_aff or "none"]; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local required_aff_rank = valid_affiliations[room:get_members_only() and "member" or "none"]; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 if from_rank < required_aff_rank then |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 return true; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local can_see_real_jids = not room:is_anonymous_for(from_jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local reply = st.reply(stanza) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 :tag("participants", { xmlns = xmlns_gc3 }); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 for jid, aff in room:each_affiliation() do |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local nick = room:get_registered_nick(jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local visible_jid = can_see_real_jids and jid or nil; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 reply:text_tag("item", nil, { |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 affiliation = aff; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 jid = visible_jid; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 nick = nick; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 id = room:get_occupant_id_from_jid(jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 }); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 origin.send(reply); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 return true; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 local function room_event_handler(handler, allow_nonexistent) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return function (event) |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local origin, stanza = event.origin, event.stanza; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 local room_jid = jid_bare(stanza.attr.to); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 local room = get_room_from_jid(room_jid); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 if not room and allow_nonexistent ~= true then |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 return true; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 return handler(room, stanza, origin); |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 module:hook("iq-get/bare/"..xmlns_gc3..":participants", room_event_handler(fetch_participant_list)); |
