Skip to content

Commit 1b192ea

Browse files
authored
Merge pull request #7945 from vector-im/feature/fre/vb_notification_on_first_chunk
Voice Broadcast - only send a notification on the first chunk
2 parents f3e56cf + 72e0dc4 commit 1b192ea

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

changelog.d/7845.wip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Voice Broadcast] Only display a notification on the first voice chunk

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,7 @@
22952295
<string name="sent_verification_conclusion">Verification Conclusion</string>
22962296
<string name="sent_location">Shared their location</string>
22972297
<string name="sent_live_location">Shared their live location</string>
2298+
<string name="started_a_voice_broadcast">Started a voice broadcast</string>
22982299

22992300
<string name="verification_request_waiting">Waiting…</string>
23002301
<string name="verification_request_other_cancelled">%s canceled</string>

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import im.vector.app.core.resources.StringProvider
2727
import im.vector.app.features.html.EventHtmlRenderer
2828
import im.vector.app.features.voicebroadcast.VoiceBroadcastConstants
2929
import im.vector.app.features.voicebroadcast.isLive
30+
import im.vector.app.features.voicebroadcast.isVoiceBroadcast
3031
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent
3132
import me.gujun.android.span.image
3233
import me.gujun.android.span.span
@@ -39,6 +40,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageContent
3940
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
4041
import org.matrix.android.sdk.api.session.room.model.message.MessageTextContent
4142
import org.matrix.android.sdk.api.session.room.model.message.MessageType
43+
import org.matrix.android.sdk.api.session.room.model.message.asMessageAudioEvent
4244
import org.matrix.android.sdk.api.session.room.model.relation.ReactionContent
4345
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
4446
import org.matrix.android.sdk.api.session.room.timeline.getTextDisplayableContent
@@ -86,10 +88,16 @@ class DisplayableEventFormatter @Inject constructor(
8688
simpleFormat(senderName, stringProvider.getString(R.string.sent_an_image), appendAuthor)
8789
}
8890
MessageType.MSGTYPE_AUDIO -> {
89-
if ((messageContent as? MessageAudioContent)?.voiceMessageIndicator != null) {
90-
simpleFormat(senderName, stringProvider.getString(R.string.sent_a_voice_message), appendAuthor)
91-
} else {
92-
simpleFormat(senderName, stringProvider.getString(R.string.sent_an_audio_file), appendAuthor)
91+
when {
92+
(messageContent as? MessageAudioContent)?.voiceMessageIndicator == null -> {
93+
simpleFormat(senderName, stringProvider.getString(R.string.sent_an_audio_file), appendAuthor)
94+
}
95+
timelineEvent.root.asMessageAudioEvent().isVoiceBroadcast() -> {
96+
simpleFormat(senderName, stringProvider.getString(R.string.started_a_voice_broadcast), appendAuthor)
97+
}
98+
else -> {
99+
simpleFormat(senderName, stringProvider.getString(R.string.sent_a_voice_message), appendAuthor)
100+
}
93101
}
94102
}
95103
MessageType.MSGTYPE_VIDEO -> {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2023 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package im.vector.app.features.notifications
17+
18+
import im.vector.app.ActiveSessionDataSource
19+
import im.vector.app.features.voicebroadcast.isVoiceBroadcast
20+
import im.vector.app.features.voicebroadcast.sequence
21+
import org.matrix.android.sdk.api.session.events.model.isVoiceMessage
22+
import org.matrix.android.sdk.api.session.getRoom
23+
import org.matrix.android.sdk.api.session.room.getTimelineEvent
24+
import org.matrix.android.sdk.api.session.room.model.message.asMessageAudioEvent
25+
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
26+
import javax.inject.Inject
27+
28+
class FilteredEventDetector @Inject constructor(
29+
private val activeSessionDataSource: ActiveSessionDataSource
30+
) {
31+
32+
/**
33+
* Returns true if the given event should be ignored.
34+
* Used to skip notifications if a non expected message is received.
35+
*/
36+
fun shouldBeIgnored(notifiableEvent: NotifiableEvent): Boolean {
37+
val session = activeSessionDataSource.currentValue?.orNull() ?: return false
38+
39+
if (notifiableEvent is NotifiableMessageEvent) {
40+
val room = session.getRoom(notifiableEvent.roomId) ?: return false
41+
val timelineEvent = room.getTimelineEvent(notifiableEvent.eventId) ?: return false
42+
return timelineEvent.shouldBeIgnored()
43+
}
44+
return false
45+
}
46+
47+
/**
48+
* Whether the timeline event should be ignored.
49+
*/
50+
private fun TimelineEvent.shouldBeIgnored(): Boolean {
51+
if (root.isVoiceMessage()) {
52+
val audioEvent = root.asMessageAudioEvent()
53+
// if the event is a voice message related to a voice broadcast, only show the event on the first chunk.
54+
return audioEvent.isVoiceBroadcast() && audioEvent?.sequence != 1
55+
}
56+
57+
return false
58+
}
59+
}

vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class NotificationDrawerManager @Inject constructor(
4747
private val notifiableEventProcessor: NotifiableEventProcessor,
4848
private val notificationRenderer: NotificationRenderer,
4949
private val notificationEventPersistence: NotificationEventPersistence,
50+
private val filteredEventDetector: FilteredEventDetector,
5051
private val buildMeta: BuildMeta,
5152
) {
5253

@@ -100,6 +101,11 @@ class NotificationDrawerManager @Inject constructor(
100101
Timber.d("onNotifiableEventReceived(): is push: ${notifiableEvent.canBeReplaced}")
101102
}
102103

104+
if (filteredEventDetector.shouldBeIgnored(notifiableEvent)) {
105+
Timber.d("onNotifiableEventReceived(): ignore the event")
106+
return
107+
}
108+
103109
add(notifiableEvent)
104110
}
105111

0 commit comments

Comments
 (0)