Skip to content

Commit

Permalink
Improve the text for mentions and replies in notifications (#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp authored Aug 22, 2024
1 parent eeeb8fc commit 7859526
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ class DefaultNotifiableEventResolver @Inject constructor(
is NotificationContent.MessageLike.RoomMessage -> {
val senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId)
val messageBody = descriptionFromMessageContent(content, senderDisambiguatedDisplayName)
val notificationBody = if (hasMention) {
stringProvider.getString(R.string.notification_mentioned_you_body, messageBody)
} else {
messageBody
}
buildNotifiableMessageEvent(
sessionId = userId,
senderId = content.senderId,
Expand All @@ -117,12 +112,13 @@ class DefaultNotifiableEventResolver @Inject constructor(
noisy = isNoisy,
timestamp = this.timestamp,
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
body = notificationBody,
body = messageBody,
imageUriString = fetchImageIfPresent(client)?.toString(),
roomName = roomDisplayName,
roomIsDm = isDm,
roomAvatarPath = roomAvatarUrl,
senderAvatarPath = senderAvatarUrl,
hasMentionOrReply = hasMention,
)
}
is NotificationContent.StateEvent.RoomMemberContent -> {
Expand Down Expand Up @@ -340,6 +336,7 @@ internal fun buildNotifiableMessageEvent(
isRedacted: Boolean = false,
isUpdated: Boolean = false,
type: String = EventType.MESSAGE,
hasMentionOrReply: Boolean = false,
) = NotifiableMessageEvent(
sessionId = sessionId,
senderId = senderId,
Expand All @@ -363,4 +360,5 @@ internal fun buildNotifiableMessageEvent(
isRedacted = isRedacted,
isUpdated = isUpdated,
type = type,
hasMentionOrReply = hasMentionOrReply,
)
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,22 @@ class DefaultNotificationCreator @Inject constructor(
val senderPerson = if (event.outGoingMessage) {
null
} else {
val senderName = event.senderDisambiguatedDisplayName.orEmpty()
// If the notification is for a mention or reply, we create a fake `Person` with a custom name and key
val displayName = if (event.hasMentionOrReply) {
stringProvider.getString(R.string.notification_sender_mention_reply, senderName)
} else {
senderName
}
val key = if (event.hasMentionOrReply) {
"mention-or-reply:${event.eventId.value}"
} else {
event.senderId.value
}
Person.Builder()
.setName(event.senderDisambiguatedDisplayName?.annotateForDebug(70))
.setName(displayName.annotateForDebug(70))
.setIcon(bitmapLoader.getUserIcon(event.senderAvatarPath, imageLoader))
.setKey(event.senderId.value)
.setKey(key)
.build()
}
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ data class NotifiableMessageEvent(
val outGoingMessageFailed: Boolean = false,
override val isRedacted: Boolean = false,
override val isUpdated: Boolean = false,
val type: String = EventType.MESSAGE
val type: String = EventType.MESSAGE,
val hasMentionOrReply: Boolean = false,
) : NotifiableEvent {
override val description: String = body ?: ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class DefaultNotifiableEventResolverTest {
)
)
val result = sut.resolveEvent(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID)
val expectedResult = createNotifiableMessageEvent(body = "Mentioned you: Hello world")
val expectedResult = createNotifiableMessageEvent(body = "Hello world", hasMentionOrReply = true)
assertThat(result).isEqualTo(expectedResult)
}

Expand Down Expand Up @@ -687,7 +687,10 @@ class DefaultNotifiableEventResolverTest {
)
}

private fun createNotifiableMessageEvent(body: String): NotifiableMessageEvent {
private fun createNotifiableMessageEvent(
body: String,
hasMentionOrReply: Boolean = false,
): NotifiableMessageEvent {
return NotifiableMessageEvent(
sessionId = A_SESSION_ID,
roomId = A_ROOM_ID,
Expand All @@ -708,7 +711,8 @@ class DefaultNotifiableEventResolverTest {
outGoingMessage = false,
outGoingMessageFailed = false,
isRedacted = false,
isUpdated = false
isUpdated = false,
hasMentionOrReply = hasMentionOrReply,
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/ui-strings/src/main/res/values/localazy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<string name="action_tap_for_options">"Tap for options"</string>
<string name="action_try_again">"Try again"</string>
<string name="action_unpin">"Unpin"</string>
<string name="action_view_in_timeline">"View in timeline"</string>
<string name="action_view_source">"View source"</string>
<string name="action_yes">"Yes"</string>
<string name="common_about">"About"</string>
Expand Down Expand Up @@ -177,6 +178,7 @@ Reason: %1$s."</string>
<string name="common_people">"People"</string>
<string name="common_permalink">"Permalink"</string>
<string name="common_permission">"Permission"</string>
<string name="common_pinned">"Pinned"</string>
<string name="common_please_wait">"Please wait…"</string>
<string name="common_poll_end_confirmation">"Are you sure you want to end this poll?"</string>
<string name="common_poll_summary">"Poll: %1$s"</string>
Expand Down

0 comments on commit 7859526

Please sign in to comment.