Skip to content

Commit 0971a28

Browse files
authored
Merge pull request #8057 from vector-im/yostyle/vb_utd
Let the user know when we are not able to decrypt the voice broadcast…
2 parents 5b5cbf5 + 8775c4d commit 0971a28

File tree

14 files changed

+119
-26
lines changed

14 files changed

+119
-26
lines changed

changelog.d/7820.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Let the user know when we are not able to decrypt the voice broadcast chunks

library/ui-strings/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,6 +3120,7 @@
31203120
<string name="error_voice_broadcast_already_in_progress_message">You are already recording a voice broadcast. Please end your current voice broadcast to start a new one.</string>
31213121
<string name="error_voice_broadcast_unable_to_play">Unable to play this voice broadcast.</string>
31223122
<string name="error_voice_broadcast_no_connection_recording">Connection error - Recording paused</string>
3123+
<string name="error_voice_broadcast_unable_to_decrypt">Unable to decrypt this voice broadcast.</string>
31233124
<!-- Examples of usage: 6h 15min 30sec left / 15min 30sec left / 30sec left -->
31243125
<string name="voice_broadcast_recording_time_left">%1$s left</string>
31253126
<string name="stop_voice_broadcast_dialog_title">Stop live broadcasting?</string>

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/EventService.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ interface EventService {
2828
roomId: String,
2929
eventId: String
3030
): Event
31+
32+
/**
33+
* Get an Event from cache. Return null if not found.
34+
*/
35+
fun getEventFromCache(
36+
roomId: String,
37+
eventId: String
38+
): Event?
3139
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/EventEntityQueries.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ internal fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQu
4747
.equalTo(EventEntityFields.EVENT_ID, eventId)
4848
}
4949

