Merge pull request #5854 from element-hq/feature/fga/space_invite_notification
change(notification): handle invite notification for spaces
This commit is contained in:
commit
a5c889ff40
6 changed files with 62 additions and 6 deletions
|
|
@ -30,6 +30,7 @@ data class NotificationData(
|
||||||
val roomDisplayName: String?,
|
val roomDisplayName: String?,
|
||||||
val isDirect: Boolean,
|
val isDirect: Boolean,
|
||||||
val isDm: Boolean,
|
val isDm: Boolean,
|
||||||
|
val isSpace: Boolean,
|
||||||
val isEncrypted: Boolean,
|
val isEncrypted: Boolean,
|
||||||
val isNoisy: Boolean,
|
val isNoisy: Boolean,
|
||||||
val timestamp: Long,
|
val timestamp: Long,
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ class NotificationMapper(
|
||||||
roomDisplayName = item.roomInfo.displayName,
|
roomDisplayName = item.roomInfo.displayName,
|
||||||
isDirect = item.roomInfo.isDirect,
|
isDirect = item.roomInfo.isDirect,
|
||||||
isDm = isDm,
|
isDm = isDm,
|
||||||
|
isSpace = item.roomInfo.isSpace,
|
||||||
isEncrypted = item.roomInfo.isEncrypted.orFalse(),
|
isEncrypted = item.roomInfo.isEncrypted.orFalse(),
|
||||||
isNoisy = item.isNoisy.orFalse(),
|
isNoisy = item.isNoisy.orFalse(),
|
||||||
timestamp = timestamp,
|
timestamp = timestamp,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import io.element.android.libraries.matrix.test.A_USER_NAME_2
|
||||||
fun aNotificationData(
|
fun aNotificationData(
|
||||||
content: NotificationContent = NotificationContent.MessageLike.RoomEncrypted,
|
content: NotificationContent = NotificationContent.MessageLike.RoomEncrypted,
|
||||||
isDirect: Boolean = false,
|
isDirect: Boolean = false,
|
||||||
|
isSpace: Boolean = false,
|
||||||
hasMention: Boolean = false,
|
hasMention: Boolean = false,
|
||||||
threadId: ThreadId? = null,
|
threadId: ThreadId? = null,
|
||||||
timestamp: Long = A_TIMESTAMP,
|
timestamp: Long = A_TIMESTAMP,
|
||||||
|
|
@ -40,6 +41,7 @@ fun aNotificationData(
|
||||||
roomDisplayName = roomDisplayName,
|
roomDisplayName = roomDisplayName,
|
||||||
isDirect = isDirect,
|
isDirect = isDirect,
|
||||||
isDm = false,
|
isDm = false,
|
||||||
|
isSpace = isSpace,
|
||||||
isEncrypted = false,
|
isEncrypted = false,
|
||||||
isNoisy = false,
|
isNoisy = false,
|
||||||
timestamp = timestamp,
|
timestamp = timestamp,
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,11 @@ class DefaultNotifiableEventResolver(
|
||||||
soundName = null,
|
soundName = null,
|
||||||
isRedacted = false,
|
isRedacted = false,
|
||||||
isUpdated = false,
|
isUpdated = false,
|
||||||
description = descriptionFromRoomMembershipInvite(senderDisambiguatedDisplayName, isDirect),
|
description = descriptionFromRoomMembershipInvite(
|
||||||
|
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
|
||||||
|
isDirectRoom = isDirect,
|
||||||
|
isSpace = isSpace
|
||||||
|
),
|
||||||
// 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
|
||||||
|
|
@ -332,12 +336,19 @@ class DefaultNotifiableEventResolver(
|
||||||
|
|
||||||
private fun descriptionFromRoomMembershipInvite(
|
private fun descriptionFromRoomMembershipInvite(
|
||||||
senderDisambiguatedDisplayName: String,
|
senderDisambiguatedDisplayName: String,
|
||||||
isDirectRoom: Boolean
|
isDirectRoom: Boolean,
|
||||||
|
isSpace: Boolean,
|
||||||
): String {
|
): String {
|
||||||
return if (isDirectRoom) {
|
return when {
|
||||||
stringProvider.getString(R.string.notification_invite_body_with_sender, senderDisambiguatedDisplayName)
|
isDirectRoom -> {
|
||||||
} else {
|
stringProvider.getString(R.string.notification_invite_body_with_sender, senderDisambiguatedDisplayName)
|
||||||
stringProvider.getString(R.string.notification_room_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_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_space_invite_body">"Invited you to join the space"</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_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_thread_in_room">"Thread in %1$s"</string>
|
||||||
<string name="notification_ticker_text_dm">"%1$s: %2$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_ID
|
||||||
import io.element.android.libraries.matrix.test.A_ROOM_NAME
|
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_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_TIMESTAMP
|
||||||
import io.element.android.libraries.matrix.test.A_USER_ID_2
|
import io.element.android.libraries.matrix.test.A_USER_ID_2
|
||||||
import io.element.android.libraries.matrix.test.A_USER_NAME_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))
|
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
|
@Test
|
||||||
fun `resolve invite direct`() = runTest {
|
fun `resolve invite direct`() = runTest {
|
||||||
val sut = createDefaultNotifiableEventResolver(
|
val sut = createDefaultNotifiableEventResolver(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue