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([]) } .catch { _ in Just([]) }
.sink { [weak self] rosters in .sink { [weak self] rosters in
self?.actualRosters = rosters 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 // Contacts list
contactsList
}
}
}
@ViewBuilder private var contactsList: some View {
if !clientsStore.actualRosters.isEmpty { if !clientsStore.actualRosters.isEmpty {
List { List {
ForEach(clientsStore.actualRosters) { roster in ForEach(elements.indices, id: \.self) { index in
let element = elements[index]
if let roster = element as? Roster {
ContactsScreenRow( ContactsScreenRow(
roster: roster roster: roster
) )
} else if let bareJid = element as? String {
SharedSectionTitle(text: bareJid)
}
} }
} }
.listStyle(.plain) .listStyle(.plain)
@ -40,6 +51,21 @@ struct ContactsScreen: View {
Spacer() 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
} }
} }
} }