Software /
code /
prosody-modules
Comparison
mod_muc_restrict_avatars/mod_muc_restrict_avatars.lua @ 5920:5b95e06d75d5
Guard for not room
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Tue, 30 Apr 2024 15:06:03 -0500 |
parent | 5905:66e7d46b1d4b |
comparison
equal
deleted
inserted
replaced
5905:66e7d46b1d4b | 5920:5b95e06d75d5 |
---|---|
28 -- Handle MUC configuration form submission | 28 -- Handle MUC configuration form submission |
29 module:hook("muc-config-submitted", function(event) | 29 module:hook("muc-config-submitted", function(event) |
30 local room, fields, changed = event.room, event.fields, event.changed; | 30 local room, fields, changed = event.room, event.fields, event.changed; |
31 local restrict_avatars = fields["restrict_avatars"]; | 31 local restrict_avatars = fields["restrict_avatars"]; |
32 | 32 |
33 if restrict_avatars ~= is_avatar_restriction_enabled(room) then | 33 if room and restrict_avatars ~= is_avatar_restriction_enabled(room) then |
34 -- Update room settings based on the submitted value | 34 -- Update room settings based on the submitted value |
35 room._data.restrict_avatars = restrict_avatars; | 35 room._data.restrict_avatars = restrict_avatars; |
36 -- Mark the configuration as changed | 36 -- Mark the configuration as changed |
37 if type(changed) == "table" then | 37 if type(changed) == "table" then |
38 changed["restrict_avatars"] = true; | 38 changed["restrict_avatars"] = true; |
44 | 44 |
45 -- Handle presence/full events to filter avatar advertisements | 45 -- Handle presence/full events to filter avatar advertisements |
46 module:hook("presence/full", function(event) | 46 module:hook("presence/full", function(event) |
47 local stanza = event.stanza; | 47 local stanza = event.stanza; |
48 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)); |
49 if not room:get_affiliation(stanza.attr.from) then | 49 if room and not room:get_affiliation(stanza.attr.from) then |
50 if is_avatar_restriction_enabled(room) then | 50 if is_avatar_restriction_enabled(room) then |
51 stanza:maptags(filter_avatar_advertisement); | 51 stanza:maptags(filter_avatar_advertisement); |
52 end | 52 end |
53 end | 53 end |
54 end, 1); | 54 end, 1); |