Annotate

mod_muc_hide_media/mod_muc_hide_media.lua @ 3681:d267e381255f

mod_muc_hide_media: Module to allow hiding inline media in a MUC
author Matthew Wild <mwild1@gmail.com>
date Sun, 29 Sep 2019 11:48:27 +0100
child 3689:65e94270c413
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
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 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
52 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
53 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
54 if should_hide_media(event.room) then
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 stanza:remove_children("x", "jabber:x:oob");
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 end
d267e381255f mod_muc_hide_media: Module to allow hiding inline media in a MUC
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 end, 20);