| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-06-22 20:06:19 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-06-22 20:16:17 UTC |
| parent | b1fbd3ca4c793040f17be8ec524b4debc8041b3a |
| borogove/Chat.hx | +15 | -0 |
| test/TestChat.hx | +26 | -0 |
diff --git a/borogove/Chat.hx b/borogove/Chat.hx index 78129a4..459fd8c 100644 --- a/borogove/Chat.hx +++ b/borogove/Chat.hx @@ -1657,6 +1657,21 @@ class Channel extends Chat { return disco.features.contains("urn:xmpp:message-moderate:1") && it.next().mucUser.role == "moderator"; } + /** + If the user is muted by local policy, send a request to moderators + **/ + public function requestToSend() { + // TODO: no way to send a message long with the request right now that + // will be supported by Snikket, but might be nice. + final outboxItem = outbox.newItem(); + outboxItem.handle(() -> client.sendStanza( + new Stanza("message", { to: chatId }) + .tag("x", { xmlns: "jabber:x:data", type: "submit" }) + .tag("field", { "var": "FORM_TYPE" }).textTag("value", "http://jabber.org/protocol/muc#request").up() + .tag("field", { "var": "muc#role" }).textTag("value", "participant").up() + )); + } + private function isOwner() { if (self == null) return false; diff --git a/test/TestChat.hx b/test/TestChat.hx index 86e2704..590adcf 100644 --- a/test/TestChat.hx +++ b/test/TestChat.hx @@ -668,6 +668,32 @@ class TestChat extends utest.Test { Assert.raises(() -> chat.setPhoto(source), String); } + + public function testRequestToSend(async: Async) { + final persistence = new Dummy(); + final client = new Client("test@example.com", persistence); + final chat = new borogove.Chat.Channel(client, client.stream, persistence, "channel@example.com"); + + client.stream.on("sendStanza", (stanza: Stanza) -> { + if (stanza.name == "message" && stanza.attr.get("to") == "channel@example.com" && stanza.attr.get("type") == null) { + final x = stanza.getChild("x", "jabber:x:data"); + if (x != null && x.attr.get("type") == "submit") { + final fields = x.allTags("field"); + Assert.equals(2, fields.length); + Assert.equals("FORM_TYPE", fields[0].attr.get("var")); + Assert.equals("http://jabber.org/protocol/muc#request", fields[0].getChild("value").getText()); + Assert.equals("muc#role", fields[1].attr.get("var")); + Assert.equals("participant", fields[1].getChild("value").getText()); + async.done(); + return EventHandled; + } + } + return EventUnhandled; + }); + + chat.outbox.start(); + chat.requestToSend(); + } } @:access(borogove)