From f778a0502c13d48991b1f2d7a54e5c56c1c0a678 Mon Sep 17 00:00:00 2001 From: Infi Date: Tue, 6 Jun 2023 00:36:43 +0200 Subject: [PATCH] feat: read only server ordering Signed-off-by: Infi --- .../revolt/screens/chat/ChatRouterScreen.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/chat/revolt/screens/chat/ChatRouterScreen.kt b/app/src/main/java/chat/revolt/screens/chat/ChatRouterScreen.kt index ae4e2bf0..c1cb48d2 100644 --- a/app/src/main/java/chat/revolt/screens/chat/ChatRouterScreen.kt +++ b/app/src/main/java/chat/revolt/screens/chat/ChatRouterScreen.kt @@ -53,6 +53,7 @@ import chat.revolt.R import chat.revolt.api.RevoltAPI import chat.revolt.api.realtime.DisconnectionState import chat.revolt.api.realtime.RealtimeSocket +import chat.revolt.api.settings.SyncedSettings import chat.revolt.components.chat.DisconnectedNotice import chat.revolt.components.generic.UserAvatar import chat.revolt.components.generic.presenceFromStatus @@ -349,8 +350,22 @@ fun ChatRouterScreen(topNav: NavController, viewModel: ChatRouterViewModel = hil ServerDrawerSeparator() - RevoltAPI.serverCache.values - .sortedBy { it.id } + // This seems to confuse the formatter, here's what it does: + // - Take the list of servers and filter them by the ones that are in the ordering. + // - Sort the servers that are in the ordering using the ordering. + // - Add the servers that aren't in the ordering to the end of the list. + // - Sort the servers that aren't in the ordering by their ID (creation order). + ((RevoltAPI.serverCache.values.filter { + SyncedSettings.ordering.servers.contains( + it.id + ) + } + .sortedBy { SyncedSettings.ordering.servers.indexOf(it.id) }) + (RevoltAPI.serverCache.values.filter { + !SyncedSettings.ordering.servers.contains( + it.id + ) + }.sortedBy { it.id } + )) .forEach { server -> if (server.id == null || server.name == null) return@forEach