Software /
code /
prosody
Annotate
plugins/muc/name.lib.lua @ 8674:55807a2f5d23
luacheckrc: Only allow top level declarations in the main prosody executable
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 23 Mar 2018 13:13:07 +0100 |
parent | 7401:e16b3fd0bd80 |
child | 8986:320ae6dbb2e8 |
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 return true; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
21 end |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
22 |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
23 module:hook("muc-disco#info", function(event) |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
24 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
|
25 end); |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
26 |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
27 module:hook("muc-config-form", function(event) |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
28 table.insert(event.form, { |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
29 name = "muc#roomconfig_roomname"; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
30 type = "text-single"; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
31 label = "Name"; |
7124
a0764a8d6b26
MUC: Roll back parts of 50b9a7e86de9 that were not in the disco#info event
Kim Alvefur <zash@zash.se>
parents:
7121
diff
changeset
|
32 value = get_name(event.room) or ""; |
6209
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
33 }); |
7401
e16b3fd0bd80
MUC: Assign priorities to config form hooks so they have a consistent order on each start
Kim Alvefur <zash@zash.se>
parents:
7353
diff
changeset
|
34 end, 100-1); |
6209
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
35 |
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
|
36 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
|
37 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
|
38 event.status_codes["104"] = true; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
39 end |
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 |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
42 return { |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
43 get = get_name; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
44 set = set_name; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
45 }; |