MUC: Assign priorities to config form hooks so they have a consistent order on each...
[prosody.git] / plugins / muc / description.lib.lua
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_description(room)
11         return room._data.description;
12 end
13
14 local function set_description(room, description)
15         if description == "" then description = nil; end
16         if get_description(room) == description then return false; end
17         room._data.description = description;
18         return true;
19 end
20
21 local function add_form_option(event)
22         table.insert(event.form, {
23                 name = "muc#roomconfig_roomdesc";
24                 type = "text-single";
25                 label = "Description";
26                 value = get_description(event.room) or "";
27         });
28 end
29 module:hook("muc-disco#info", add_form_option);
30 module:hook("muc-config-form", add_form_option, 100-2);
31
32 module:hook("muc-config-submitted/muc#roomconfig_roomdesc", function(event)
33         if set_description(event.room, event.value) then
34                 event.status_codes["104"] = true;
35         end
36 end);
37
38 return {
39         get = get_description;
40         set = set_description;
41 };