Software /
code /
prosody
Comparison
plugins/muc/language.lib.lua @ 8833:9c90cd2fc4c3
MUC: Add support for setting a room language (closes #1149)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 30 May 2018 09:06:17 +0200 |
parent | 8831:plugins/muc/description.lib.lua@f25fa63750fb |
child | 9034:1c709e3d2e5e |
comparison
equal
deleted
inserted
replaced
8832:a9c3b15b9d37 | 8833:9c90cd2fc4c3 |
---|---|
1 -- Prosody IM | |
2 -- Copyright (C) 2008-2010 Matthew Wild | |
3 -- Copyright (C) 2008-2010 Waqas Hussain | |
4 -- Copyright (C) 2014 Daurnimator | |
5 -- | |
6 -- This project is MIT/X11 licensed. Please see the | |
7 -- COPYING file in the source package for more information. | |
8 -- | |
9 | |
10 local function get_language(room) | |
11 return room._data.language; | |
12 end | |
13 | |
14 local function set_language(room, language) | |
15 if language == "" then language = nil; end | |
16 if get_language(room) == language then return false; end | |
17 room._data.language = language; | |
18 return true; | |
19 end | |
20 | |
21 local function add_disco_form(event) | |
22 table.insert(event.form, { | |
23 name = "muc#roominfo_lang"; | |
24 value = ""; | |
25 }); | |
26 event.formdata["muc#roominfo_lang"] = get_language(event.room); | |
27 end | |
28 | |
29 local function add_form_option(event) | |
30 table.insert(event.form, { | |
31 name = "muc#roomconfig_lang"; | |
32 label = "Language tag for Room (e.g. 'en', 'de', 'fr' etc.)"; | |
33 type = "text-single"; | |
34 value = get_language(event.room) or ""; | |
35 }); | |
36 end | |
37 | |
38 module:hook("muc-disco#info", add_disco_form); | |
39 module:hook("muc-config-form", add_form_option, 100-9.5); | |
40 | |
41 module:hook("muc-config-submitted/muc#roomconfig_lang", function(event) | |
42 if set_language(event.room, event.value) then | |
43 event.status_codes["104"] = true; | |
44 end | |
45 end); | |
46 | |
47 return { | |
48 get = get_language; | |
49 set = set_language; | |
50 }; |