annotate mod_muc_restrict_media/mod_muc_restrict_media.lua @ 4787:df2246b15075

mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
author Matthew Wild <mwild1@gmail.com>
date Tue, 23 Nov 2021 17:14:25 +0000
parents
children f06d04cfea7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4787
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 module:depends"muc";
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local restrict_by_default = not module:get_option_boolean("muc_room_default_restrict_media", true);
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local function should_restrict_media(room)
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local restrict_media = room._data.restrict_media;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 if restrict_media == nil then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 restrict_media = restrict_by_default;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 return restrict_media;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 module:hook("muc-config-form", function(event)
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local room, form = event.room, event.form;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 table.insert(form, {
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_media",
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 type = "boolean",
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 label = "Display inline media (images, etc.) from non-members",
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 value = not should_restrict_media(room),
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 });
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end);
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 module:hook("muc-config-submitted", function(event)
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local room, fields, changed = event.room, event.fields, event.changed;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local new_restrict_media = not fields["{xmpp:prosody.im}muc#roomconfig_unaffiliated_media"];
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if new_restrict_media ~= should_restrict_media(room) then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 if new_restrict_media == restrict_by_default(room) then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 room._data.restrict_media = nil;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 else
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 room._data.restrict_media = new_restrict_media;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 if type(changed) == "table" then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 changed["{xmpp:prosody.im}muc#roomconfig_unaffiliated_media"] = true;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 else
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 event.changed = true;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end);
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 module:hook("muc-disco#info", function (event)
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 local room, form, formdata = event.room, event.form, event.formdata;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local allow_unaffiliated_media = not should_restrict_media(room);
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 table.insert(form, {
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 name = "{xmpp:prosody.im}muc#roomconfig_unaffiliated_media",
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 });
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 formdata["{xmpp:prosody.im}muc#roomconfig_unaffiliated_media"] = allow_unaffiliated_media;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end);
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 local function filter_media_tags(tag)
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 local xmlns = tag.attr.xmlns;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 if xmlns == "jabber:x:oob" then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 return nil;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 elseif xmlns == "urn:xmpp:reference:0" then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 if tag:get_child("media-sharing", "urn:xmpp:sims:1") then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 return nil;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 return tag;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 module:hook("muc-occupant-groupchat", function (event)
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 local stanza = event.stanza;
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 if stanza.attr.type ~= "groupchat" then return; end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 if should_restrict_media(event.room) then
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 stanza:maptags(filter_media_tags);
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 end
df2246b15075 mod_muc_restrict_media: Allow hiding inline media from unaffiliated users in MUCs
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 end, 20);