This commit is contained in:
fmodf 2024-10-20 20:45:53 +02:00
parent 9909611674
commit d6f08ca691
2 changed files with 44 additions and 11 deletions

View file

@ -211,6 +211,13 @@ private extension ClientsStore {
.catch { _ in Just([]) }
.sink { [weak self] rosters in
self?.actualRosters = rosters
.sorted {
if $0.bareJid != $1.bareJid {
return $0.bareJid < $1.bareJid
} else {
return $0.contactBareJid < $1.contactBareJid
}
}
}
}

View file

@ -26,12 +26,23 @@ struct ContactsScreen: View {
)
// Contacts list
contactsList
}
}
}
@ViewBuilder private var contactsList: some View {
if !clientsStore.actualRosters.isEmpty {
List {
ForEach(clientsStore.actualRosters) { roster in
ForEach(elements.indices, id: \.self) { index in
let element = elements[index]
if let roster = element as? Roster {
ContactsScreenRow(
roster: roster
)
} else if let bareJid = element as? String {
SharedSectionTitle(text: bareJid)
}
}
}
.listStyle(.plain)
@ -40,6 +51,21 @@ struct ContactsScreen: View {
Spacer()
}
}
private var elements: [Any] {
if clientsStore.clients.filter({ $0.credentials.isActive }).count == 1 {
return clientsStore.actualRosters
} else {
var result: [Any] = []
for roster in clientsStore.actualRosters {
if result.isEmpty {
result.append(roster.bareJid)
} else if let last = result.last as? Roster, last.bareJid != roster.bareJid {
result.append(roster.bareJid)
}
result.append(roster)
}
return result
}
}
}