Add special notifications for mentions (#1846)
* Add special notifications for mentions --------- Co-authored-by: ElementBot <benoitm+elementbot@element.io>
This commit is contained in:
committed by
GitHub
parent
8ae8853c15
commit
4ca75a3bac
1
changelog.d/1451.feature
Normal file
1
changelog.d/1451.feature
Normal file
@@ -0,0 +1 @@
|
||||
Display different notifications for mentions.
|
||||
@@ -82,6 +82,11 @@ class NotifiableEventResolver @Inject constructor(
|
||||
return when (val content = this.content) {
|
||||
is NotificationContent.MessageLike.RoomMessage -> {
|
||||
val messageBody = descriptionFromMessageContent(content, senderDisplayName ?: content.senderId.value)
|
||||
val notificationBody = if (hasMention) {
|
||||
stringProvider.getString(R.string.notification_mentioned_you_body, messageBody)
|
||||
} else {
|
||||
messageBody
|
||||
}
|
||||
buildNotifiableMessageEvent(
|
||||
sessionId = userId,
|
||||
senderId = content.senderId,
|
||||
@@ -90,7 +95,7 @@ class NotifiableEventResolver @Inject constructor(
|
||||
noisy = isNoisy,
|
||||
timestamp = this.timestamp,
|
||||
senderName = senderDisplayName,
|
||||
body = messageBody,
|
||||
body = notificationBody,
|
||||
imageUriString = this.contentUrl,
|
||||
roomName = roomDisplayName,
|
||||
roomIsDirect = isDirect,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<string name="notification_invitation_action_join">"Vstoupit"</string>
|
||||
<string name="notification_invitation_action_reject">"Odmítnout"</string>
|
||||
<string name="notification_invite_body">"Vás pozval(a) do chatu"</string>
|
||||
<string name="notification_mentioned_you_body">"Zmínili vás: %1$s"</string>
|
||||
<string name="notification_new_messages">"Nové zprávy"</string>
|
||||
<string name="notification_reaction_body">"Reagoval(a) s %1$s"</string>
|
||||
<string name="notification_room_action_mark_as_read">"Označit jako přečtené"</string>
|
||||
|
||||
@@ -25,8 +25,10 @@ import io.element.android.libraries.matrix.api.room.RoomMembershipState
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.AudioMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.EmoteMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.FileMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.FormattedBody
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.ImageMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.LocationMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.MessageFormat
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.NoticeMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
||||
@@ -51,6 +53,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class NotifiableEventResolverTest {
|
||||
@@ -97,6 +100,71 @@ class NotifiableEventResolverTest {
|
||||
assertThat(result).isEqualTo(expectedResult)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "en")
|
||||
fun `resolve event message with mention`() = runTest {
|
||||
val sut = createNotifiableEventResolver(
|
||||
notificationResult = Result.success(
|
||||
createNotificationData(
|
||||
content = NotificationContent.MessageLike.RoomMessage(
|
||||
senderId = A_USER_ID_2,
|
||||
messageType = TextMessageType(body = "Hello world", formatted = null)
|
||||
),
|
||||
hasMention = true,
|
||||
)
|
||||
)
|
||||
)
|
||||
val result = sut.resolveEvent(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID)
|
||||
val expectedResult = createNotifiableMessageEvent(body = "Mentioned you: Hello world")
|
||||
assertThat(result).isEqualTo(expectedResult)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve HTML formatted event message text takes plain text version`() = runTest {
|
||||
val sut = createNotifiableEventResolver(
|
||||
notificationResult = Result.success(
|
||||
createNotificationData(
|
||||
content = NotificationContent.MessageLike.RoomMessage(
|
||||
senderId = A_USER_ID_2,
|
||||
messageType = TextMessageType(
|
||||
body = "Hello world!",
|
||||
formatted = FormattedBody(
|
||||
body = "<b>Hello world</b>",
|
||||
format = MessageFormat.HTML,
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
val result = sut.resolveEvent(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID)
|
||||
val expectedResult = createNotifiableMessageEvent(body = "Hello world")
|
||||
assertThat(result).isEqualTo(expectedResult)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve incorrectly formatted event message text uses fallback`() = runTest {
|
||||
val sut = createNotifiableEventResolver(
|
||||
notificationResult = Result.success(
|
||||
createNotificationData(
|
||||
content = NotificationContent.MessageLike.RoomMessage(
|
||||
senderId = A_USER_ID_2,
|
||||
messageType = TextMessageType(
|
||||
body = "Hello world",
|
||||
formatted = FormattedBody(
|
||||
body = "???Hello world!???",
|
||||
format = MessageFormat.UNKNOWN,
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
val result = sut.resolveEvent(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID)
|
||||
val expectedResult = createNotifiableMessageEvent(body = "Hello world")
|
||||
assertThat(result).isEqualTo(expectedResult)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve event message audio`() = runTest {
|
||||
val sut = createNotifiableEventResolver(
|
||||
@@ -430,6 +498,7 @@ class NotifiableEventResolverTest {
|
||||
private fun createNotificationData(
|
||||
content: NotificationContent,
|
||||
isDirect: Boolean = false,
|
||||
hasMention: Boolean = false,
|
||||
): NotificationData {
|
||||
return NotificationData(
|
||||
eventId = AN_EVENT_ID,
|
||||
@@ -444,7 +513,7 @@ class NotifiableEventResolverTest {
|
||||
timestamp = A_TIMESTAMP,
|
||||
content = content,
|
||||
contentUrl = null,
|
||||
hasMention = false,
|
||||
hasMention = hasMention,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -227,6 +227,9 @@
|
||||
<item quantity="other">"%d votes"</item>
|
||||
</plurals>
|
||||
<string name="preference_rageshake">"Rageshake to report bug"</string>
|
||||
<string name="screen_edit_poll_delete_confirmation">"Are you sure you want to delete this poll?"</string>
|
||||
<string name="screen_edit_poll_delete_confirmation_title">"Delete Poll"</string>
|
||||
<string name="screen_edit_poll_title">"Edit poll"</string>
|
||||
<string name="screen_media_picker_error_failed_selection">"Failed selecting media, please try again."</string>
|
||||
<string name="screen_media_upload_preview_error_failed_processing">"Failed processing media to upload, please try again."</string>
|
||||
<string name="screen_media_upload_preview_error_failed_sending">"Failed uploading media, please try again."</string>
|
||||
|
||||
Reference in New Issue
Block a user