Separated encrypted from non-encrypted rooms. Moved DMs to the bottom.

This commit is contained in:
Stefan Ceriu
2022-03-10 16:40:16 +02:00
parent d0f88356d2
commit fc8e92eef1
2 changed files with 20 additions and 16 deletions
@@ -37,20 +37,24 @@ struct HomeScreenViewState: BindableState {
var rooms: [HomeScreenRoom] = []
var isLoadingRooms: Bool = false
var firstDirectRooms: [HomeScreenRoom] {
Array(rooms.filter { $0.isDirect }.prefix(5))
var sortedRooms: [HomeScreenRoom] {
rooms.sorted(by: { ($0.displayName ?? $0.id).lowercased() < ($1.displayName ?? $1.id).lowercased() })
}
var otherDirectRooms: [HomeScreenRoom] {
Array(rooms.filter { $0.isDirect }.dropFirst(5))
var unencryptedDMs: [HomeScreenRoom] {
Array(sortedRooms.filter { $0.isDirect && !$0.isEncrypted })
}
var firstNondirectRooms: [HomeScreenRoom] {
Array(rooms.filter { !$0.isDirect }.prefix(5))
var encryptedDMs: [HomeScreenRoom] {
Array(sortedRooms.filter { $0.isDirect && $0.isEncrypted})
}
var otherNondirectRooms: [HomeScreenRoom] {
Array(rooms.filter { !$0.isDirect }.dropFirst(5))
var unencryptedRooms: [HomeScreenRoom] {
Array(sortedRooms.filter { !$0.isDirect && !$0.isEncrypted })
}
var encryptedRooms: [HomeScreenRoom] {
Array(sortedRooms.filter { !$0.isDirect && $0.isEncrypted })
}
}
@@ -33,15 +33,15 @@ struct HomeScreen: View {
}
} else {
List {
Section("People") {
ForEach(context.viewState.firstDirectRooms) { room in
Section("Rooms") {
ForEach(context.viewState.unencryptedRooms) { room in
RoomCell(room: room, context: context)
}
let other = context.viewState.otherDirectRooms
let other = context.viewState.encryptedRooms
if other.count > 0 {
DisclosureGroup("See more") {
DisclosureGroup("Encrypted") {
ForEach(other) { room in
RoomCell(room: room, context: context)
}
@@ -49,15 +49,15 @@ struct HomeScreen: View {
}
}
Section("Rooms") {
ForEach(context.viewState.firstNondirectRooms) { room in
Section("People") {
ForEach(context.viewState.unencryptedDMs) { room in
RoomCell(room: room, context: context)
}
let other = context.viewState.otherNondirectRooms
let other = context.viewState.encryptedDMs
if other.count > 0 {
DisclosureGroup("See more") {
DisclosureGroup("Encrypted") {
ForEach(other) { room in
RoomCell(room: room, context: context)
}