allow state events to be missing/null

- dendrite can omit the state field from the sync response
This commit is contained in:
Adam Brown 2022-10-22 20:06:31 +01:00
parent f7f4c897d6
commit 1f3c62e9c3
4 changed files with 5 additions and 5 deletions

View File

@ -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,

View File

@ -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<ApiAccountEvent.FullyRead>()?.firstOrNull()?.content?.eventId
return when (previousState) {

View File

@ -50,7 +50,7 @@ internal class RoomProcessor(
}
private fun ApiSyncRoom.collectMembers(userCredentials: UserCredentials): List<RoomMember> {
return (this.state.stateEvents + this.timeline.apiTimelineEvents)
return (this.state?.stateEvents.orEmpty() + this.timeline.apiTimelineEvents)
.filterIsInstance<ApiTimelineEvent.RoomMember>()
.mapNotNull {
when {

View File

@ -70,7 +70,7 @@ internal class SyncReducer(
}
private fun findRoomsLeft(response: ApiSyncResponse, userCredentials: UserCredentials) = response.rooms?.leave?.filter {
it.value.state.stateEvents.filterIsInstance<ApiTimelineEvent.RoomMember>().any {
it.value.state?.stateEvents.orEmpty().filterIsInstance<ApiTimelineEvent.RoomMember>().any {
it.content.membership.isLeave() && it.senderId == userCredentials.userId
}
}?.map { it.key } ?: emptyList()
@ -91,7 +91,7 @@ internal class SyncReducer(
}
private fun Map<RoomId, ApiSyncRoom>.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