Annotate

plugins/muc/name.lib.lua @ 6991:84e01dbb739e

MUC: Update all config form handlers to take advantage of the new per-option events
author Matthew Wild <mwild1@gmail.com>
date Fri, 11 Dec 2015 15:33:58 +0000
parent 6209:cc00e78e6a31
child 7119:50b9a7e86de9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6209
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
1 -- Prosody IM
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
4 -- Copyright (C) 2014 Daurnimator
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
5 --
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
7 -- COPYING file in the source package for more information.
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
8 --
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
9
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
10 local jid_split = require "util.jid".split;
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
11
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
12 local function get_name(room)
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
13 return room._data.name or jid_split(room.jid);
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
14 end
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
15
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
16 local function set_name(room, name)
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
17 if name == "" or name == (jid_split(room.jid)) then name = nil; end
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
18 if room._data.name == name then return false; end
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
19 room._data.name = name;
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
20 if room.save then room:save(true); end
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
21 return true;
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
22 end
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
23
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
24 module:hook("muc-disco#info", function(event)
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
25 event.reply:tag("identity", {category="conference", type="text", name=get_name(event.room)}):up();
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
26 end);
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
27
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
28 module:hook("muc-config-form", function(event)
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
29 table.insert(event.form, {
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
30 name = "muc#roomconfig_roomname";
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
31 type = "text-single";
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
32 label = "Name";
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
33 value = get_name(event.room) or "";
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
34 });
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
35 end);
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
36
6991
84e01dbb739e MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents: 6209
diff changeset
37 module:hook("muc-config-submitted/muc#roomconfig_roomname", function(event)
84e01dbb739e MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents: 6209
diff changeset
38 if set_name(event.room, event.value) then
6209
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
39 event.status_codes["104"] = true;
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
40 end
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
41 end);
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
42
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
43 return {
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
44 get = get_name;
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
45 set = set_name;
cc00e78e6a31 plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
46 };