diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift index 6f7d4345d..f0b679814 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift @@ -119,6 +119,34 @@ extension RoomSummary: CustomStringConvertible { } extension RoomSummary { + /// An empty summary used when the room info is momentarily unavailable (e.g. while the client tears + /// down on logout). Keeps the diff indices aligned with the SDK instead of crashing. + static func placeholder(room: Room) -> RoomSummary { + RoomSummary(room: room, + id: room.id(), + joinRequestType: nil, + name: room.id(), + isDirect: false, + isSpace: false, + avatarURL: nil, + heroes: [], + activeMembersCount: 0, + lastMessage: nil, + lastMessageDate: nil, + lastMessageState: nil, + unreadMessagesCount: 0, + unreadMentionsCount: 0, + unreadNotificationsCount: 0, + notificationMode: nil, + canonicalAlias: nil, + alternativeAliases: [], + hasOngoingCall: false, + activeCallIntent: nil, + isMarkedUnread: false, + isFavourite: false, + isTombstoned: false) + } + init(room: Room, id: String, settingsMode: RoomNotificationModeProxy, hasUnreadMessages: Bool, hasUnreadMentions: Bool, hasUnreadNotifications: Bool) { self.room = room self.id = id diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 13b85a7bc..2e5c3bbc9 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -281,7 +281,11 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { let roomDetails = await fetchRoomDetails(from: room) guard let roomInfo = roomDetails.roomInfo else { - fatalError("Missing room info for \(room.id())") + // The room info can be momentarily unavailable while the client tears down (e.g. on logout), + // where the SDK still delivers a diff but `room.roomInfo()` throws. Return a placeholder to + // keep the diff indices aligned with the SDK instead of crashing. + MXLog.error("Missing room info for \(room.id())") + return .placeholder(room: room) } var attributedLastMessage: AttributedString?