Software /
code /
prosody
Comparison
plugins/muc/name.lib.lua @ 8986:320ae6dbb2e8
MUC: Add roomconfig_roomname to disco#info, and ensure it's not auto-generated
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 07 Jul 2018 12:14:29 +0100 |
parent | 7401:e16b3fd0bd80 |
child | 8988:d92b8bc6614c |
comparison
equal
deleted
inserted
replaced
8985:4101bcf9639a | 8986:320ae6dbb2e8 |
---|---|
12 local function get_name(room) | 12 local function get_name(room) |
13 return room._data.name or jid_split(room.jid); | 13 return room._data.name or jid_split(room.jid); |
14 end | 14 end |
15 | 15 |
16 local function set_name(room, name) | 16 local function set_name(room, name) |
17 if name == "" or name == (jid_split(room.jid)) then name = nil; end | 17 if name == "" then name = nil; end |
18 if room._data.name == name then return false; end | 18 if room._data.name == name then return false; end |
19 room._data.name = name; | 19 room._data.name = name; |
20 return true; | 20 return true; |
21 end | 21 end |
22 | 22 |
23 module:hook("muc-disco#info", function(event) | 23 local function insert_name_into_form(event); |
24 event.reply:tag("identity", {category="conference", type="text", name=get_name(event.room)}):up(); | |
25 end); | |
26 | |
27 module:hook("muc-config-form", function(event) | |
28 table.insert(event.form, { | 24 table.insert(event.form, { |
29 name = "muc#roomconfig_roomname"; | 25 name = "muc#roomconfig_roomname"; |
30 type = "text-single"; | 26 type = "text-single"; |
31 label = "Name"; | 27 label = "Name"; |
32 value = get_name(event.room) or ""; | 28 value = event.room._data.name; |
33 }); | 29 }); |
34 end, 100-1); | 30 end |
31 | |
32 module:hook("muc-disco#info", function(event) | |
33 event.reply:tag("identity", {category="conference", type="text", name=get_name(event.room)}):up(); | |
34 insert_name_into_form(event); | |
35 end); | |
36 | |
37 module:hook("muc-config-form", insert_name_into_form, 100-1); | |
35 | 38 |
36 module:hook("muc-config-submitted/muc#roomconfig_roomname", function(event) | 39 module:hook("muc-config-submitted/muc#roomconfig_roomname", function(event) |
37 if set_name(event.room, event.value) then | 40 if set_name(event.room, event.value) then |
38 event.status_codes["104"] = true; | 41 event.status_codes["104"] = true; |
39 end | 42 end |