Software /
code /
prosody
Comparison
plugins/muc/description.lib.lua @ 6204:c3254827698d
plugins/muc/muc.lib: Move description functions out to own file
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Wed, 02 Apr 2014 15:14:52 -0400 |
child | 6991:84e01dbb739e |
comparison
equal
deleted
inserted
replaced
6203:b6ffce01e6cf | 6204:c3254827698d |
---|---|
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 if room.save then room:save(true); end | |
19 return true; | |
20 end | |
21 | |
22 local function add_form_option(event) | |
23 table.insert(event.form, { | |
24 name = "muc#roomconfig_roomdesc"; | |
25 type = "text-single"; | |
26 label = "Description"; | |
27 value = get_description(event.room) or ""; | |
28 }); | |
29 end | |
30 module:hook("muc-disco#info", add_form_option); | |
31 module:hook("muc-config-form", add_form_option); | |
32 | |
33 module:hook("muc-config-submitted", function(event) | |
34 local new = event.fields["muc#roomconfig_roomdesc"]; | |
35 if new ~= nil and set_description(event.room, new) then | |
36 event.status_codes["104"] = true; | |
37 end | |
38 end); | |
39 | |
40 return { | |
41 get = get_description; | |
42 set = set_description; | |
43 }; |