Merge pull request #5854 from element-hq/feature/fga/space_invite_notification
change(notification): handle invite notification for spaces
This commit is contained in:
@@ -30,6 +30,7 @@ data class NotificationData(
|
||||
val roomDisplayName: String?,
|
||||
val isDirect: Boolean,
|
||||
val isDm: Boolean,
|
||||
val isSpace: Boolean,
|
||||
val isEncrypted: Boolean,
|
||||
val isNoisy: Boolean,
|
||||
val timestamp: Long,
|
||||
|
||||
@@ -53,6 +53,7 @@ class NotificationMapper(
|
||||
roomDisplayName = item.roomInfo.displayName,
|
||||
isDirect = item.roomInfo.isDirect,
|
||||
isDm = isDm,
|
||||
isSpace = item.roomInfo.isSpace,
|
||||
isEncrypted = item.roomInfo.isEncrypted.orFalse(),
|
||||
isNoisy = item.isNoisy.orFalse(),
|
||||
timestamp = timestamp,
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.element.android.libraries.matrix.test.A_USER_NAME_2
|
||||
fun aNotificationData(
|
||||
content: NotificationContent = NotificationContent.MessageLike.RoomEncrypted,
|
||||
isDirect: Boolean = false,
|
||||
isSpace: Boolean = false,
|
||||
hasMention: Boolean = false,
|
||||
threadId: ThreadId? = null,
|
||||
timestamp: Long = A_TIMESTAMP,
|
||||
@@ -40,6 +41,7 @@ fun aNotificationData(
|
||||
roomDisplayName = roomDisplayName,
|
||||
isDirect = isDirect,
|
||||
isDm = false,
|
||||
isSpace = isSpace,
|
||||
isEncrypted = false,
|
||||
isNoisy = false,
|
||||
timestamp = timestamp,
|
||||
|
||||
@@ -183,7 +183,11 @@ class DefaultNotifiableEventResolver(
|
||||
soundName = null,
|
||||
isRedacted = false,
|
||||
isUpdated = false,
|
||||
description = descriptionFromRoomMembershipInvite(senderDisambiguatedDisplayName, isDirect),
|
||||
description = descriptionFromRoomMembershipInvite(
|
||||
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
|
||||
isDirectRoom = isDirect,
|
||||
isSpace = isSpace
|
||||
),
|
||||
// TODO check if type is needed anymore
|
||||
type = null,
|
||||
// TODO check if title is needed anymore
|
||||
@@ -332,12 +336,19 @@ class DefaultNotifiableEventResolver(
|
||||
|
||||
private fun descriptionFromRoomMembershipInvite(
|
||||
senderDisambiguatedDisplayName: String,
|
||||
isDirectRoom: Boolean
|
||||
isDirectRoom: Boolean,
|
||||
isSpace: Boolean,
|
||||
): String {
|
||||
return if (isDirectRoom) {
|
||||
stringProvider.getString(R.string.notification_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||
} else {
|
||||
stringProvider.getString(R.string.notification_room_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||
return when {
|
||||
isDirectRoom -> {
|
||||
stringProvider.getString(R.string.notification_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||
}
|
||||
isSpace -> {
|
||||
stringProvider.getString(R.string.notification_space_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||
}
|
||||
else -> {
|
||||
stringProvider.getString(R.string.notification_room_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
<string name="notification_sender_me">"Me"</string>
|
||||
<string name="notification_sender_mention_reply">"%1$s mentioned or replied"</string>
|
||||
<string name="notification_space_invite_body">"Invited you to join the space"</string>
|
||||
<string name="notification_space_invite_body_with_sender">"%1$s invited you to join the space"</string>
|
||||
<string name="notification_test_push_notification_content">"You are viewing the notification! Click me!"</string>
|
||||
<string name="notification_thread_in_room">"Thread in %1$s"</string>
|
||||
<string name="notification_ticker_text_dm">"%1$s: %2$s"</string>
|
||||
|
||||
@@ -38,6 +38,7 @@ import io.element.android.libraries.matrix.test.A_REDACTION_REASON
|
||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||
import io.element.android.libraries.matrix.test.A_ROOM_NAME
|
||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||
import io.element.android.libraries.matrix.test.A_SPACE_NAME
|
||||
import io.element.android.libraries.matrix.test.A_TIMESTAMP
|
||||
import io.element.android.libraries.matrix.test.A_USER_ID_2
|
||||
import io.element.android.libraries.matrix.test.A_USER_NAME_2
|
||||
@@ -474,6 +475,45 @@ class DefaultNotifiableEventResolverTest {
|
||||
assertThat(result.getEvent(request)).isEqualTo(Result.success(expectedResult))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve invite space`() = runTest {
|
||||
val sut = createDefaultNotifiableEventResolver(
|
||||
notificationResult = Result.success(
|
||||
mapOf(
|
||||
AN_EVENT_ID to Result.success(aNotificationData(
|
||||
content = NotificationContent.Invite(
|
||||
senderId = A_USER_ID_2,
|
||||
),
|
||||
roomDisplayName = A_SPACE_NAME,
|
||||
isDirect = false,
|
||||
isSpace = true,
|
||||
))
|
||||
)
|
||||
)
|
||||
)
|
||||
val request = NotificationEventRequest(A_SESSION_ID, A_ROOM_ID, AN_EVENT_ID, "firebase")
|
||||
val result = sut.resolveEvents(A_SESSION_ID, listOf(request))
|
||||
val expectedResult = ResolvedPushEvent.Event(
|
||||
InviteNotifiableEvent(
|
||||
sessionId = A_SESSION_ID,
|
||||
roomId = A_ROOM_ID,
|
||||
eventId = AN_EVENT_ID,
|
||||
editedEventId = null,
|
||||
canBeReplaced = true,
|
||||
roomName = A_SPACE_NAME,
|
||||
noisy = false,
|
||||
title = null,
|
||||
description = "Bob invited you to join the space",
|
||||
type = null,
|
||||
timestamp = A_TIMESTAMP,
|
||||
soundName = null,
|
||||
isRedacted = false,
|
||||
isUpdated = false,
|
||||
)
|
||||
)
|
||||
assertThat(result.getEvent(request)).isEqualTo(Result.success(expectedResult))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resolve invite direct`() = runTest {
|
||||
val sut = createDefaultNotifiableEventResolver(
|
||||
|
||||
Reference in New Issue
Block a user