Annotate

mod_muc_hide_media/mod_muc_hide_media.lua @ 5731:37ba9478b387

mod_audit: Fix recording location info The method :query_by_addr only works for IPv4, even if you open the IPv6 database, which is an odd API. It also returns a table, not a string.
author Kim Alvefur <zash@zash.se>
date Mon, 13 Nov 2023 12:14:31 +0100
parent 4788: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",
4788
9084588c73ae mod_muc_hide_media: Fix disco#info field (thanks mirux)
Kim Alvefur <zash@zash.se>
parents: 3689
diff changeset
46 type = "boolean",
3681
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 });
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 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
49 end);
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50
3689
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
51 local function filter_media_tags(tag)
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
52 local xmlns = tag.attr.xmlns;
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
53 if xmlns == "jabber:x:oob" then
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
54 return nil;
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
55 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
56 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
57 return nil;
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 end
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
60 return tag;
65e94270c413 mod_muc_hide_media: Also strip SIMS media
Matthew Wild <mwild1@gmail.com>
parents: 3681
diff changeset
61 end
3681
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 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
64 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
65 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
66 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
67 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
68 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 end, 20);