50+
internal fun EventEntity.Companion.where(realm: Realm, roomId: String, eventId: String): RealmQuery<EventEntity> {
51+
return realm.where<EventEntity>()
52+
.equalTo(EventEntityFields.ROOM_ID, roomId)
53+
.equalTo(EventEntityFields.EVENT_ID, eventId)
54+
}
55+
5056
internal fun EventEntity.Companion.whereRoomId(realm: Realm, roomId: String): RealmQuery<EventEntity> {
5157
return realm.where<EventEntity>()
5258
.equalTo(EventEntityFields.ROOM_ID, roomId)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ package org.matrix.android.sdk.internal.session.events
1818

1919
import org.matrix.android.sdk.api.session.events.EventService
2020
import org.matrix.android.sdk.api.session.events.model.Event
21+
import org.matrix.android.sdk.internal.database.RealmSessionProvider
22+
import org.matrix.android.sdk.internal.database.mapper.asDomain
23+
import org.matrix.android.sdk.internal.database.model.EventEntity
24+
import org.matrix.android.sdk.internal.database.query.where
2125
import org.matrix.android.sdk.internal.session.call.CallEventProcessor
2226
import org.matrix.android.sdk.internal.session.room.timeline.GetEventTask
2327
import javax.inject.Inject
2428

2529
internal class DefaultEventService @Inject constructor(
2630
private val getEventTask: GetEventTask,
27-
private val callEventProcessor: CallEventProcessor
31+
private val callEventProcessor: CallEventProcessor,
32+
private val realmSessionProvider: RealmSessionProvider,
2833
) : EventService {
2934

3035
override suspend fun getEvent(roomId: String, eventId: String): Event {
@@ -36,4 +41,16 @@ internal class DefaultEventService @Inject constructor(
3641

3742
return event
3843
}
44+
45+
override fun getEventFromCache(roomId: String, eventId: String): Event? {
46+
return realmSessionProvider.withRealm { realm ->
47+
EventEntity.where(
48+
realm = realm,
49+
roomId = roomId,
50+
eventId = eventId
51+
)
52+
.findFirst()
53+
?.asDomain()
54+
}
55+
}
3956
}

vector/src/main/java/im/vector/app/core/error/ErrorFormatter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ class DefaultErrorFormatter @Inject constructor(
160160
RecordingError.BlockedBySomeoneElse -> stringProvider.getString(R.string.error_voice_broadcast_blocked_by_someone_else_message)
161161
RecordingError.NoPermission -> stringProvider.getString(R.string.error_voice_broadcast_permission_denied_message)
162162
RecordingError.UserAlreadyBroadcasting -> stringProvider.getString(R.string.error_voice_broadcast_already_in_progress_message)
163-
is VoiceBroadcastFailure.ListeningError -> stringProvider.getString(R.string.error_voice_broadcast_unable_to_play)
163+
is VoiceBroadcastFailure.ListeningError.UnableToPlay,
164+
is VoiceBroadcastFailure.ListeningError.PrepareMediaPlayerError -> stringProvider.getString(R.string.error_voice_broadcast_unable_to_play)
165+
is VoiceBroadcastFailure.ListeningError.UnableToDecrypt -> stringProvider.getString(R.string.error_voice_broadcast_unable_to_decrypt)
164166
}
165167
}
166168

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ import im.vector.app.core.epoxy.VectorEpoxyModel
2222
import im.vector.app.features.analytics.DecryptionFailureTracker
2323
import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventVisibilityHelper
2424
import im.vector.app.features.voicebroadcast.VoiceBroadcastConstants
25+
import im.vector.app.features.voicebroadcast.model.isVoiceBroadcast
26+
import org.matrix.android.sdk.api.session.Session
2527
import org.matrix.android.sdk.api.session.events.model.EventType
28+
import org.matrix.android.sdk.api.session.events.model.RelationType
2629
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
30+
import org.matrix.android.sdk.api.session.room.timeline.getRelationContent
2731
import timber.log.Timber
2832
import javax.inject.Inject
2933

@@ -39,6 +43,7 @@ class TimelineItemFactory @Inject constructor(
3943
private val callItemFactory: CallItemFactory,
4044
private val decryptionFailureTracker: DecryptionFailureTracker,
4145
private val timelineEventVisibilityHelper: TimelineEventVisibilityHelper,
46+
private val session: Session,
4247
) {
4348

4449
/**
@@ -130,11 +135,16 @@ class TimelineItemFactory @Inject constructor(
130135
EventType.CALL_ANSWER -> callItemFactory.create(params)
131136
// Crypto
132137
EventType.ENCRYPTED -> {
133-
if (event.root.isRedacted()) {
138+
val relationContent = event.getRelationContent()
139+
when {
134140
// Redacted event, let the MessageItemFactory handle it
135-
messageItemFactory.create(params)
136-
} else {
137-
encryptedItemFactory.create(params)
141+
event.root.isRedacted() -> messageItemFactory.create(params)
142+
relationContent?.type == RelationType.REFERENCE -> {
143+
// Hide the decryption error for VoiceBroadcast chunks
144+
val relatedEvent = relationContent.eventId?.let { session.eventService().getEventFromCache(event.roomId, it) }
145+
if (relatedEvent?.isVoiceBroadcast() != true) encryptedItemFactory.create(params) else null
146+
}
147+
else -> encryptedItemFactory.create(params)
138148
}
139149
}
140150
EventType.KEY_VERIFICATION_CANCEL,

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VoiceBroadcastItemFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class VoiceBroadcastItemFactory @Inject constructor(
7575
voiceBroadcast = voiceBroadcast,
7676
voiceBroadcastState = voiceBroadcastContent.voiceBroadcastState,
7777
duration = voiceBroadcastEventsGroup.getDuration(),
78+
hasUnableToDecryptEvent = voiceBroadcastEventsGroup.hasUnableToDecryptEvent(),
7879
recorderName = params.event.senderInfo.disambiguatedDisplayName,
7980
recorder = voiceBroadcastRecorder,
8081
player = voiceBroadcastPlayer,

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineEventsGroups.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState
2525
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent
2626
import org.matrix.android.sdk.api.extensions.orFalse
2727
import org.matrix.android.sdk.api.session.events.model.EventType
28+
import org.matrix.android.sdk.api.session.events.model.RelationType
29+
import org.matrix.android.sdk.api.session.events.model.getRelationContent
2830
import org.matrix.android.sdk.api.session.events.model.toModel
2931
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
3032
import org.matrix.android.sdk.api.session.room.model.message.asMessageAudioEvent
@@ -61,6 +63,7 @@ class TimelineEventsGroups {
6163
private fun TimelineEvent.getGroupIdOrNull(): String? {
6264
val type = root.getClearType()
6365
val content = root.getClearContent()
66+
val relationContent = root.getRelationContent()
6467
return when {
6568
EventType.isCallEvent(type) -> (content?.get("call_id") as? String)
6669
type == VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO -> root.asVoiceBroadcastEvent()?.reference?.eventId
@@ -69,6 +72,9 @@ class TimelineEventsGroups {
6972
// Group voice messages with a reference to an eventId
7073
root.asMessageAudioEvent()?.getVoiceBroadcastEventId()
7174
}
75+
type == EventType.ENCRYPTED && relationContent?.type == RelationType.REFERENCE -> {
76+
relationContent.eventId
77+
}
7278
else -> {
7379
null
7480
}
@@ -153,4 +159,8 @@ class VoiceBroadcastEventsGroup(private val group: TimelineEventsGroup) {
153159
fun getDuration(): Int {
154160
return group.events.mapNotNull { it.root.asMessageAudioEvent()?.duration }.sum()
155161
}
162+
163+
fun hasUnableToDecryptEvent(): Boolean {
164+
return group.events.any { it.root.getClearType() == EventType.ENCRYPTED }
165+
}
156166
}

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageVoiceBroadcastItem.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ abstract class AbsMessageVoiceBroadcastItem<H : AbsMessageVoiceBroadcastItem.Hol
4545
protected val player get() = voiceBroadcastAttributes.player
4646
protected val playbackTracker get() = voiceBroadcastAttributes.playbackTracker
4747
protected val duration get() = voiceBroadcastAttributes.duration
48+
protected val hasUnableToDecryptEvent get() = voiceBroadcastAttributes.hasUnableToDecryptEvent
4849
protected val roomItem get() = voiceBroadcastAttributes.roomItem
4950
protected val colorProvider get() = voiceBroadcastAttributes.colorProvider
5051
protected val drawableProvider get() = voiceBroadcastAttributes.drawableProvider
@@ -102,6 +103,7 @@ abstract class AbsMessageVoiceBroadcastItem<H : AbsMessageVoiceBroadcastItem.Hol
102103
val voiceBroadcast: VoiceBroadcast,
103104
val voiceBroadcastState: VoiceBroadcastState?,
104105
val duration: Int,
106+
val hasUnableToDecryptEvent: Boolean,
105107
val recorderName: String,
106108
val recorder: VoiceBroadcastRecorder?,
107109
val player: VoiceBroadcastPlayer,

0 commit comments

Comments
 (0)