Software / code / prosody
Comparison
plugins/muc/name.lib.lua @ 6209:cc00e78e6a31
plugins/muc: Move name functions to seperate module
| author | daurnimator <quae@daurnimator.com> |
|---|---|
| date | Wed, 02 Apr 2014 17:02:07 -0400 |
| child | 6991:84e01dbb739e |
comparison
equal
deleted
inserted
replaced
| 6208:d724289a5226 | 6209:cc00e78e6a31 |
|---|---|
| 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 jid_split = require "util.jid".split; | |
| 11 | |
| 12 local function get_name(room) | |
| 13 return room._data.name or jid_split(room.jid); | |
| 14 end | |
| 15 | |
| 16 local function set_name(room, name) | |
| 17 if name == "" or name == (jid_split(room.jid)) then name = nil; end | |
| 18 if room._data.name == name then return false; end | |
| 19 room._data.name = name; | |
| 20 if room.save then room:save(true); end | |
| 21 return true; | |
| 22 end | |
| 23 | |
| 24 module:hook("muc-disco#info", function(event) | |
| 25 event.reply:tag("identity", {category="conference", type="text", name=get_name(event.room)}):up(); | |
| 26 end); | |
| 27 | |
| 28 module:hook("muc-config-form", function(event) | |
| 29 table.insert(event.form, { | |
| 30 name = "muc#roomconfig_roomname"; | |
| 31 type = "text-single"; | |
| 32 label = "Name"; | |
| 33 value = get_name(event.room) or ""; | |
| 34 }); | |
| 35 end); | |
| 36 | |
| 37 module:hook("muc-config-submitted", function(event) | |
| 38 local new = event.fields["muc#roomconfig_roomname"]; | |
| 39 if new ~= nil and set_name(event.room, new) then | |
| 40 event.status_codes["104"] = true; | |
| 41 end | |
| 42 end); | |
| 43 | |
| 44 return { | |
| 45 get = get_name; | |
| 46 set = set_name; | |
| 47 }; |