util.encodings: Spell out all IDNA 2008 options ICU has
[prosody.git] / plugins / muc / name.lib.lua
blob37fe12599e4234c4c77edda4397c729b44a59505
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 --
10 local jid_split = require "util.jid".split;
12 local function get_name(room)
13 return room._data.name or jid_split(room.jid);
14 end
16 local function set_name(room, name)
17 if name == "" then name = nil; end
18 if room._data.name == name then return false; end
19 room._data.name = name;
20 return true;
21 end
23 local function insert_name_into_form(event)
24 table.insert(event.form, {
25 name = "muc#roomconfig_roomname";
26 type = "text-single";
27 label = "Title";
28 value = event.room._data.name;
29 });
30 end
32 module:hook("muc-disco#info", function(event)
33 event.reply:tag("identity", {category="conference", type="text", name=get_name(event.room)}):up();
34 insert_name_into_form(event);
35 end);
37 module:hook("muc-config-form", insert_name_into_form, 100-1);
39 module:hook("muc-config-submitted/muc#roomconfig_roomname", function(event)
40 if set_name(event.room, event.value) then
41 event.status_codes["104"] = true;
42 end
43 end);
45 return {
46 get = get_name;
47 set = set_name;