Files
Stefan-SangerandClaude Opus 4.8 c05bb9aadb fix(muc): serialize e2e roominfo as string in disco#info
mod_vnc_e2ehints put the raw boolean returned by get_e2e() (false when
unset) into the disco#info roominfo formdata. muc#roominfo_e2e is a
text-single field, and util.dataforms/util.stanza cannot serialize a
boolean field value, so room:get_disco_info() raised an error and the
server silently dropped the disco#info reply for every existing room
(confirmed at the wire level: non-existent rooms returned item-not-found,
existing rooms returned nothing). Coerce the value to a string, matching
the working mod_vnc_muc_data pattern. get_e2e() itself is left returning a
boolean since the muc-config-form boolean field needs it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Part-of: <http://gitlab.vnc.biz/uxf/vnctalk-prosody/-/merge_requests/3>
2026-07-15 17:58:02 +02:00

60 lines
1.6 KiB
Lua

local jid_split = require "util.jid".split;
module:depends"muc";
local function get_e2e(room)
local e2e = room._data.e2e;
if e2e then -- explicitly configured
return e2e;
end
return false;
end
module:hook("muc-config-form", function(event)
local room, form = event.room, event.form;
local re2e = get_e2e(room);
table.insert(form, {
name = "muc#roomconfig_e2e",
type = "boolean",
label = "if the room is E2E ecnrypted",
value = re2e,
});
-- value = get_e2e(room),
end);
module:hook("muc-config-submitted", function(event)
local room, fields, changed = event.room, event.fields, event.changed;
local new = fields["muc#roomconfig_e2e"];
if new ~= get_e2e(room) then
if new == get_e2e(room) then
room._data.e2e = false;
else
room._data.e2e = new;
end
if type(changed) == "table" then
changed["muc#roomconfig_e2e"] = true;
else
event.changed = true;
end
end
end);
module:hook("muc-disco#info", function (event)
local room, form, formdata = event.room, event.form, event.formdata;
local e2e = get_e2e(room);
module:log("info", "got e2e as %s", e2e);
-- if not e2e or e2e == "" then
--return;
-- end
table.insert(form, {
name = "muc#roominfo_e2e",
});
-- formdata values must be strings: this is a text-single field (no type),
-- and util.dataforms/util.stanza cannot serialize a raw boolean as a
-- field value. get_e2e() returns a boolean (false when unset), so an
-- unconverted value broke room:get_disco_info() for every existing room
-- and the server silently dropped the disco#info reply.
formdata["muc#roominfo_e2e"] = tostring(e2e);
end);