avoiding dispatching invitation accepted events

- we only want to notify users when they receive an invititation, not when they've accepted it
This commit is contained in:
Adam Brown 2021-10-08 16:56:50 +01:00
parent 109a5a6664
commit e95d49a3ae

View file

@ -17,7 +17,11 @@
package org.matrix.android.sdk.internal.session.notification package org.matrix.android.sdk.internal.session.notification
import org.matrix.android.sdk.api.pushrules.rest.PushRule import org.matrix.android.sdk.api.pushrules.rest.PushRule
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
import org.matrix.android.sdk.api.session.sync.model.RoomsSyncResponse import org.matrix.android.sdk.api.session.sync.model.RoomsSyncResponse
import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.task.Task import org.matrix.android.sdk.internal.task.Task
@ -51,11 +55,14 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
value.timeline?.events?.map { it.copy(roomId = key) } value.timeline?.events?.map { it.copy(roomId = key) }
} }
.flatten() .flatten()
.filterNot { it.isInvitationJoined() }
val inviteEvents = params.syncResponse.invite val inviteEvents = params.syncResponse.invite
.mapNotNull { (key, value) -> .mapNotNull { (key, value) ->
value.inviteState?.events?.map { it.copy(roomId = key) } value.inviteState?.events?.map { it.copy(roomId = key) }
} }
.flatten() .flatten()
val allEvents = (newJoinEvents + inviteEvents).filter { event -> val allEvents = (newJoinEvents + inviteEvents).filter { event ->
when (event.type) { when (event.type) {
EventType.MESSAGE, EventType.MESSAGE,
@ -93,3 +100,6 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
defaultPushRuleService.dispatchFinish() defaultPushRuleService.dispatchFinish()
} }
} }
private fun Event.isInvitationJoined(): Boolean = type == EventType.STATE_ROOM_MEMBER &&
content?.toModel<RoomMemberContent>()?.membership == Membership.INVITE