annotate mod_muc_webchat_url/mod_muc_webchat_url.lua @ 3672:b8bcea17ccd6

mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
author Kim Alvefur <zash@zash.se>
date Tue, 17 Sep 2019 17:12:59 +0200
parents mod_muc_lang/mod_muc_lang.lua@ef5d52ca31bb
children 11ebf1da416b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
1 local jid_split = require "util.jid".split;
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
2 module:depends"muc";
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
3
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
4 local webchat_baseurl = module:get_option_string("muc_webchat_baseurl", nil);
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
5
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
6 local function get_webchat_url(room)
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
7 local webchat_url = room._data.webchat_url;
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
8 if webchat_url then -- explicitly configured
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
9 return webchat_url;
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
10 end
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
11 if not webchat_baseurl then
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
12 -- no template
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
13 return nil;
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
14 end
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
15 if room:get_hidden() or room:get_members_only() or room:get_password() then
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
16 -- not a public room
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
17 return nil;
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
18 end
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
19 return (webchat_baseurl:gsub("{(%w+)}", {
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
20 jid = room.jid,
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
21 node = select(1, jid_split(room.jid)),
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
22 host = select(2, jid_split(room.jid)),
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
23 }));
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
24 end
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 module:hook("muc-config-form", function(event)
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local room, form = event.room, event.form;
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 table.insert(form, {
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
29 name = "muc#roomconfig_webchat_url",
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 type = "text-single",
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
31 label = "URL where this room can be joined",
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
32 value = get_webchat_url(room),
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 });
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end);
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 module:hook("muc-config-submitted", function(event)
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 local room, fields, changed = event.room, event.fields, event.changed;
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
38 local new = fields["muc#roomconfig_webchat_url"];
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
39 if new ~= room._data.webchat_url then
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
40 room._data.webchat_url = new;
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 if type(changed) == "table" then
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
42 changed["muc#roomconfig_webchat_url"] = true;
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 else
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 event.changed = true;
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 end
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 end
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 end);
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 module:hook("muc-disco#info", function (event)
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 local room, form, formdata = event.room, event.form, event.formdata;
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
52 local webchat_url = get_webchat_url(room);
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
53 if not webchat_url or webchat_url == "" then
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
54 return;
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
55 end
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 table.insert(form, {
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
57 name = "muc#roominfo_webchat_url",
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 });
3672
b8bcea17ccd6 mod_muc_webchat_url: Advertise the URL to a webchat in disco#info
Kim Alvefur <zash@zash.se>
parents: 3546
diff changeset
59 formdata["muc#roominfo_webchat_url"] = webchat_url;
3069
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 end);
e1db146984a0 mod_muc_lang: Advertises the room language
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61