diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/request/ApiSyncResponse.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/request/ApiSyncResponse.kt index 39b8a90b..b4f417c9 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/request/ApiSyncResponse.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/request/ApiSyncResponse.kt @@ -53,7 +53,7 @@ internal data class ApiInviteEvents( @Serializable internal data class ApiSyncRoom( @SerialName("timeline") val timeline: ApiSyncRoomTimeline, - @SerialName("state") val state: ApiSyncRoomState, + @SerialName("state") val state: ApiSyncRoomState? = null, @SerialName("account_data") val accountData: ApiAccountData? = null, @SerialName("ephemeral") val ephemeral: ApiEphemeral? = null, @SerialName("summary") val summary: ApiRoomSummary? = null, diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomOverviewProcessor.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomOverviewProcessor.kt index f4a9149f..0218d812 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomOverviewProcessor.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomOverviewProcessor.kt @@ -13,7 +13,7 @@ internal class RoomOverviewProcessor( ) { suspend fun process(roomToProcess: RoomToProcess, previousState: RoomOverview?, lastMessage: LastMessage?): RoomOverview? { - val combinedEvents = roomToProcess.apiSyncRoom.state.stateEvents + roomToProcess.apiSyncRoom.timeline.apiTimelineEvents + val combinedEvents = (roomToProcess.apiSyncRoom.state?.stateEvents.orEmpty()) + roomToProcess.apiSyncRoom.timeline.apiTimelineEvents val isEncrypted = combinedEvents.any { it is ApiTimelineEvent.Encryption } val readMarker = roomToProcess.apiSyncRoom.accountData?.events?.filterIsInstance()?.firstOrNull()?.content?.eventId return when (previousState) { diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomProcessor.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomProcessor.kt index eca9c77c..96916864 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomProcessor.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomProcessor.kt @@ -50,7 +50,7 @@ internal class RoomProcessor( } private fun ApiSyncRoom.collectMembers(userCredentials: UserCredentials): List { - return (this.state.stateEvents + this.timeline.apiTimelineEvents) + return (this.state?.stateEvents.orEmpty() + this.timeline.apiTimelineEvents) .filterIsInstance() .mapNotNull { when { diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/SyncReducer.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/SyncReducer.kt index 9bba3387..a606895c 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/SyncReducer.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/SyncReducer.kt @@ -70,7 +70,7 @@ internal class SyncReducer( } private fun findRoomsLeft(response: ApiSyncResponse, userCredentials: UserCredentials) = response.rooms?.leave?.filter { - it.value.state.stateEvents.filterIsInstance().any { + it.value.state?.stateEvents.orEmpty().filterIsInstance().any { it.content.membership.isLeave() && it.senderId == userCredentials.userId } }?.map { it.key } ?: emptyList() @@ -91,7 +91,7 @@ internal class SyncReducer( } private fun Map.keepRoomsWithChanges() = this.filter { - it.value.state.stateEvents.isNotEmpty() || + it.value.state?.stateEvents.orEmpty().isNotEmpty() || it.value.timeline.apiTimelineEvents.isNotEmpty() || it.value.accountData?.events?.isNotEmpty() == true || it.value.ephemeral?.events?.isNotEmpty() == true