Fixes #1102 - Crashes when opening the invites screen

This commit is contained in:
Stefan Ceriu
2023-06-20 16:44:44 +03:00
committed by Stefan Ceriu
parent 8052441bd7
commit 2bee5ab95d
4 changed files with 11 additions and 6 deletions

View File

@@ -19,7 +19,7 @@ enum InvitesScreenViewModelAction {
}
struct InvitesScreenViewState: BindableState {
var invites: [InvitesScreenRoomDetails]?
var invites: [InvitesScreenRoomDetails] = []
var bindings: InvitesScreenViewStateBindings = .init()
}
@@ -27,7 +27,7 @@ struct InvitesScreenViewStateBindings {
var alertInfo: AlertInfo<Bool>?
}
struct InvitesScreenRoomDetails {
struct InvitesScreenRoomDetails: Identifiable {
let roomDetails: RoomSummaryDetails
var inviter: RoomMemberProxyProtocol?
var isUnread: Bool
@@ -35,6 +35,10 @@ struct InvitesScreenRoomDetails {
var isDirect: Bool {
roomDetails.isDirect
}
var id: String {
roomDetails.id
}
}
enum InvitesScreenViewAction {

View File

@@ -95,11 +95,11 @@ class InvitesScreenViewModel: InvitesScreenViewModelType, InvitesScreenViewModel
let inviter: RoomMemberProxyProtocol? = await room.inviter()
guard let inviter, let inviteIndex = state.invites?.firstIndex(where: { $0.roomDetails.id == roomID }) else {
guard let inviter, let inviteIndex = state.invites.firstIndex(where: { $0.roomDetails.id == roomID }) else {
return
}
state.invites?[inviteIndex].inviter = inviter
state.invites[inviteIndex].inviter = inviter
}
}

View File

@@ -21,9 +21,9 @@ struct InvitesScreen: View {
var body: some View {
ScrollView {
if let rooms = context.viewState.invites, !rooms.isEmpty {
if !context.viewState.invites.isEmpty {
LazyVStack(spacing: 0) {
ForEach(rooms, id: \.roomDetails.id) { invite in
ForEach(context.viewState.invites) { invite in
InvitesScreenCell(invite: invite,
imageProvider: context.imageProvider,
acceptAction: { context.send(viewAction: .accept(invite)) },

1
changelog.d/1102.bugfix Normal file
View File

@@ -0,0 +1 @@
Fixed crashes when opening the invites screen