diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt
index 19f9e1f356..283b28ab31 100644
--- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt
+++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt
@@ -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(
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(
}
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)
}
}
diff --git a/libraries/push/impl/src/main/res/values/localazy.xml b/libraries/push/impl/src/main/res/values/localazy.xml
index 5fed2718a1..f3d1e5392f 100644
--- a/libraries/push/impl/src/main/res/values/localazy.xml
+++ b/libraries/push/impl/src/main/res/values/localazy.xml
@@ -23,6 +23,7 @@
- "%d invitations"
"Invited you to chat"
+ "%1$s invited you to chat"
"Mentioned you: %1$s"
"New Messages"
@@ -33,6 +34,7 @@
"Mark as read"
"Quick reply"
"Invited you to join the room"
+ "%1$s invited you to join the room"
"Me"
"%1$s mentioned or replied"
"You are viewing the notification! Click me!"
diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt
index e41d26b943..7dc0eab13b 100644
--- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt
+++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt
@@ -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 {
}
@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 {
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 {
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,