Merge pull request #219 from ouchadam/bug/dendrite-sync-error
Allow SyncResponse state events to be optional
This commit is contained in:
commit
3517cf492a
|
@ -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,
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue