Mercurial > prosody-modules
annotate mod_muc_hide_media/mod_muc_hide_media.lua @ 5519:83ebfc367169
mod_http_oauth2: Return Authentication Time per OpenID Core Section 2
Mandatory To Implement, either MUST include or OPTIONAL depending on
things we don't look at, so might as well include it all the time.
Since we do not persist authentication state with cookies or such, the
authentication time will always be some point between the user being
sent to the authorization endpoint and the time they are sent back to
the client application.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 05 Jun 2023 22:32:44 +0200 |
parents | 9084588c73ae |
children |
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); |