This commit is contained in:
fmodf 2024-10-21 10:23:13 +02:00
parent 9315a89f65
commit f353f5e491
2 changed files with 31 additions and 2 deletions

View file

@ -239,6 +239,13 @@ private extension ClientsStore {
.catch { _ in Just([]) } .catch { _ in Just([]) }
.sink { [weak self] chats in .sink { [weak self] chats in
self?.actualChats = chats self?.actualChats = chats
.sorted {
if $0.account != $1.account {
return $0.account < $1.account
} else {
return $0.participant < $1.participant
}
}
} }
} }
} }

View file

@ -28,8 +28,13 @@ struct ChatsListScreen: View {
// Chats list // Chats list
if !clientsStore.actualChats.isEmpty { if !clientsStore.actualChats.isEmpty {
List { List {
ForEach(clientsStore.actualChats) { chat in ForEach(elements.indices, id: \.self) { index in
let element = elements[index]
if let chat = element as? Chat {
ChatsRow(chat: chat) ChatsRow(chat: chat)
} else if let account = element as? String {
SharedSectionTitle(text: account)
}
} }
} }
.listStyle(.plain) .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 { private struct ChatsRow: View {