93 lines
2.5 KiB
Lua
93 lines
2.5 KiB
Lua
local jid_split = require "util.jid".split;
|
|
local st = require "util.stanza";
|
|
local json = require "util.json";
|
|
|
|
|
|
module:depends"muc";
|
|
|
|
local function dumpTable(t, depth)
|
|
local result = "";
|
|
if (not depth) then depth = 0 end;
|
|
|
|
local prefix = string.rep(" ", depth);
|
|
|
|
if (type(t) ~= "table") then
|
|
result = result.." "..tostring(t);
|
|
else
|
|
for key,value in pairs(t) do
|
|
result = result..prefix..tostring(key).." => "..dumpTable(value, depth+1).."\n"
|
|
end
|
|
end
|
|
|
|
return result;
|
|
end
|
|
|
|
local function get_vdata(room)
|
|
local vdata = room._data.vdata;
|
|
if vdata then -- explicitly configured
|
|
return vdata;
|
|
end
|
|
return "{ }";
|
|
end
|
|
|
|
module:hook("muc-config-form", function(event)
|
|
local room, form = event.room, event.form;
|
|
local vdata = get_vdata(room);
|
|
table.insert(form, {
|
|
name = "muc#roomconfig_vdata",
|
|
type = "text-single",
|
|
label = "muc data",
|
|
value = vdata,
|
|
});
|
|
-- value = get_e2e(room),
|
|
end);
|
|
|
|
|
|
local function broadcast_presence(room)
|
|
local data = room._data;
|
|
local aff = room._affiliations;
|
|
module:log("info", "updated config for room %s", room);
|
|
module:log("info", "new data: %s", dumpTable(data));
|
|
module:log("info", "new aff: %s", dumpTable(aff));
|
|
end
|
|
|
|
module:hook("muc-config-submitted", function(event)
|
|
local room, fields, changed = event.room, event.fields, event.changed;
|
|
local data = room._data;
|
|
local affiliations = room._affiliations;
|
|
-- module:log("info", "updated config for room %s", room);
|
|
-- module:log("info", "new data: %s", dumpTable(data));
|
|
-- module:log("info", "new aff: %s", dumpTable(affiliations));
|
|
-- module:log("info", "event.fields: %s", dumpTable(fields));
|
|
-- module:log("info", "event.changed: %s", dumpTable(changed));
|
|
|
|
room._data.vdata = fields["muc#roomconfig_vdata"];
|
|
if type(changed) == "table" then
|
|
changed["muc#roomconfig_vdata"] = true;
|
|
else
|
|
event.changed = true;
|
|
end
|
|
local msg = st.message({type='groupchat', from=room.jid})
|
|
:tag('x', {xmlns='xmpp:vnctalk:update'})
|
|
:tag("affiliations"):text(json.encode(affiliations)):up()
|
|
:tag("data"):text(json.encode(data)):up();
|
|
module:log("info","st: %s", tostring(msg));
|
|
room:broadcast_message(msg);
|
|
|
|
end, -1);
|
|
|
|
|
|
module:hook("muc-disco#info", function (event)
|
|
local room, form, formdata = event.room, event.form, event.formdata;
|
|
|
|
local vdata = get_vdata(room);
|
|
module:log("info", "got disco vdata as %s", vdata);
|
|
-- if not e2e or e2e == "" then
|
|
--return;
|
|
-- end
|
|
table.insert(form, {
|
|
name = "muc#roominfo_vdata",
|
|
});
|
|
formdata["muc#roominfo_vdata"] = vdata;
|
|
end);
|