| author | Eric Roberts
<eric@devl.me> 2026-09-09 17:24:22 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2026-09-09 17:44:41 UTC |
| parent | 8a6a4f41ef1cf0a6f190affe8b666a0802668c3c |
| borogove/Client.hx | +16 | -19 |
| test/TestClient.hx | +15 | -0 |
diff --git a/borogove/Client.hx b/borogove/Client.hx index b8b14e2..4eb44d3 100644 --- a/borogove/Client.hx +++ b/borogove/Client.hx @@ -1090,12 +1090,9 @@ class Client extends EventEmitter { if (firstSync) { // We resumed from disk so these must have been synced before // and will get anything since live - for (chat in getChats()) { - final channel = Std.downcast(chat, Channel); - if (channel != null) { - channel.inSync = channel.self != null; - if (!channel.inSync) channel.join(); - } + for (channel in getChannels()) { + channel.inSync = channel.self != null; + if (!channel.inSync) channel.join(); } } @@ -1372,6 +1369,10 @@ class Client extends EventEmitter { return chats.filter((chat) -> chat.uiState != Closed); } + private function getChannels():Array<Channel> { + return getChats().map(c -> Std.downcast(c, Channel)).filter(c -> c != null); + } + /** Search for chats the user can start or join @@ -2456,24 +2457,20 @@ class Client extends EventEmitter { } private function pingAllChannels(refresh: Bool) { - for (chat in getChats()) { - final channel = Std.downcast(chat, Channel); - channel?.selfPing(refresh || channel?.disco == null); + for (channel in getChannels()) { + channel.selfPing(refresh || channel.disco == null); } } private function joinAllChannels() { - for (chat in getChats()) { - final channel = Std.downcast(chat, Channel); - if (channel != null) { - if (channel.disco.identities.length < 1) { - channel.refreshDisco(() -> { - channel.join(true); - }); - } else { + for (channel in getChannels()) { + if (channel.disco.identities.length < 1) { + channel.refreshDisco(() -> { channel.join(true); - haxe.Timer.delay(() -> channel.refreshDisco(), 30000); - } + }); + } else { + channel.join(true); + haxe.Timer.delay(() -> channel.refreshDisco(), 30000); } } } diff --git a/test/TestClient.hx b/test/TestClient.hx index c02ca3b..13e575f 100644 --- a/test/TestClient.hx +++ b/test/TestClient.hx @@ -492,6 +492,21 @@ class TestClient extends utest.Test { client.start(); } + public function testGetChannelsReturnsOnlyChannels() { + final persistence = new Dummy(); + final client = new Client("test@example.com", persistence); + client.getDirectChat("direct1@example.com"); + client.getDirectChat("direct2@example.com"); + client.chats.push(new borogove.Chat.Channel(client, client.stream, persistence, "room1@example.com")); + client.chats.push(new borogove.Chat.Channel(client, client.stream, persistence, "room2@example.com")); + + final channels = client.getChannels(); + Assert.equals(2, channels.length); + Assert.isTrue(Std.isOfType(channels[0], borogove.Chat.Channel)); + Assert.isTrue(Std.isOfType(channels[1], borogove.Chat.Channel)); + Assert.same(["room1@example.com", "room2@example.com"], channels.map(channel -> channel.chatId)); + } + public function testUsePassword(async: Async) { final persistence = new Dummy(); final client = new Client("test@example.com", persistence);