Software /
code /
prosody
Annotate
plugins/muc/name.lib.lua @ 7121:bb1adaabcff6
MUC: Fix copypaste mistake
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 03 Feb 2016 02:16:28 +0100 |
parent | 7119:50b9a7e86de9 |
child | 7124:a0764a8d6b26 |
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 }); |
7121 | 34 event.formdata["muc#roomconfig_roomname"] = get_name(event.room) or ""; |
6209
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 }; |