| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-11-10 03:18:40 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-11-10 03:18:40 UTC |
| parent | 4b7d5403a5548e13d95dce7f781162b5a2b331f6 |
| borogove/Chat.hx | +9 | -7 |
| test/TestChat.hx | +31 | -0 |
| test/TestClient.hx | +26 | -0 |
diff --git a/borogove/Chat.hx b/borogove/Chat.hx index 7d95a44..7d439b6 100644 --- a/borogove/Chat.hx +++ b/borogove/Chat.hx @@ -1671,13 +1671,15 @@ class Channel extends Chat { private function completeCreation(): Void { if (uiState != Creating) return; - uiState = Open; - outbox.start(); - client.channelPinger.schedule(this); - persistence.storeChats(client.accountId(), [this]); - persistence.storeMembers(client.accountId(), chatId, [self]).then(_ -> trigger("members/update", [self])); - client.sortChats(); - client.trigger("chats/update", [this]); + refreshDisco(() -> { + uiState = Open; + outbox.start(); + client.channelPinger.schedule(this); + persistence.storeChats(client.accountId(), [this]); + persistence.storeMembers(client.accountId(), chatId, [self]).then(_ -> trigger("members/update", [self])); + client.sortChats(); + client.trigger("chats/update", [this]); + }); } private function maybeConfigureCreation(): Void { diff --git a/test/TestChat.hx b/test/TestChat.hx index 444a2ef..24b84f7 100644 --- a/test/TestChat.hx +++ b/test/TestChat.hx @@ -701,6 +701,37 @@ class TestChat extends utest.Test { }); } + public function testCreationCompletionRefreshesDisco() { + final persistence = new Dummy(); + final client = new Client("test@example.com", persistence); + final channel = new Channel(client, client.stream, persistence, "room@example.com", Creating); + + var discoRequested = false; + var stillCreatingWhenDiscoSent = false; + client.stream.on("sendStanza", (stanza: Stanza) -> { + if (stanza.name == "iq" && stanza.attr.get("type") == "get" && stanza.getChild("query", "http://jabber.org/protocol/disco#info") != null) { + discoRequested = true; + stillCreatingWhenDiscoSent = channel.uiState == Creating; + client.stream.onStanza( + new Stanza("iq", { xmlns: "jabber:client", type: "result", id: stanza.attr.get("id"), from: "room@example.com", to: "test@example.com" }) + .tag("query", { xmlns: "http://jabber.org/protocol/disco#info" }) + .tag("identity", { category: "conference", type: "text" }).up() + .tag("feature", { "var": "http://jabber.org/protocol/muc" }).up() + .tag("feature", { "var": "muc_membersonly" }).up() + .up() + ); + } + return EventUnhandled; + }); + + channel.completeCreation(); + + Assert.isTrue(discoRequested); + Assert.isTrue(stillCreatingWhenDiscoSent); + Assert.isTrue(channel.isPrivate()); + Assert.equals(Open, channel.uiState); + } + public function testSelfPingNoopWhileCreating() { final persistence = new Dummy(); final client = new Client("test@example.com", persistence); diff --git a/test/TestClient.hx b/test/TestClient.hx index 27fe16d..aa4a177 100644 --- a/test/TestClient.hx +++ b/test/TestClient.hx @@ -1684,6 +1684,7 @@ class TestClient extends utest.Test { var submitted: Null<Stanza> = null; var ownerGets = 0; var ownerSets = 0; + var discoGets = 0; var done = false; client.on("chats/update", (chats: Array<Chat>) -> { @@ -1693,6 +1694,7 @@ class TestClient extends utest.Test { done = true; Assert.equals(1, ownerGets); Assert.equals(1, ownerSets); + Assert.equals(1, discoGets); Assert.notNull(submitted); Assert.equals("Design Team", submittedField(submitted, "muc#roomconfig_roomname")); Assert.equals("0", submittedField(submitted, "muc#roomconfig_membersonly")); @@ -1731,6 +1733,17 @@ class TestClient extends utest.Test { client.stream.onStanza(responseStanza); return EventHandled; } + + if (stanza.getChild("query", "http://jabber.org/protocol/disco#info") != null) { + discoGets++; + final responseStanza = new Stanza("iq", { xmlns: "jabber:client", type: "result", id: stanza.attr.get("id"), from: "design-team@groups.example.com", to: "test@example.com" }) + .tag("query", { xmlns: "http://jabber.org/protocol/disco#info" }) + .tag("identity", { category: "conference", type: "text", name: "Design Team" }).up() + .tag("feature", { "var": "http://jabber.org/protocol/muc" }).up() + .up(); + client.stream.onStanza(responseStanza); + return EventHandled; + } } else if (stanza.name == "iq" && stanza.attr.get("type") == "set") { final query = stanza.getChild("query", "http://jabber.org/protocol/muc#owner"); if (query != null) { @@ -1778,6 +1791,7 @@ class TestClient extends utest.Test { var submitted: Null<Stanza> = null; var ownerGets = 0; var ownerSets = 0; + var discoGets = 0; client.stream.on("sendStanza", (stanza: Stanza) -> { if (stanza.name == "iq" && stanza.attr.get("type") == "get") { @@ -1796,6 +1810,17 @@ class TestClient extends utest.Test { client.stream.onStanza(responseStanza); return EventHandled; } + + if (stanza.getChild("query", "http://jabber.org/protocol/disco#info") != null) { + discoGets++; + final responseStanza = new Stanza("iq", { xmlns: "jabber:client", type: "result", id: stanza.attr.get("id"), from: "design-team@groups.example.com", to: "test@example.com" }) + .tag("query", { xmlns: "http://jabber.org/protocol/disco#info" }) + .tag("identity", { category: "conference", type: "text", name: "Design Team" }).up() + .tag("feature", { "var": "http://jabber.org/protocol/muc" }).up() + .up(); + client.stream.onStanza(responseStanza); + return EventHandled; + } } else if (stanza.name == "iq" && stanza.attr.get("type") == "set") { final query = stanza.getChild("query", "http://jabber.org/protocol/muc#owner"); if (query != null) { @@ -1843,6 +1868,7 @@ class TestClient extends utest.Test { Assert.equals("completed", nextSession.status); Assert.equals(1, ownerGets); Assert.equals(1, ownerSets); + Assert.equals(1, discoGets); Assert.notNull(submitted); Assert.equals("Design Team", submittedField(submitted, "muc#roomconfig_roomname")); Assert.equals(Open, channel.uiState);