Mercurial > prosody-modules
comparison 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 |
parents | |
children | 65e94270c413 |
comparison
equal
deleted
inserted
replaced
3680:7570976318a9 | 3681:d267e381255f |
---|---|
1 module:depends"muc"; | |
2 | |
3 local hide_by_default = not module:get_option_boolean("muc_room_default_hide_media", false); | |
4 | |
5 local function should_hide_media(room) | |
6 local hide_media = room._data.hide_media; | |
7 if hide_media == nil then | |
8 hide_media = hide_by_default; | |
9 end | |
10 return hide_media; | |
11 end | |
12 | |
13 module:hook("muc-config-form", function(event) | |
14 local room, form = event.room, event.form; | |
15 table.insert(form, { | |
16 name = "{xmpp:prosody.im}muc#roomconfig_display_media", | |
17 type = "boolean", | |
18 label = "Display inline media (images, etc.)", | |
19 value = not should_hide_media(room), | |
20 }); | |
21 end); | |
22 | |
23 module:hook("muc-config-submitted", function(event) | |
24 local room, fields, changed = event.room, event.fields, event.changed; | |
25 local new_hide_media = not fields["{xmpp:prosody.im}muc#roomconfig_display_media"]; | |
26 if new_hide_media ~= should_hide_media(room) then | |
27 if new_hide_media == hide_by_default(room) then | |
28 room._data.hide_media = nil; | |
29 else | |
30 room._data.hide_media = new_hide_media; | |
31 end | |
32 if type(changed) == "table" then | |
33 changed["{xmpp:prosody.im}muc#roomconfig_display_media"] = true; | |
34 else | |
35 event.changed = true; | |
36 end | |
37 end | |
38 end); | |
39 | |
40 module:hook("muc-disco#info", function (event) | |
41 local room, form, formdata = event.room, event.form, event.formdata; | |
42 | |
43 local display_media = not should_hide_media(room); | |
44 table.insert(form, { | |
45 name = "{xmpp:prosody.im}muc#roomconfig_display_media", | |
46 }); | |
47 formdata["{xmpp:prosody.im}muc#roomconfig_display_media"] = display_media; | |
48 end); | |
49 | |
50 | |
51 module:hook("muc-occupant-groupchat", function (event) | |
52 local stanza = event.stanza; | |
53 if stanza.attr.type ~= "groupchat" then return; end | |
54 if should_hide_media(event.room) then | |
55 stanza:remove_children("x", "jabber:x:oob"); | |
56 end | |
57 end, 20); |