Skip to content

Commit

Permalink
Merge pull request #3503 from element-hq/bma/invitationWithSender
Browse files Browse the repository at this point in the history
Include inviter in the notification for invitation
  • Loading branch information
bmarty authored Sep 24, 2024
2 parents d4e8488 + 6fc801e commit 12fa376
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.room.RoomMember
import io.element.android.libraries.matrix.api.room.StateEventType
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
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_TOPIC
import io.element.android.libraries.matrix.test.notificationsettings.FakeNotificationSettingsService
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
import io.element.android.libraries.matrix.test.room.aRoomInfo
Expand All @@ -22,8 +24,8 @@ fun aMatrixRoom(
roomId: RoomId = A_ROOM_ID,
displayName: String = A_ROOM_NAME,
rawName: String? = displayName,
topic: String? = "A topic",
avatarUrl: String? = "https://matrix.org/avatar.jpg",
topic: String? = A_ROOM_TOPIC,
avatarUrl: String? = AN_AVATAR_URL,
isEncrypted: Boolean = true,
isPublic: Boolean = true,
isDirect: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
import io.element.android.libraries.matrix.api.room.StateEventType
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
import io.element.android.libraries.matrix.test.AN_EVENT_ID
import io.element.android.libraries.matrix.test.A_ROOM_NAME
import io.element.android.libraries.matrix.test.A_ROOM_TOPIC
import io.element.android.libraries.matrix.test.A_SESSION_ID
import io.element.android.libraries.matrix.test.A_USER_ID_2
import io.element.android.libraries.matrix.test.FakeMatrixClient
Expand Down Expand Up @@ -129,7 +132,12 @@ class RoomDetailsPresenterTest {

@Test
fun `present - initial state is updated with roomInfo if it exists`() = runTest {
val roomInfo = aRoomInfo(name = "A room name", topic = "A topic", avatarUrl = "https://matrix.org/avatar.jpg", pinnedEventIds = listOf(AN_EVENT_ID))
val roomInfo = aRoomInfo(
name = A_ROOM_NAME,
topic = A_ROOM_TOPIC,
avatarUrl = AN_AVATAR_URL,
pinnedEventIds = listOf(AN_EVENT_ID),
)
val room = aMatrixRoom(
canInviteResult = { Result.success(true) },
canUserJoinCallResult = { Result.success(true) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.element.android.libraries.matrix.api.room.RoomNotificationMode
import io.element.android.libraries.matrix.api.room.RoomNotificationSettings

const val A_USER_NAME = "alice"
const val A_USER_NAME_2 = "Bob"
const val A_PASSWORD = "password"
const val A_PASSPHRASE = "passphrase"
const val A_SECRET = "secret"
Expand Down Expand Up @@ -55,6 +56,7 @@ val A_UNIQUE_ID = UniqueId("aUniqueId")
val A_UNIQUE_ID_2 = UniqueId("aUniqueId2")

const val A_ROOM_NAME = "A room name"
const val A_ROOM_TOPIC = "A room topic"
const val A_ROOM_RAW_NAME = "A room raw name"
const val A_MESSAGE = "Hello world!"
const val A_REPLY = "OK, I'll be there!"
Expand All @@ -80,3 +82,5 @@ val AN_EXCEPTION = Exception(A_FAILURE_REASON)
const val A_RECOVERY_KEY = "1234 5678"

val A_SERVER_LIST = listOf("server1", "server2")

const val A_TIMESTAMP = 567L
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ import io.element.android.libraries.matrix.api.notification.NotificationContent
import io.element.android.libraries.matrix.api.notification.NotificationData
import io.element.android.libraries.matrix.test.AN_EVENT_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_TIMESTAMP
import io.element.android.libraries.matrix.test.A_USER_NAME_2

fun aNotificationData(
senderDisplayName: String?,
senderIsNameAmbiguous: Boolean,
content: NotificationContent = NotificationContent.MessageLike.RoomEncrypted,
isDirect: Boolean = false,
hasMention: Boolean = false,
timestamp: Long = A_TIMESTAMP,
senderDisplayName: String? = A_USER_NAME_2,
senderIsNameAmbiguous: Boolean = false,
roomDisplayName: String? = A_ROOM_NAME
): NotificationData {
return NotificationData(
eventId = AN_EVENT_ID,
Expand All @@ -23,13 +31,13 @@ fun aNotificationData(
senderDisplayName = senderDisplayName,
senderIsNameAmbiguous = senderIsNameAmbiguous,
roomAvatarUrl = null,
roomDisplayName = null,
isDirect = false,
roomDisplayName = roomDisplayName,
isDirect = isDirect,
isDm = false,
isEncrypted = false,
isNoisy = false,
timestamp = 0L,
content = NotificationContent.MessageLike.RoomEncrypted,
hasMention = false,
timestamp = timestamp,
content = content,
hasMention = hasMention,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
)
}
is NotificationContent.Invite -> {
val senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId)
InviteNotifiableEvent(
sessionId = userId,
roomId = roomId,
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
Loading

0 comments on commit 12fa376

Please sign in to comment.