annotate mod_muc_hide_media/mod_muc_hide_media.lua @ 4283:2ae71126e379

mod_sentry: New module to forward errors to a Sentry server
author Matthew Wild <mwild1@gmail.com>
date Tue, 08 Dec 2020 15:34:53 +0000
parents 65e94270c413
children 9084588c73ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3681
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 module:depends"muc";
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local hide_by_default = not module:get_option_boolean("muc_room_default_hide_media", false);
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local function should_hide_media(room)
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local hide_media = room._data.hide_media;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 if hide_media == nil then
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 hide_media = hide_by_default;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 return hide_media;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 module:hook("muc-config-form", function(event)
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local room, form = event.room, event.form;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 table.insert(form, {
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 name = "{xmpp:prosody.im}muc#roomconfig_display_media",
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 type = "boolean",
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 label = "Display inline media (images, etc.)",
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 value = not should_hide_media(room),
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 });
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end);
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 module:hook("muc-config-submitted", function(event)
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local room, fields, changed = event.room, event.fields, event.changed;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local new_hide_media = not fields["{xmpp:prosody.im}muc#roomconfig_display_media"];
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if new_hide_media ~= should_hide_media(room) then
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 if new_hide_media == hide_by_default(room) then
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 room._data.hide_media = nil;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 else
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 room._data.hide_media = new_hide_media;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 if type(changed) == "table" then
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 changed["{xmpp:prosody.im}muc#roomconfig_display_media"] = true;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 else
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 event.changed = true;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end);
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 module:hook("muc-disco#info", function (event)
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 local room, form, formdata = event.room, event.form, event.formdata;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local display_media = not should_hide_media(room);
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 table.insert(form, {
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 name = "{xmpp:prosody.im}muc#roomconfig_display_media",
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 });
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 formdata["{xmpp:prosody.im}muc#roomconfig_display_media"] = display_media;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end);
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
3689
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
50 local function filter_media_tags(tag)
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
51 local xmlns = tag.attr.xmlns;
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
52 if xmlns == "jabber:x:oob" then
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
53 return nil;
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
54 elseif xmlns == "urn:xmpp:reference:0" then
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
55 if tag:get_child("media-sharing", "urn:xmpp:sims:1") then
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
56 return nil;
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
57 end
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
58 end
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
59 return tag;
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
60 end
3681
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 module:hook("muc-occupant-groupchat", function (event)
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 local stanza = event.stanza;
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 if stanza.attr.type ~= "groupchat" then return; end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 if should_hide_media(event.room) then
3689
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
66 stanza:maptags(filter_media_tags);
3681
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 end, 20);