Adapt to new DM definition changes in the SDK (#6748)
* Set `DmRoomDefinition.TwoPeople` in `ClientBuilder`. This applies the 'direct and with at most 2 non-service members' rule to what the SDK should consider a DM. * Map `RoomInfo.isDm` from the SDK * Map `NotificationData.isDm` from `NotificationInfo.roomInfo.isDm` * Remove `RoomIsDmCheck` file as its extension functions are now redundant. Move `Room.isDm` helper function to `BaseRoom`. * Map `isDm` in `SpaceRoom` from the SDK too * Replace `isDirect` with `isDm` where possible * Map `RoomMember.isServiceMember` from the SDK and use it to tell apart normal members of a room from service members (i.e. `RoomMembersState.getDirectRoomMember`)
This commit is contained in:
parent
5e5e0bbc6e
commit
11476c73cf
66 changed files with 115 additions and 232 deletions
|
|
@ -19,7 +19,7 @@ fun BaseRoom.toAnalyticsViewRoom(
|
|||
val activeSpace = selectedSpace?.toActiveSpace() ?: ViewRoom.ActiveSpace.Home
|
||||
|
||||
return ViewRoom(
|
||||
isDM = info().isDirect,
|
||||
isDM = info().isDm,
|
||||
isSpace = info().isSpace,
|
||||
trigger = trigger,
|
||||
activeSpace = activeSpace,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ interface NotificationSettingsService {
|
|||
val notificationSettingsChangeFlow: SharedFlow<Unit>
|
||||
suspend fun getRoomNotificationSettings(roomId: RoomId, isEncrypted: Boolean, isOneToOne: Boolean): Result<RoomNotificationSettings>
|
||||
suspend fun getDefaultRoomNotificationMode(isEncrypted: Boolean, isOneToOne: Boolean): Result<RoomNotificationMode>
|
||||
suspend fun setDefaultRoomNotificationMode(isEncrypted: Boolean, mode: RoomNotificationMode, isOneToOne: Boolean): Result<Unit>
|
||||
suspend fun setDefaultRoomNotificationMode(isEncrypted: Boolean, mode: RoomNotificationMode, isDM: Boolean): Result<Unit>
|
||||
suspend fun setRoomNotificationMode(roomId: RoomId, mode: RoomNotificationMode): Result<Unit>
|
||||
suspend fun restoreDefaultRoomNotificationMode(roomId: RoomId): Result<Unit>
|
||||
suspend fun muteRoom(roomId: RoomId): Result<Unit>
|
||||
|
|
|
|||
|
|
@ -61,13 +61,12 @@ interface BaseRoom : Closeable {
|
|||
*/
|
||||
fun info(): RoomInfo = roomInfoFlow.value
|
||||
|
||||
fun predecessorRoom(): PredecessorRoom?
|
||||
|
||||
/**
|
||||
* A one-to-one is a room with exactly 2 members.
|
||||
* See [the Matrix spec](https://spec.matrix.org/latest/client-server-api/#default-underride-rules).
|
||||
* Returns whether the [BaseRoom] is a DM, with an updated state from the latest [RoomInfo].
|
||||
*/
|
||||
val isOneToOne: Boolean get() = info().activeMembersCount == 2L
|
||||
fun isDm() = roomInfoFlow.value.isDm
|
||||
|
||||
fun predecessorRoom(): PredecessorRoom?
|
||||
|
||||
/**
|
||||
* Try to load the room members and update the membersFlow.
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ data class RoomInfo(
|
|||
val avatarUrl: String?,
|
||||
val isPublic: Boolean?,
|
||||
val isDirect: Boolean,
|
||||
val isDm: Boolean,
|
||||
val isEncrypted: Boolean?,
|
||||
val joinRule: JoinRule?,
|
||||
val isSpace: Boolean,
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Element Creations Ltd.
|
||||
* Copyright 2024, 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.room
|
||||
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
||||
/**
|
||||
* Returns whether the room with the provided info is a DM.
|
||||
* A DM is a room with at most 2 active members (one of them may have left).
|
||||
*
|
||||
* @param isDirect true if the room is direct
|
||||
* @param activeMembersCount the number of active members in the room (joined or invited)
|
||||
*/
|
||||
fun isDm(isDirect: Boolean, activeMembersCount: Int): Boolean {
|
||||
return isDirect && activeMembersCount <= 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the [BaseRoom] is a DM, with an updated state from the latest [RoomInfo].
|
||||
*/
|
||||
suspend fun BaseRoom.isDm() = roomInfoFlow.first().isDm
|
||||
|
||||
/**
|
||||
* Returns whether the [RoomInfo] is from a DM.
|
||||
*/
|
||||
val RoomInfo.isDm get() = isDm(isDirect, activeMembersCount.toInt())
|
||||
|
|
@ -22,6 +22,7 @@ data class RoomMember(
|
|||
val isIgnored: Boolean,
|
||||
val role: Role,
|
||||
val membershipChangeReason: String?,
|
||||
val isServiceMember: Boolean,
|
||||
) {
|
||||
/**
|
||||
* Role of the RoomMember, based on its [powerLevel].
|
||||
|
|
|
|||
|
|
@ -40,5 +40,5 @@ fun RoomMembersState.activeRoomMembers(): List<RoomMember> {
|
|||
fun RoomMembersState.getDirectRoomMember(roomInfo: RoomInfo, sessionId: SessionId): RoomMember? {
|
||||
return roomMembers()
|
||||
?.takeIf { roomInfo.isDm }
|
||||
?.find { it.userId != sessionId && it.membership.isActive() }
|
||||
?.find { !it.isServiceMember && it.userId != sessionId && it.membership.isActive() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import io.element.android.libraries.matrix.api.MatrixClient
|
|||
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.CurrentUserMembership
|
||||
import io.element.android.libraries.matrix.api.room.isDm
|
||||
import io.element.android.libraries.matrix.api.room.toMatrixUser
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
|
|
|||
|
|
@ -21,5 +21,5 @@ data class RoomSummary(
|
|||
is LatestEventValue.Remote -> latestEvent.timestamp
|
||||
is LatestEventValue.RoomInvite -> latestEvent.timestamp
|
||||
}
|
||||
val isOneToOne get() = info.activeMembersCount == 2L
|
||||
val isDm = info.isDm
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ data class SpaceRoom(
|
|||
*/
|
||||
val via: ImmutableList<String>,
|
||||
val isDirect: Boolean?,
|
||||
val isDm: Boolean?,
|
||||
) {
|
||||
val isSpace = roomType == RoomType.Space
|
||||
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Element Creations Ltd.
|
||||
* Copyright 2024, 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.room
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Test
|
||||
|
||||
class RoomIsDmCheckTest {
|
||||
@Test
|
||||
fun `a room is a DM only if it has at most 2 members and is direct`() {
|
||||
val isDirect = true
|
||||
val activeMembersCount = 2
|
||||
|
||||
val isDm = isDm(isDirect, activeMembersCount)
|
||||
|
||||
assertThat(isDm).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a room can be a DM if it has also a single active user`() {
|
||||
val isDirect = true
|
||||
val activeMembersCount = 1
|
||||
|
||||
val isDm = isDm(isDirect, activeMembersCount)
|
||||
|
||||
assertThat(isDm).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a room is not a DM if it's not direct`() {
|
||||
val isDirect = false
|
||||
val activeMembersCount = 2
|
||||
|
||||
val isDm = isDm(isDirect, activeMembersCount)
|
||||
|
||||
assertThat(isDm).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a room is not a DM if it has more than 2 active users`() {
|
||||
val isDirect = true
|
||||
val activeMembersCount = 3
|
||||
|
||||
val isDm = isDm(isDirect, activeMembersCount)
|
||||
|
||||
assertThat(isDm).isFalse()
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,7 @@ import org.matrix.rustcomponents.sdk.SlidingSyncVersion
|
|||
import org.matrix.rustcomponents.sdk.SlidingSyncVersionBuilder
|
||||
import org.matrix.rustcomponents.sdk.use
|
||||
import timber.log.Timber
|
||||
import uniffi.matrix_sdk_base.DmRoomDefinition
|
||||
import uniffi.matrix_sdk_base.MediaRetentionPolicy
|
||||
import uniffi.matrix_sdk_crypto.CollectStrategy
|
||||
import uniffi.matrix_sdk_crypto.DecryptionSettings
|
||||
|
|
@ -169,6 +170,7 @@ class RustMatrixClientFactory(
|
|||
)
|
||||
.enableShareHistoryOnInvite(true)
|
||||
.threadsEnabled(featureFlagService.isFeatureEnabled(FeatureFlags.Threads), threadSubscriptions = false)
|
||||
.dmRoomDefinition(DmRoomDefinition.TWO_MEMBERS)
|
||||
.requestConfig(
|
||||
RequestConfig(
|
||||
timeout = 30_000uL,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package io.element.android.libraries.matrix.impl.analytics
|
|||
import im.vector.app.features.analytics.plan.JoinedRoom
|
||||
import io.element.android.libraries.matrix.api.room.BaseRoom
|
||||
import io.element.android.libraries.matrix.api.room.RoomInfo
|
||||
import io.element.android.libraries.matrix.api.room.isDm
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
||||
private fun Long.toAnalyticsRoomSize(): JoinedRoom.RoomSize {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import io.element.android.libraries.matrix.api.core.ThreadId
|
|||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.notification.NotificationContent
|
||||
import io.element.android.libraries.matrix.api.notification.NotificationData
|
||||
import io.element.android.libraries.matrix.api.room.isDm
|
||||
import io.element.android.libraries.matrix.impl.room.join.map
|
||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||
import org.matrix.rustcomponents.sdk.NotificationEvent
|
||||
|
|
@ -37,10 +36,6 @@ class NotificationMapper(
|
|||
): Result<NotificationData> {
|
||||
return runCatchingExceptions {
|
||||
notificationItem.use { item ->
|
||||
val isDm = isDm(
|
||||
isDirect = item.roomInfo.isDirect,
|
||||
activeMembersCount = item.roomInfo.joinedMembersCount.toInt(),
|
||||
)
|
||||
val timestamp = item.timestamp() ?: clock.epochMillis()
|
||||
NotificationData(
|
||||
sessionId = sessionId,
|
||||
|
|
@ -50,10 +45,10 @@ class NotificationMapper(
|
|||
senderAvatarUrl = item.senderInfo.avatarUrl,
|
||||
senderDisplayName = item.senderInfo.displayName,
|
||||
senderIsNameAmbiguous = item.senderInfo.isNameAmbiguous,
|
||||
roomAvatarUrl = item.roomInfo.avatarUrl ?: item.senderInfo.avatarUrl.takeIf { isDm },
|
||||
roomAvatarUrl = item.roomInfo.avatarUrl ?: item.senderInfo.avatarUrl.takeIf { item.roomInfo.isDm },
|
||||
roomDisplayName = item.roomInfo.displayName,
|
||||
isDirect = item.roomInfo.isDirect,
|
||||
isDm = isDm,
|
||||
isDm = item.roomInfo.isDm,
|
||||
isSpace = item.roomInfo.isSpace,
|
||||
isEncrypted = item.roomInfo.isEncrypted.orFalse(),
|
||||
isNoisy = item.isNoisy.orFalse(),
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ class RustNotificationSettingsService(
|
|||
override suspend fun setDefaultRoomNotificationMode(
|
||||
isEncrypted: Boolean,
|
||||
mode: RoomNotificationMode,
|
||||
isOneToOne: Boolean
|
||||
isDM: Boolean
|
||||
): Result<Unit> = withContext(dispatchers.io) {
|
||||
runCatchingExceptions {
|
||||
try {
|
||||
notificationSettings.await().setDefaultRoomNotificationMode(isEncrypted, isOneToOne, mode.let(RoomNotificationSettingsMapper::mapMode))
|
||||
notificationSettings.await().setDefaultRoomNotificationMode(isEncrypted, isDM, mode.let(RoomNotificationSettingsMapper::mapMode))
|
||||
} catch (exception: NotificationSettingsException.RuleNotFound) {
|
||||
// `setDefaultRoomNotificationMode` updates multiple rules including unstable rules (e.g. the polls push rules defined in the MSC3930)
|
||||
// since production home servers may not have these rules yet, we drop the RuleNotFound error
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ class JoinedRustRoom(
|
|||
roomNotificationSettingsStateFlow.value = RoomNotificationSettingsState.Pending(prevRoomNotificationSettings = currentRoomNotificationSettings)
|
||||
runCatchingExceptions {
|
||||
val isEncrypted = roomInfoFlow.value.isEncrypted ?: getUpdatedIsEncrypted().getOrThrow()
|
||||
notificationSettingsService.getRoomNotificationSettings(roomId, isEncrypted, isOneToOne).getOrThrow()
|
||||
notificationSettingsService.getRoomNotificationSettings(roomId = roomId, isEncrypted = isEncrypted, isOneToOne = isDm()).getOrThrow()
|
||||
}.map {
|
||||
roomNotificationSettingsStateFlow.value = RoomNotificationSettingsState.Ready(it)
|
||||
}.onFailure {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import org.matrix.rustcomponents.sdk.RoomInfo
|
|||
*/
|
||||
fun RoomInfo.elementHeroes(): List<MatrixUser> {
|
||||
return heroes
|
||||
.takeIf { isDirect && activeMembersCount.toLong() == 2L }
|
||||
.takeIf { isDm }
|
||||
?.takeIf { it.size == 1 }
|
||||
?.map { it.map() }
|
||||
.orEmpty()
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ class RoomInfoMapper {
|
|||
avatarUrl = it.avatarUrl,
|
||||
isPublic = it.isPublic,
|
||||
isDirect = it.isDirect,
|
||||
isDm = it.isDm,
|
||||
isEncrypted = when (it.encryptionState) {
|
||||
EncryptionState.ENCRYPTED -> true
|
||||
EncryptionState.NOT_ENCRYPTED -> false
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import io.element.android.libraries.matrix.api.room.RoomMember
|
|||
import io.element.android.libraries.matrix.api.room.RoomMembersState
|
||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
||||
import io.element.android.libraries.matrix.api.room.draft.ComposerDraft
|
||||
import io.element.android.libraries.matrix.api.room.isDm
|
||||
import io.element.android.libraries.matrix.api.room.powerlevels.RoomPermissions
|
||||
import io.element.android.libraries.matrix.api.room.powerlevels.RoomPowerLevelsValues
|
||||
import io.element.android.libraries.matrix.api.room.tombstone.PredecessorRoom
|
||||
|
|
@ -119,7 +118,7 @@ class RustBaseRoom(
|
|||
innerRoom.membersNoSync().use { members ->
|
||||
members.nextChunk(members.len())
|
||||
?.map(RoomMemberMapper::map)
|
||||
?.firstOrNull { roomMember -> roomMember.userId != sessionId && roomMember.membership.isActive() }
|
||||
?.firstOrNull { roomMember -> !roomMember.isServiceMember && roomMember.userId != sessionId && roomMember.membership.isActive() }
|
||||
}
|
||||
} else {
|
||||
null
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ object RoomMemberMapper {
|
|||
powerLevel = powerLevel,
|
||||
isIgnored = roomMember.isIgnored,
|
||||
role = mapRole(roomMember.suggestedRoleForPowerLevel, powerLevel),
|
||||
membershipChangeReason = roomMember.membershipChangeReason
|
||||
membershipChangeReason = roomMember.membershipChangeReason,
|
||||
isServiceMember = roomMember.isServiceMember,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class SpaceRoomMapper {
|
|||
worldReadable = spaceRoom.worldReadable.orFalse(),
|
||||
via = spaceRoom.via.toImmutableList(),
|
||||
isDirect = spaceRoom.isDirect,
|
||||
isDm = spaceRoom.isDm,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import io.element.android.libraries.matrix.api.media.VideoInfo
|
|||
import io.element.android.libraries.matrix.api.poll.PollKind
|
||||
import io.element.android.libraries.matrix.api.room.IntentionalMention
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.matrix.api.room.isDm
|
||||
import io.element.android.libraries.matrix.api.room.location.AssetType
|
||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
|
||||
import io.element.android.libraries.matrix.api.timeline.MsgType
|
||||
|
|
|
|||
|
|
@ -43,6 +43,19 @@ class JoinedExtKtTest {
|
|||
@Test
|
||||
fun `test isDirect parameter mapping`() = runTest {
|
||||
assertThat(aRoom(isDirect = true).toAnalyticsJoinedRoom(null))
|
||||
.isEqualTo(
|
||||
JoinedRoom(
|
||||
isDM = false,
|
||||
isSpace = false,
|
||||
roomSize = JoinedRoom.RoomSize.One,
|
||||
trigger = null
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test isDm parameter mapping`() = runTest {
|
||||
assertThat(aRoom(isDm = true).toAnalyticsJoinedRoom(null))
|
||||
.isEqualTo(
|
||||
JoinedRoom(
|
||||
isDM = true,
|
||||
|
|
@ -80,12 +93,13 @@ class JoinedExtKtTest {
|
|||
}
|
||||
|
||||
private fun aRoom(
|
||||
isDm: Boolean = false,
|
||||
isDirect: Boolean = false,
|
||||
isSpace: Boolean = false,
|
||||
joinedMemberCount: Long = 0
|
||||
): FakeBaseRoom {
|
||||
return FakeBaseRoom().apply {
|
||||
givenRoomInfo(aRoomInfo(isDirect = isDirect, isSpace = isSpace, joinedMembersCount = joinedMemberCount))
|
||||
givenRoomInfo(aRoomInfo(isDm = isDm, isDirect = isDirect, isSpace = isSpace, joinedMembersCount = joinedMemberCount))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,5 +50,5 @@ internal fun aRustSpaceRoom(
|
|||
childrenCount = childrenCount,
|
||||
state = state,
|
||||
heroes = heroes,
|
||||
via = emptyList()
|
||||
via = emptyList(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import org.matrix.rustcomponents.sdk.RequestConfig
|
|||
import org.matrix.rustcomponents.sdk.SlidingSyncVersionBuilder
|
||||
import org.matrix.rustcomponents.sdk.SqliteStoreBuilder
|
||||
import uniffi.matrix_sdk.BackupDownloadStrategy
|
||||
import uniffi.matrix_sdk_base.DmRoomDefinition
|
||||
import uniffi.matrix_sdk_crypto.CollectStrategy
|
||||
import uniffi.matrix_sdk_crypto.DecryptionSettings
|
||||
|
||||
|
|
@ -47,5 +48,6 @@ class FakeFfiClientBuilder(
|
|||
override fun sqliteStore(config: SqliteStoreBuilder): ClientBuilder = this
|
||||
override fun inMemoryStore(): ClientBuilder = this
|
||||
override fun crossProcessLockConfig(crossProcessLockConfig: CrossProcessLockConfig): ClientBuilder = this
|
||||
override fun dmRoomDefinition(dmRoomDefinition: DmRoomDefinition): ClientBuilder = this
|
||||
override suspend fun build() = buildResult()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ class RoomInfoExtTest {
|
|||
@Test
|
||||
fun `get non empty element Heroes`() {
|
||||
val result = aRustRoomInfo(
|
||||
isDirect = true,
|
||||
activeMembersCount = 2uL,
|
||||
isDm = true,
|
||||
heroes = listOf(aRustRoomHero())
|
||||
).elementHeroes()
|
||||
assertThat(result).isEqualTo(
|
||||
|
|
@ -38,8 +37,7 @@ class RoomInfoExtTest {
|
|||
@Test
|
||||
fun `too many heroes and element Heroes is empty`() {
|
||||
val result = aRustRoomInfo(
|
||||
isDirect = true,
|
||||
activeMembersCount = 2uL,
|
||||
isDm = true,
|
||||
heroes = listOf(aRustRoomHero(), aRustRoomHero())
|
||||
).elementHeroes()
|
||||
assertThat(result).isEmpty()
|
||||
|
|
@ -48,18 +46,7 @@ class RoomInfoExtTest {
|
|||
@Test
|
||||
fun `not direct and element Heroes is empty`() {
|
||||
val result = aRustRoomInfo(
|
||||
isDirect = false,
|
||||
activeMembersCount = 2uL,
|
||||
heroes = listOf(aRustRoomHero())
|
||||
).elementHeroes()
|
||||
assertThat(result).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `too many members and element Heroes is empty`() {
|
||||
val result = aRustRoomInfo(
|
||||
isDirect = true,
|
||||
activeMembersCount = 3uL,
|
||||
isDm = false,
|
||||
heroes = listOf(aRustRoomHero())
|
||||
).elementHeroes()
|
||||
assertThat(result).isEmpty()
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ class RoomInfoMapperTest {
|
|||
privilegedCreatorsRole = true,
|
||||
isLowPriority = true,
|
||||
activeRoomCallConsensusIntent = RtcCallIntentConsensus.Full(RtcCallIntent.AUDIO),
|
||||
isDm = true,
|
||||
)
|
||||
)
|
||||
).isEqualTo(
|
||||
|
|
@ -136,6 +137,7 @@ class RoomInfoMapperTest {
|
|||
privilegedCreatorRole = true,
|
||||
isLowPriority = true,
|
||||
activeCallIntentConsensus = CallIntentConsensus.Full(CallIntent.AUDIO),
|
||||
isDm = true,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -181,6 +183,7 @@ class RoomInfoMapperTest {
|
|||
privilegedCreatorsRole = true,
|
||||
isLowPriority = true,
|
||||
activeRoomCallConsensusIntent = RtcCallIntentConsensus.None,
|
||||
isDm = false,
|
||||
)
|
||||
)
|
||||
).isEqualTo(
|
||||
|
|
@ -225,6 +228,7 @@ class RoomInfoMapperTest {
|
|||
privilegedCreatorRole = true,
|
||||
isLowPriority = true,
|
||||
activeCallIntentConsensus = CallIntentConsensus.None,
|
||||
isDm = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,12 +70,12 @@ class FakeNotificationSettingsService(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun setDefaultRoomNotificationMode(isEncrypted: Boolean, mode: RoomNotificationMode, isOneToOne: Boolean): Result<Unit> {
|
||||
override suspend fun setDefaultRoomNotificationMode(isEncrypted: Boolean, mode: RoomNotificationMode, isDM: Boolean): Result<Unit> {
|
||||
val error = setDefaultNotificationModeError
|
||||
if (error != null) {
|
||||
return Result.failure(error)
|
||||
}
|
||||
if (isOneToOne) {
|
||||
if (isDM) {
|
||||
if (isEncrypted) {
|
||||
defaultEncryptedOneToOneRoomNotificationMode = mode
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -134,7 +134,11 @@ class FakeJoinedRoom(
|
|||
}
|
||||
|
||||
override suspend fun updateRoomNotificationSettings(): Result<Unit> = simulateLongTask {
|
||||
val notificationSettings = roomNotificationSettingsService.getRoomNotificationSettings(roomId, info().isEncrypted.orFalse(), isOneToOne).getOrThrow()
|
||||
val notificationSettings = roomNotificationSettingsService.getRoomNotificationSettings(
|
||||
roomId = roomId,
|
||||
isEncrypted = info().isEncrypted.orFalse(),
|
||||
isOneToOne = isDm(),
|
||||
).getOrThrow()
|
||||
(roomNotificationSettingsStateFlow as MutableStateFlow).value = RoomNotificationSettingsState.Ready(notificationSettings)
|
||||
return Result.success(Unit)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ fun aRoomInfo(
|
|||
privilegedCreatorRole: Boolean = false,
|
||||
isLowPriority: Boolean = false,
|
||||
activeCallIntentConsensus: CallIntentConsensus = CallIntentConsensus.None,
|
||||
isDm: Boolean = false,
|
||||
) = RoomInfo(
|
||||
id = id,
|
||||
name = name,
|
||||
|
|
@ -109,4 +110,5 @@ fun aRoomInfo(
|
|||
privilegedCreatorRole = privilegedCreatorRole,
|
||||
isLowPriority = isLowPriority,
|
||||
activeCallIntentConsensus = activeCallIntentConsensus,
|
||||
isDm = isDm,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ fun aRoomMember(
|
|||
isIgnored: Boolean = false,
|
||||
role: RoomMember.Role = RoomMember.Role.User,
|
||||
membershipChangeReason: String? = null,
|
||||
isServiceMember: Boolean = false,
|
||||
) = RoomMember(
|
||||
userId = userId,
|
||||
displayName = displayName,
|
||||
|
|
@ -33,6 +34,7 @@ fun aRoomMember(
|
|||
isIgnored = isIgnored,
|
||||
role = role,
|
||||
membershipChangeReason = membershipChangeReason,
|
||||
isServiceMember = isServiceMember,
|
||||
)
|
||||
|
||||
fun aRoomMemberList() = persistentListOf(
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ fun aRoomSummary(
|
|||
privilegedCreatorRole = privilegedCreatorRole,
|
||||
isLowPriority = isLowPriority,
|
||||
activeCallIntentConsensus = activeCallIntentConsensus,
|
||||
isDm = false,
|
||||
),
|
||||
latestEvent = latestEvent,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -30,13 +30,10 @@ class RoomMembersTest {
|
|||
private val roomMember3 = aRoomMember(A_USER_ID_3)
|
||||
|
||||
@Test
|
||||
fun `getDirectRoomMember emits other member for encrypted DM with 2 joined members`() = runTest {
|
||||
fun `getDirectRoomMember emits other member for encrypted DM`() = runTest {
|
||||
val joinedRoom = FakeBaseRoom(
|
||||
sessionId = A_USER_ID,
|
||||
initialRoomInfo = aRoomInfo(
|
||||
isDirect = true,
|
||||
joinedMembersCount = 2,
|
||||
)
|
||||
initialRoomInfo = aRoomInfo(isDm = true, isEncrypted = true)
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
joinedRoom.getDirectRoomMember(
|
||||
|
|
@ -51,7 +48,7 @@ class RoomMembersTest {
|
|||
fun `getDirectRoomMember emit null if the room is not a dm`() = runTest {
|
||||
val joinedRoom = FakeBaseRoom(
|
||||
sessionId = A_USER_ID,
|
||||
initialRoomInfo = aRoomInfo(isDirect = false)
|
||||
initialRoomInfo = aRoomInfo(isDm = false)
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
joinedRoom.getDirectRoomMember(
|
||||
|
|
@ -66,10 +63,7 @@ class RoomMembersTest {
|
|||
fun `getDirectRoomMember emits other member even if the room is not encrypted`() = runTest {
|
||||
val joinedRoom = FakeBaseRoom(
|
||||
sessionId = A_USER_ID,
|
||||
initialRoomInfo = aRoomInfo(
|
||||
isDirect = true,
|
||||
activeMembersCount = 2,
|
||||
)
|
||||
initialRoomInfo = aRoomInfo(isDm = true)
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
joinedRoom.getDirectRoomMember(
|
||||
|
|
@ -80,42 +74,11 @@ class RoomMembersTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getDirectRoomMember emit null if the room has only 1 member`() = runTest {
|
||||
val joinedRoom = FakeBaseRoom(
|
||||
sessionId = A_USER_ID,
|
||||
initialRoomInfo = aRoomInfo(isDirect = true)
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
joinedRoom.getDirectRoomMember(
|
||||
RoomMembersState.Ready(persistentListOf(roomMember1))
|
||||
)
|
||||
}.test {
|
||||
assertThat(awaitItem().value).isNull()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getDirectRoomMember emit null if the room has only 3 members`() = runTest {
|
||||
val joinedRoom = FakeBaseRoom(
|
||||
sessionId = A_USER_ID,
|
||||
).apply {
|
||||
givenRoomInfo(aRoomInfo(isDirect = true, activeMembersCount = 3L))
|
||||
}
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
joinedRoom.getDirectRoomMember(
|
||||
RoomMembersState.Ready(persistentListOf(roomMember1, roomMember2, roomMember3))
|
||||
)
|
||||
}.test {
|
||||
assertThat(awaitItem().value).isNull()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getDirectRoomMember emit null if the other member is not active`() = runTest {
|
||||
val joinedRoom = FakeBaseRoom(
|
||||
sessionId = A_USER_ID,
|
||||
initialRoomInfo = aRoomInfo(isDirect = true),
|
||||
initialRoomInfo = aRoomInfo(isDm = true),
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
joinedRoom.getDirectRoomMember(
|
||||
|
|
@ -135,10 +98,7 @@ class RoomMembersTest {
|
|||
fun `getDirectRoomMember emit the other member if there are 2 active members`() = runTest {
|
||||
val joinedRoom = FakeBaseRoom(
|
||||
sessionId = A_USER_ID,
|
||||
initialRoomInfo = aRoomInfo(
|
||||
isDirect = true,
|
||||
activeMembersCount = 2,
|
||||
)
|
||||
initialRoomInfo = aRoomInfo(isDm = true)
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
joinedRoom.getDirectRoomMember(
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ fun aRoomMember(
|
|||
isIgnored: Boolean = false,
|
||||
role: RoomMember.Role = RoomMember.Role.User,
|
||||
membershipChangeReason: String? = null,
|
||||
isServiceMember: Boolean = false,
|
||||
) = RoomMember(
|
||||
userId = userId,
|
||||
displayName = displayName,
|
||||
|
|
@ -43,6 +44,7 @@ fun aRoomMember(
|
|||
isIgnored = isIgnored,
|
||||
role = role,
|
||||
membershipChangeReason = membershipChangeReason,
|
||||
isServiceMember = isServiceMember,
|
||||
)
|
||||
|
||||
fun aRoomMemberList() = persistentListOf(
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ fun aSpaceRoom(
|
|||
topic: String? = null,
|
||||
worldReadable: Boolean = false,
|
||||
isDirect: Boolean? = null,
|
||||
isDm: Boolean? = null,
|
||||
via: List<String> = emptyList(),
|
||||
) = SpaceRoom(
|
||||
rawName = rawName,
|
||||
|
|
@ -51,5 +52,6 @@ fun aSpaceRoom(
|
|||
topic = topic,
|
||||
worldReadable = worldReadable,
|
||||
via = via.toImmutableList(),
|
||||
isDirect = isDirect
|
||||
isDirect = isDirect,
|
||||
isDm = isDm,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import io.element.android.libraries.matrix.api.core.SessionId
|
|||
import io.element.android.libraries.matrix.api.core.ThreadId
|
||||
import io.element.android.libraries.matrix.api.room.CreateTimelineParams
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.matrix.api.room.isDm
|
||||
import io.element.android.libraries.matrix.api.timeline.ReceiptType
|
||||
import io.element.android.libraries.matrix.api.timeline.Timeline
|
||||
import io.element.android.libraries.preferences.api.store.SessionPreferencesStoreFactory
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue