change(notification): handle invite notification for spaces

This commit is contained in:
ganfra 2025-12-04 12:25:30 +01:00
parent 24e3705671
commit 236db9e35d
6 changed files with 63 additions and 6 deletions

View file

@ -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)
}
}
}

View file

@ -38,6 +38,8 @@
<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_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>

View file

@ -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(