From f353f5e491b0f6f11adb58463bb45d9c98f6fbe2 Mon Sep 17 00:00:00 2001 From: fmodf Date: Mon, 21 Oct 2024 10:23:13 +0200 Subject: [PATCH] wip --- .../AppData/Store/ClientsStore.swift | 7 +++++ .../View/Main/ChatList/ChatsListScreen.swift | 26 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ConversationsClassic/AppData/Store/ClientsStore.swift b/ConversationsClassic/AppData/Store/ClientsStore.swift index 7fb1f80..17c22b8 100644 --- a/ConversationsClassic/AppData/Store/ClientsStore.swift +++ b/ConversationsClassic/AppData/Store/ClientsStore.swift @@ -239,6 +239,13 @@ private extension ClientsStore { .catch { _ in Just([]) } .sink { [weak self] chats in self?.actualChats = chats + .sorted { + if $0.account != $1.account { + return $0.account < $1.account + } else { + return $0.participant < $1.participant + } + } } } } diff --git a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift index 3679d5d..4984ec3 100644 --- a/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift +++ b/ConversationsClassic/View/Main/ChatList/ChatsListScreen.swift @@ -28,8 +28,13 @@ struct ChatsListScreen: View { // Chats list if !clientsStore.actualChats.isEmpty { List { - ForEach(clientsStore.actualChats) { chat in - ChatsRow(chat: chat) + ForEach(elements.indices, id: \.self) { index in + let element = elements[index] + if let chat = element as? Chat { + ChatsRow(chat: chat) + } else if let account = element as? String { + SharedSectionTitle(text: account) + } } } .listStyle(.plain) @@ -40,6 +45,23 @@ struct ChatsListScreen: View { } } } + + private var elements: [Any] { + if clientsStore.clients.filter({ $0.credentials.isActive }).count == 1 { + return clientsStore.actualChats + } else { + var result: [Any] = [] + for chat in clientsStore.actualChats { + if result.isEmpty { + result.append(chat.account) + } else if let last = result.last as? Chat, last.account != chat.account { + result.append(chat.account) + } + result.append(chat) + } + return result + } + } } private struct ChatsRow: View {