Include sender name in notification for invite content.
This commit is contained in:
parent
39f0703765
commit
9f713e54b1
3 changed files with 84 additions and 9 deletions
|
|
@ -112,6 +112,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is NotificationContent.Invite -> {
|
is NotificationContent.Invite -> {
|
||||||
|
val senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId)
|
||||||
InviteNotifiableEvent(
|
InviteNotifiableEvent(
|
||||||
sessionId = userId,
|
sessionId = userId,
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
|
|
@ -124,8 +125,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
||||||
soundName = null,
|
soundName = null,
|
||||||
isRedacted = false,
|
isRedacted = false,
|
||||||
isUpdated = false,
|
isUpdated = false,
|
||||||
// TODO We could use the senderId here
|
description = descriptionFromRoomMembershipInvite(senderDisambiguatedDisplayName, isDirect),
|
||||||
description = descriptionFromRoomMembershipInvite(isDirect),
|
|
||||||
// TODO check if type is needed anymore
|
// TODO check if type is needed anymore
|
||||||
type = null,
|
type = null,
|
||||||
// TODO check if title is needed anymore
|
// TODO check if title is needed anymore
|
||||||
|
|
@ -278,12 +278,13 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun descriptionFromRoomMembershipInvite(
|
private fun descriptionFromRoomMembershipInvite(
|
||||||
|
senderDisambiguatedDisplayName: String,
|
||||||
isDirectRoom: Boolean
|
isDirectRoom: Boolean
|
||||||
): String {
|
): String {
|
||||||
return if (isDirectRoom) {
|
return if (isDirectRoom) {
|
||||||
stringProvider.getString(R.string.notification_invite_body)
|
stringProvider.getString(R.string.notification_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||||
} else {
|
} else {
|
||||||
stringProvider.getString(R.string.notification_room_invite_body)
|
stringProvider.getString(R.string.notification_room_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
<item quantity="other">"%d invitations"</item>
|
<item quantity="other">"%d invitations"</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
<string name="notification_invite_body">"Invited you to chat"</string>
|
<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_mentioned_you_body">"Mentioned you: %1$s"</string>
|
||||||
<string name="notification_new_messages">"New Messages"</string>
|
<string name="notification_new_messages">"New Messages"</string>
|
||||||
<plurals name="notification_new_messages_for_room">
|
<plurals name="notification_new_messages_for_room">
|
||||||
|
|
@ -33,6 +34,7 @@
|
||||||
<string name="notification_room_action_mark_as_read">"Mark as read"</string>
|
<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_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">"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_me">"Me"</string>
|
||||||
<string name="notification_sender_mention_reply">"%1$s mentioned or replied"</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>
|
<string name="notification_test_push_notification_content">"You are viewing the notification! Click me!"</string>
|
||||||
|
|
|
||||||
|
|
@ -404,7 +404,7 @@ class DefaultNotifiableEventResolverTest {
|
||||||
roomName = null,
|
roomName = null,
|
||||||
noisy = false,
|
noisy = false,
|
||||||
title = null,
|
title = null,
|
||||||
description = "Invited you to join the room",
|
description = "Bob invited you to join the room",
|
||||||
type = null,
|
type = null,
|
||||||
timestamp = A_TIMESTAMP,
|
timestamp = A_TIMESTAMP,
|
||||||
soundName = null,
|
soundName = null,
|
||||||
|
|
@ -416,7 +416,7 @@ class DefaultNotifiableEventResolverTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `resolve invite invite direct`() = runTest {
|
fun `resolve invite direct`() = runTest {
|
||||||
val sut = createDefaultNotifiableEventResolver(
|
val sut = createDefaultNotifiableEventResolver(
|
||||||
notificationResult = Result.success(
|
notificationResult = Result.success(
|
||||||
createNotificationData(
|
createNotificationData(
|
||||||
|
|
@ -438,7 +438,77 @@ class DefaultNotifiableEventResolverTest {
|
||||||
roomName = null,
|
roomName = null,
|
||||||
noisy = false,
|
noisy = false,
|
||||||
title = null,
|
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,
|
type = null,
|
||||||
timestamp = A_TIMESTAMP,
|
timestamp = A_TIMESTAMP,
|
||||||
soundName = null,
|
soundName = null,
|
||||||
|
|
@ -755,13 +825,15 @@ class DefaultNotifiableEventResolverTest {
|
||||||
isDirect: Boolean = false,
|
isDirect: Boolean = false,
|
||||||
hasMention: Boolean = false,
|
hasMention: Boolean = false,
|
||||||
timestamp: Long = A_TIMESTAMP,
|
timestamp: Long = A_TIMESTAMP,
|
||||||
|
senderDisplayName: String? = "Bob",
|
||||||
|
senderIsNameAmbiguous: Boolean = false,
|
||||||
): NotificationData {
|
): NotificationData {
|
||||||
return NotificationData(
|
return NotificationData(
|
||||||
eventId = AN_EVENT_ID,
|
eventId = AN_EVENT_ID,
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
senderAvatarUrl = null,
|
senderAvatarUrl = null,
|
||||||
senderDisplayName = "Bob",
|
senderDisplayName = senderDisplayName,
|
||||||
senderIsNameAmbiguous = false,
|
senderIsNameAmbiguous = senderIsNameAmbiguous,
|
||||||
roomAvatarUrl = null,
|
roomAvatarUrl = null,
|
||||||
roomDisplayName = null,
|
roomDisplayName = null,
|
||||||
isDirect = isDirect,
|
isDirect = isDirect,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue