wip
This commit is contained in:
parent
9315a89f65
commit
f353f5e491
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,13 @@ struct ChatsListScreen: View {
|
|||
// Chats list
|
||||
if !clientsStore.actualChats.isEmpty {
|
||||
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)
|
||||
} 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 {
|
||||
|
|
Loading…
Reference in a new issue