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,20 +26,46 @@ struct ContactsScreen: View {
) )
// Contacts list // Contacts list
if !clientsStore.actualRosters.isEmpty { contactsList
List { }
ForEach(clientsStore.actualRosters) { roster in }
ContactsScreenRow( }
roster: roster
) @ViewBuilder private var contactsList: some View {
} if !clientsStore.actualRosters.isEmpty {
List {
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)
.background(Color.Material.Background.light)
} else {
Spacer()
} }
} }
.listStyle(.plain)
.background(Color.Material.Background.light)
} else {
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
} }
} }
} }