Software /
code /
prosody-modules
Comparison
mod_muc_restrict_avatars/mod_muc_restrict_avatars.lua @ 5905:66e7d46b1d4b
mod_muc_restrict_avatars: Allow MUC admin to control restriction
Thanks, Strix!
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Tue, 09 Apr 2024 14:44:52 -0500 |
parent | 5672:2c69577b28c2 |
child | 5920:5b95e06d75d5 |
comparison
equal
deleted
inserted
replaced
5904:eb1c524a5150 | 5905:66e7d46b1d4b |
---|---|
7 end | 7 end |
8 | 8 |
9 return tag; | 9 return tag; |
10 end | 10 end |
11 | 11 |
12 -- Function to determine if avatar restriction is enabled | |
13 local function is_avatar_restriction_enabled(room) | |
14 return room._data.restrict_avatars; | |
15 end | |
16 | |
17 -- Add MUC configuration form option for avatar restriction | |
18 module:hook("muc-config-form", function(event) | |
19 local room, form = event.room, event.form; | |
20 table.insert(form, { | |
21 name = "restrict_avatars", | |
22 type = "boolean", | |
23 label = "Restrict avatars to members only", | |
24 value = is_avatar_restriction_enabled(room) | |
25 }); | |
26 end); | |
27 | |
28 -- Handle MUC configuration form submission | |
29 module:hook("muc-config-submitted", function(event) | |
30 local room, fields, changed = event.room, event.fields, event.changed; | |
31 local restrict_avatars = fields["restrict_avatars"]; | |
32 | |
33 if restrict_avatars ~= is_avatar_restriction_enabled(room) then | |
34 -- Update room settings based on the submitted value | |
35 room._data.restrict_avatars = restrict_avatars; | |
36 -- Mark the configuration as changed | |
37 if type(changed) == "table" then | |
38 changed["restrict_avatars"] = true; | |
39 else | |
40 event.changed = true; | |
41 end | |
42 end | |
43 end); | |
44 | |
45 -- Handle presence/full events to filter avatar advertisements | |
12 module:hook("presence/full", function(event) | 46 module:hook("presence/full", function(event) |
13 local stanza = event.stanza; | 47 local stanza = event.stanza; |
14 local room = mod_muc.get_room_from_jid(bare_jid(stanza.attr.to)); | 48 local room = mod_muc.get_room_from_jid(bare_jid(stanza.attr.to)); |
15 | |
16 if not room:get_affiliation(stanza.attr.from) then | 49 if not room:get_affiliation(stanza.attr.from) then |
17 stanza:maptags(filter_avatar_advertisement); | 50 if is_avatar_restriction_enabled(room) then |
51 stanza:maptags(filter_avatar_advertisement); | |
52 end | |
18 end | 53 end |
19 end, 1); | 54 end, 1); |