Clear notification for a room left on another client

This commit is contained in:
Benoit Marty 2019-07-19 16:44:30 +02:00
parent 1a4ec34bb2
commit 6d01a570fd
5 changed files with 21 additions and 3 deletions

View File

@ -13,6 +13,7 @@ Other changes:
Bugfix: Bugfix:
- Edited message: link confusion when (edited) appears in body (#398) - Edited message: link confusion when (edited) appears in body (#398)
- Close detail room screen when the room is left with another client (#256) - Close detail room screen when the room is left with another client (#256)
- Clear notification for a room left on another client


Translations: Translations:
- -

View File

@ -41,6 +41,7 @@ interface PushRuleService {


interface PushRuleListener { interface PushRuleListener {
fun onMatchRule(event: Event, actions: List<Action>) fun onMatchRule(event: Event, actions: List<Action>)
fun onRoomLeft(roomId: String)
fun batchFinish() fun batchFinish()
} }
} }

View File

@ -20,12 +20,10 @@ import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.auth.data.SessionParams
import im.vector.matrix.android.api.pushrules.Action import im.vector.matrix.android.api.pushrules.Action
import im.vector.matrix.android.api.pushrules.PushRuleService import im.vector.matrix.android.api.pushrules.PushRuleService
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
import im.vector.matrix.android.api.pushrules.rest.PushRule import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.internal.database.mapper.PushRulesMapper import im.vector.matrix.android.internal.database.mapper.PushRulesMapper
import im.vector.matrix.android.internal.database.model.PushRulesEntity import im.vector.matrix.android.internal.database.model.PushRulesEntity
import im.vector.matrix.android.internal.database.model.PusherEntityFields
import im.vector.matrix.android.internal.database.query.where import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.session.pushers.GetPushRulesTask import im.vector.matrix.android.internal.session.pushers.GetPushRulesTask
@ -122,13 +120,23 @@ internal class DefaultPushRuleService @Inject constructor(
} }
} }


fun dispatchRoomLeft(roomid: String) {
try {
listeners.forEach {
it.onRoomLeft(roomid)
}
} catch (e: Throwable) {
Timber.e(e, "Error while dispatching room left")
}
}

fun dispatchFinish() { fun dispatchFinish() {
try { try {
listeners.forEach { listeners.forEach {
it.batchFinish() it.batchFinish()
} }
} catch (e: Throwable) { } catch (e: Throwable) {

Timber.e(e, "Error while dispatching finish")
} }
} }
} }

View File

@ -44,6 +44,10 @@ internal class DefaultProcessEventForPushTask @Inject constructor(


override suspend fun execute(params: ProcessEventForPushTask.Params): Try<Unit> { override suspend fun execute(params: ProcessEventForPushTask.Params): Try<Unit> {
return Try { return Try {
// Handle left rooms
params.syncResponse.leave.keys.forEach {
defaultPushRuleService.dispatchRoomLeft(it)
}
val newJoinEvents = params.syncResponse.join val newJoinEvents = params.syncResponse.join
.map { entries -> .map { entries ->
entries.value.timeline?.events?.map { it.copy(roomId = entries.key) } entries.value.timeline?.events?.map { it.copy(roomId = entries.key) }

View File

@ -56,6 +56,10 @@ class PushRuleTriggerListener @Inject constructor(
} }
} }


override fun onRoomLeft(roomId: String) {
notificationDrawerManager.clearMessageEventOfRoom(roomId)
}

override fun batchFinish() { override fun batchFinish() {
notificationDrawerManager.refreshNotificationDrawer() notificationDrawerManager.refreshNotificationDrawer()
} }