Software /
code /
prosody
Changeset
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 |
parents | 6203:b6ffce01e6cf |
children | 6205:49dd381666f3 |
files | plugins/muc/description.lib.lua plugins/muc/muc.lib.lua |
diffstat | 2 files changed, 47 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/muc/description.lib.lua Wed Apr 02 15:14:52 2014 -0400 @@ -0,0 +1,43 @@ +-- Prosody IM +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain +-- Copyright (C) 2014 Daurnimator +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +local function get_description(room) + return room._data.description; +end + +local function set_description(room, description) + if description == "" then description = nil; end + if get_description(room) == description then return false; end + room._data.description = description; + if room.save then room:save(true); end + return true; +end + +local function add_form_option(event) + table.insert(event.form, { + name = "muc#roomconfig_roomdesc"; + type = "text-single"; + label = "Description"; + value = get_description(event.room) or ""; + }); +end +module:hook("muc-disco#info", add_form_option); +module:hook("muc-config-form", add_form_option); + +module:hook("muc-config-submitted", function(event) + local new = event.fields["muc#roomconfig_roomdesc"]; + if new ~= nil and set_description(event.room, new) then + event.status_codes["104"] = true; + end +end); + +return { + get = get_description; + set = set_description; +};
--- a/plugins/muc/muc.lib.lua Wed Apr 02 11:35:00 2014 -0400 +++ b/plugins/muc/muc.lib.lua Wed Apr 02 15:14:52 2014 -0400 @@ -430,9 +430,6 @@ event.reply:tag("feature", {var = event.room:get_whois() ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up(); end); module:hook("muc-disco#info", function(event) - table.insert(event.form, { name = "muc#roominfo_description", label = "Description", value = event.room:get_description() }); -end); -module:hook("muc-disco#info", function(event) local count = 0; for _ in event.room:each_occupant() do count = count + 1; end table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); end); @@ -495,16 +492,6 @@ function room_mt:get_name() return self._data.name or jid_split(self.jid); end -function room_mt:set_description(description) - if description == "" or type(description) ~= "string" then description = nil; end - if self._data.description ~= description then - self._data.description = description; - if self.save then self:save(true); end - end -end -function room_mt:get_description() - return self._data.description; -end function room_mt:set_password(password) if password == "" or type(password) ~= "string" then password = nil; end if self._data.password ~= password then @@ -928,14 +915,6 @@ end); module:hook("muc-config-form", function(event) table.insert(event.form, { - name = 'muc#roomconfig_roomdesc', - type = 'text-single', - label = 'Description', - value = event.room:get_description() or "", - }); -end); -module:hook("muc-config-form", function(event) - table.insert(event.form, { name = 'muc#roomconfig_persistentroom', type = 'boolean', label = 'Make Room Persistent?', @@ -1050,9 +1029,6 @@ event.update_option("name", "muc#roomconfig_roomname"); end); module:hook("muc-config-submitted", function(event) - event.update_option("description", "muc#roomconfig_roomdesc"); -end); -module:hook("muc-config-submitted", function(event) event.update_option("persistent", "muc#roomconfig_persistentroom"); end); module:hook("muc-config-submitted", function(event) @@ -1558,6 +1534,10 @@ return true; end +local description = module:require "muc/description"; +room_mt.get_description = description.get; +room_mt.set_description = description.set; + local _M = {}; -- module "muc" function _M.new_room(jid, config)