Skip to content

Commit 7859526

Browse files
authored
Improve the text for mentions and replies in notifications (#3328)
1 parent eeeb8fc commit 7859526

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ class DefaultNotifiableEventResolver @Inject constructor(
104104
is NotificationContent.MessageLike.RoomMessage -> {
105105
val senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId)
106106
val messageBody = descriptionFromMessageContent(content, senderDisambiguatedDisplayName)
107-
val notificationBody = if (hasMention) {
108-
stringProvider.getString(R.string.notification_mentioned_you_body, messageBody)
109-
} else {
110-
messageBody
111-
}
112107
buildNotifiableMessageEvent(
113108
sessionId = userId,
114109
senderId = content.senderId,
@@ -117,12 +112,13 @@ class DefaultNotifiableEventResolver @Inject constructor(
117112
noisy = isNoisy,
118113
timestamp = this.timestamp,
119114
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
120-
body = notificationBody,
115+
body = messageBody,
121116
imageUriString = fetchImageIfPresent(client)?.toString(),
122117
roomName = roomDisplayName,
123118
roomIsDm = isDm,
124119
roomAvatarPath = roomAvatarUrl,
125120
senderAvatarPath = senderAvatarUrl,
121+
hasMentionOrReply = hasMention,
126122
)
127123
}
128124
is NotificationContent.StateEvent.RoomMemberContent -> {
@@ -340,6 +336,7 @@ internal fun buildNotifiableMessageEvent(
340336
isRedacted: Boolean = false,
341337
isUpdated: Boolean = false,
342338
type: String = EventType.MESSAGE,
339+
hasMentionOrReply: Boolean = false,
343340
) = NotifiableMessageEvent(
344341
sessionId = sessionId,
345342
senderId = senderId,
@@ -363,4 +360,5 @@ internal fun buildNotifiableMessageEvent(
363360
isRedacted = isRedacted,
364361
isUpdated = isUpdated,
365362
type = type,
363+
hasMentionOrReply = hasMentionOrReply,
366364
)

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/factories/NotificationCreator.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,22 @@ class DefaultNotificationCreator @Inject constructor(
397397
val senderPerson = if (event.outGoingMessage) {
398398
null
399399
} else {
400+
val senderName = event.senderDisambiguatedDisplayName.orEmpty()
401+
// If the notification is for a mention or reply, we create a fake `Person` with a custom name and key
402+
val displayName = if (event.hasMentionOrReply) {
403+
stringProvider.getString(R.string.notification_sender_mention_reply, senderName)
404+
} else {
405+
senderName
406+
}
407+
val key = if (event.hasMentionOrReply) {
408+
"mention-or-reply:${event.eventId.value}"
409+
} else {
410+
event.senderId.value
411+
}
400412
Person.Builder()
401-
.setName(event.senderDisambiguatedDisplayName?.annotateForDebug(70))
413+
.setName(displayName.annotateForDebug(70))
402414
.setIcon(bitmapLoader.getUserIcon(event.senderAvatarPath, imageLoader))
403-
.setKey(event.senderId.value)
415+
.setKey(key)
404416
.build()
405417
}
406418
when {

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/model/NotifiableMessageEvent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ data class NotifiableMessageEvent(
5252
val outGoingMessageFailed: Boolean = false,
5353
override val isRedacted: Boolean = false,
5454
override val isUpdated: Boolean = false,
55-
val type: String = EventType.MESSAGE
55+
val type: String = EventType.MESSAGE,
56+
val hasMentionOrReply: Boolean = false,
5657
) : NotifiableEvent {
5758
override val description: String = body ?: ""
5859

libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class DefaultNotifiableEventResolverTest {
123123
)
124124
)
125125
val result = sut.resolveEvent(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID)
126-
val expectedResult = createNotifiableMessageEvent(body = "Mentioned you: Hello world")
126+
val expectedResult = createNotifiableMessageEvent(body = "Hello world", hasMentionOrReply = true)
127127
assertThat(result).isEqualTo(expectedResult)
128128
}
129129

@@ -687,7 +687,10 @@ class DefaultNotifiableEventResolverTest {
687687
)
688688
}
689689

690-
private fun createNotifiableMessageEvent(body: String): NotifiableMessageEvent {
690+
private fun createNotifiableMessageEvent(
691+
body: String,
692+
hasMentionOrReply: Boolean = false,
693+
): NotifiableMessageEvent {
691694
return NotifiableMessageEvent(
692695
sessionId = A_SESSION_ID,
693696
roomId = A_ROOM_ID,
@@ -708,7 +711,8 @@ class DefaultNotifiableEventResolverTest {
708711
outGoingMessage = false,
709712
outGoingMessageFailed = false,
710713
isRedacted = false,
711-
isUpdated = false
714+
isUpdated = false,
715+
hasMentionOrReply = hasMentionOrReply,
712716
)
713717
}
714718
}

libraries/ui-strings/src/main/res/values/localazy.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<string name="action_tap_for_options">"Tap for options"</string>
113113
<string name="action_try_again">"Try again"</string>
114114
<string name="action_unpin">"Unpin"</string>
115+
<string name="action_view_in_timeline">"View in timeline"</string>
115116
<string name="action_view_source">"View source"</string>
116117
<string name="action_yes">"Yes"</string>
117118
<string name="common_about">"About"</string>
@@ -177,6 +178,7 @@ Reason: %1$s."</string>
177178
<string name="common_people">"People"</string>
178179
<string name="common_permalink">"Permalink"</string>
179180
<string name="common_permission">"Permission"</string>
181+
<string name="common_pinned">"Pinned"</string>
180182
<string name="common_please_wait">"Please wait…"</string>
181183
<string name="common_poll_end_confirmation">"Are you sure you want to end this poll?"</string>
182184
<string name="common_poll_summary">"Poll: %1$s"</string>

0 commit comments

Comments
 (0)