Stop voice message on redaction (#1826)
As per product spec: Voice messages must stop playing when redacted.
This commit is contained in:
parent
af8f5b805c
commit
2e62671cda
6 changed files with 222 additions and 2 deletions
|
|
@ -32,6 +32,7 @@ import im.vector.app.features.analytics.plan.PollVote
|
|||
import io.element.android.features.messages.impl.timeline.factories.TimelineItemsFactory
|
||||
import io.element.android.features.messages.impl.timeline.model.TimelineItem
|
||||
import io.element.android.features.messages.impl.timeline.session.SessionState
|
||||
import io.element.android.features.messages.impl.voicemessages.timeline.RedactedVoiceMessageManager
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
|
|
@ -63,6 +64,7 @@ class TimelinePresenter @Inject constructor(
|
|||
private val analyticsService: AnalyticsService,
|
||||
private val verificationService: SessionVerificationService,
|
||||
private val encryptionService: EncryptionService,
|
||||
private val redactedVoiceMessageManager: RedactedVoiceMessageManager,
|
||||
) : Presenter<TimelineState> {
|
||||
|
||||
private val timeline = room.timeline
|
||||
|
|
@ -142,6 +144,7 @@ class TimelinePresenter @Inject constructor(
|
|||
paginateBackwards()
|
||||
}
|
||||
}
|
||||
.onEach(redactedVoiceMessageManager::onEachMatrixTimelineItem)
|
||||
.launchIn(this)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.features.messages.impl.voicemessages.timeline
|
||||
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.RedactedContent
|
||||
import io.element.android.libraries.mediaplayer.api.MediaPlayer
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
interface RedactedVoiceMessageManager {
|
||||
suspend fun onEachMatrixTimelineItem(timelineItems: List<MatrixTimelineItem>)
|
||||
}
|
||||
|
||||
@ContributesBinding(RoomScope::class)
|
||||
class DefaultRedactedVoiceMessageManager @Inject constructor(
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
private val mediaPlayer: MediaPlayer,
|
||||
) : RedactedVoiceMessageManager {
|
||||
override suspend fun onEachMatrixTimelineItem(timelineItems: List<MatrixTimelineItem>) {
|
||||
withContext(dispatchers.computation) {
|
||||
mediaPlayer.state.value.let { playerState ->
|
||||
if (playerState.isPlaying && playerState.mediaId != null) {
|
||||
val needsToPausePlayer = timelineItems.any {
|
||||
it is MatrixTimelineItem.Event &&
|
||||
playerState.mediaId == it.eventId?.value &&
|
||||
it.event.content is RedactedContent
|
||||
}
|
||||
if (needsToPausePlayer) {
|
||||
withContext(dispatchers.main) { mediaPlayer.pause() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue