Browse Source

Include sender name in notification for invite content.

pull/3503/head
Benoit Marty 4 weeks ago committed by Benoit Marty
parent
commit
ce650b06fb
  1. 9
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt
  2. 2
      libraries/push/impl/src/main/res/values/localazy.xml
  3. 82
      libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt

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

@ -112,6 +112,7 @@ class DefaultNotifiableEventResolver @Inject constructor( @@ -112,6 +112,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
)
}
is NotificationContent.Invite -> {
val senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId)
InviteNotifiableEvent(
sessionId = userId,
roomId = roomId,
@ -124,8 +125,7 @@ class DefaultNotifiableEventResolver @Inject constructor( @@ -124,8 +125,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
soundName = null,
isRedacted = false,
isUpdated = false,
// TODO We could use the senderId here
description = descriptionFromRoomMembershipInvite(isDirect),
description = descriptionFromRoomMembershipInvite(senderDisambiguatedDisplayName, isDirect),
// TODO check if type is needed anymore
type = null,
// TODO check if title is needed anymore
@ -278,12 +278,13 @@ class DefaultNotifiableEventResolver @Inject constructor( @@ -278,12 +278,13 @@ class DefaultNotifiableEventResolver @Inject constructor(
}
private fun descriptionFromRoomMembershipInvite(
senderDisambiguatedDisplayName: String,
isDirectRoom: Boolean
): String {
return if (isDirectRoom) {
stringProvider.getString(R.string.notification_invite_body)
stringProvider.getString(R.string.notification_invite_body_with_sender, senderDisambiguatedDisplayName)
} else {
stringProvider.getString(R.string.notification_room_invite_body)
stringProvider.getString(R.string.notification_room_invite_body_with_sender, senderDisambiguatedDisplayName)
}
}

2
libraries/push/impl/src/main/res/values/localazy.xml

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
<item quantity="other">"%d invitations"</item>
</plurals>
<string name="notification_invite_body">"Invited you to chat"</string>
<string name="notification_invite_body_with_sender">"%1$s invited you to chat"</string>
<string name="notification_mentioned_you_body">"Mentioned you: %1$s"</string>
<string name="notification_new_messages">"New Messages"</string>
<plurals name="notification_new_messages_for_room">
@ -33,6 +34,7 @@ @@ -33,6 +34,7 @@
<string name="notification_room_action_mark_as_read">"Mark as read"</string>
<string name="notification_room_action_quick_reply">"Quick reply"</string>
<string name="notification_room_invite_body">"Invited you to join the room"</string>
<string name="notification_room_invite_body_with_sender">"%1$s invited you to join the room"</string>
<string name="notification_sender_me">"Me"</string>
<string name="notification_sender_mention_reply">"%1$s mentioned or replied"</string>
<string name="notification_test_push_notification_content">"You are viewing the notification! Click me!"</string>

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

@ -404,7 +404,7 @@ class DefaultNotifiableEventResolverTest { @@ -404,7 +404,7 @@ class DefaultNotifiableEventResolverTest {
roomName = null,
noisy = false,
title = null,
description = "Invited you to join the room",
description = "Bob invited you to join the room",
type = null,
timestamp = A_TIMESTAMP,
soundName = null,
@ -416,7 +416,7 @@ class DefaultNotifiableEventResolverTest { @@ -416,7 +416,7 @@ class DefaultNotifiableEventResolverTest {
}
@Test
fun `resolve invite invite direct`() = runTest {
fun `resolve invite direct`() = runTest {
val sut = createDefaultNotifiableEventResolver(
notificationResult = Result.success(
createNotificationData(
@ -438,7 +438,77 @@ class DefaultNotifiableEventResolverTest { @@ -438,7 +438,77 @@ class DefaultNotifiableEventResolverTest {
roomName = null,
noisy = false,
title = null,
description = "Invited you to chat",
description = "Bob invited you to chat",
type = null,
timestamp = A_TIMESTAMP,
soundName = null,
isRedacted = false,
isUpdated = false,
)
)
assertThat(result).isEqualTo(expectedResult)
}
@Test
fun `resolve invite direct, no display name`() = runTest {
val sut = createDefaultNotifiableEventResolver(
notificationResult = Result.success(
createNotificationData(
content = NotificationContent.Invite(
senderId = A_USER_ID_2,
),
isDirect = true,
senderDisplayName = null,
)
)
)
val result = sut.resolveEvent(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID)
val expectedResult = ResolvedPushEvent.Event(
InviteNotifiableEvent(
sessionId = A_SESSION_ID,
roomId = A_ROOM_ID,
eventId = AN_EVENT_ID,
editedEventId = null,
canBeReplaced = true,
roomName = null,
noisy = false,
title = null,
description = "@bob:server.org invited you to chat",
type = null,
timestamp = A_TIMESTAMP,
soundName = null,
isRedacted = false,
isUpdated = false,
)
)
assertThat(result).isEqualTo(expectedResult)
}
@Test
fun `resolve invite direct, ambiguous display name`() = runTest {
val sut = createDefaultNotifiableEventResolver(
notificationResult = Result.success(
createNotificationData(
content = NotificationContent.Invite(
senderId = A_USER_ID_2,
),
isDirect = false,
senderIsNameAmbiguous = true,
)
)
)
val result = sut.resolveEvent(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID)
val expectedResult = ResolvedPushEvent.Event(
InviteNotifiableEvent(
sessionId = A_SESSION_ID,
roomId = A_ROOM_ID,
eventId = AN_EVENT_ID,
editedEventId = null,
canBeReplaced = true,
roomName = null,
noisy = false,
title = null,
description = "Bob (@bob:server.org) invited you to join the room",
type = null,
timestamp = A_TIMESTAMP,
soundName = null,
@ -755,13 +825,15 @@ class DefaultNotifiableEventResolverTest { @@ -755,13 +825,15 @@ class DefaultNotifiableEventResolverTest {
isDirect: Boolean = false,
hasMention: Boolean = false,
timestamp: Long = A_TIMESTAMP,
senderDisplayName: String? = "Bob",
senderIsNameAmbiguous: Boolean = false,
): NotificationData {
return NotificationData(
eventId = AN_EVENT_ID,
roomId = A_ROOM_ID,
senderAvatarUrl = null,
senderDisplayName = "Bob",
senderIsNameAmbiguous = false,
senderDisplayName = senderDisplayName,
senderIsNameAmbiguous = senderIsNameAmbiguous,
roomAvatarUrl = null,
roomDisplayName = null,
isDirect = isDirect,

Loading…
Cancel
Save