Software /
code /
prosody
Annotate
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 |
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 |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
37 module:hook("muc-config-submitted", function(event) |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
38 local new = event.fields["muc#roomconfig_roomname"]; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
39 if new ~= nil and set_name(event.room, new) then |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
40 event.status_codes["104"] = true; |
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 end); |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
43 |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
44 return { |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
45 get = get_name; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
46 set = set_name; |
cc00e78e6a31
plugins/muc: Move name functions to seperate module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
47 }; |