Merge pull request #219 from ouchadam/bug/dendrite-sync-error

Allow SyncResponse state events to be optional
This commit is contained in:
Adam Brown 2022-10-22 20:13:32 +01:00 committed by GitHub
commit 3517cf492a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 5 deletions

View File

@ -53,7 +53,7 @@ internal data class ApiInviteEvents(
@Serializable @Serializable
internal data class ApiSyncRoom( internal data class ApiSyncRoom(
@SerialName("timeline") val timeline: ApiSyncRoomTimeline, @SerialName("timeline") val timeline: ApiSyncRoomTimeline,
@SerialName("state") val state: ApiSyncRoomState, @SerialName("state") val state: ApiSyncRoomState? = null,
@SerialName("account_data") val accountData: ApiAccountData? = null, @SerialName("account_data") val accountData: ApiAccountData? = null,
@SerialName("ephemeral") val ephemeral: ApiEphemeral? = null, @SerialName("ephemeral") val ephemeral: ApiEphemeral? = null,
@SerialName("summary") val summary: ApiRoomSummary? = 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? { 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 isEncrypted = combinedEvents.any { it is ApiTimelineEvent.Encryption }
val readMarker = roomToProcess.apiSyncRoom.accountData?.events?.filterIsInstance<ApiAccountEvent.FullyRead>()?.firstOrNull()?.content?.eventId val readMarker = roomToProcess.apiSyncRoom.accountData?.events?.filterIsInstance<ApiAccountEvent.FullyRead>()?.firstOrNull()?.content?.eventId
return when (previousState) { return when (previousState) {

View File

@ -50,7 +50,7 @@ internal class RoomProcessor(
} }
private fun ApiSyncRoom.collectMembers(userCredentials: UserCredentials): List<RoomMember> { 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>() .filterIsInstance<ApiTimelineEvent.RoomMember>()
.mapNotNull { .mapNotNull {
when { when {

View File

@ -70,7 +70,7 @@ internal class SyncReducer(
} }
private fun findRoomsLeft(response: ApiSyncResponse, userCredentials: UserCredentials) = response.rooms?.leave?.filter { 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 it.content.membership.isLeave() && it.senderId == userCredentials.userId
} }
}?.map { it.key } ?: emptyList() }?.map { it.key } ?: emptyList()
@ -91,7 +91,7 @@ internal class SyncReducer(
} }
private fun Map<RoomId, ApiSyncRoom>.keepRoomsWithChanges() = this.filter { 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.timeline.apiTimelineEvents.isNotEmpty() ||
it.value.accountData?.events?.isNotEmpty() == true || it.value.accountData?.events?.isNotEmpty() == true ||
it.value.ephemeral?.events?.isNotEmpty() == true it.value.ephemeral?.events?.isNotEmpty() == true