Fix / Move DM shield rules to task
This commit is contained in:
parent
21d0db8382
commit
6ea38c7eb0
@ -46,6 +46,7 @@ Bugfix 🐛:
|
|||||||
- Add user to direct chat by user id (#1065)
|
- Add user to direct chat by user id (#1065)
|
||||||
- Use correct URL for SSO connection (#1178)
|
- Use correct URL for SSO connection (#1178)
|
||||||
- Emoji completion :tada: does not completes to 🎉 like on web (#1285)
|
- Emoji completion :tada: does not completes to 🎉 like on web (#1285)
|
||||||
|
- Fix bad Shield Logic for DM (#963)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
@ -19,6 +19,7 @@ import im.vector.matrix.android.api.crypto.RoomEncryptionTrustLevel
|
|||||||
import im.vector.matrix.android.api.extensions.orFalse
|
import im.vector.matrix.android.api.extensions.orFalse
|
||||||
import im.vector.matrix.android.api.session.crypto.crosssigning.MXCrossSigningInfo
|
import im.vector.matrix.android.api.session.crypto.crosssigning.MXCrossSigningInfo
|
||||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -26,17 +27,29 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
internal interface ComputeTrustTask : Task<ComputeTrustTask.Params, RoomEncryptionTrustLevel> {
|
internal interface ComputeTrustTask : Task<ComputeTrustTask.Params, RoomEncryptionTrustLevel> {
|
||||||
data class Params(
|
data class Params(
|
||||||
val userIds: List<String>
|
val activeMemberUserIds: List<String>,
|
||||||
|
val isDirectRoom: Boolean
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultComputeTrustTask @Inject constructor(
|
internal class DefaultComputeTrustTask @Inject constructor(
|
||||||
private val cryptoStore: IMXCryptoStore,
|
private val cryptoStore: IMXCryptoStore,
|
||||||
|
@UserId private val myUserId: String,
|
||||||
private val coroutineDispatchers: MatrixCoroutineDispatchers
|
private val coroutineDispatchers: MatrixCoroutineDispatchers
|
||||||
) : ComputeTrustTask {
|
) : ComputeTrustTask {
|
||||||
|
|
||||||
override suspend fun execute(params: ComputeTrustTask.Params): RoomEncryptionTrustLevel = withContext(coroutineDispatchers.crypto) {
|
override suspend fun execute(params: ComputeTrustTask.Params): RoomEncryptionTrustLevel = withContext(coroutineDispatchers.crypto) {
|
||||||
val allTrustedUserIds = params.userIds
|
|
||||||
|
// The set of “all users” depends on the type of room:
|
||||||
|
// For regular / topic rooms, all users including yourself, are considered when decorating a room
|
||||||
|
// For 1:1 and group DM rooms, all other users (i.e. excluding yourself) are considered when decorating a room
|
||||||
|
val listToCheck = if (params.isDirectRoom) {
|
||||||
|
params.activeMemberUserIds.filter { it != myUserId }
|
||||||
|
} else {
|
||||||
|
params.activeMemberUserIds
|
||||||
|
}
|
||||||
|
|
||||||
|
val allTrustedUserIds = listToCheck
|
||||||
.filter { userId -> getUserCrossSigningKeys(userId)?.isTrusted() == true }
|
.filter { userId -> getUserCrossSigningKeys(userId)?.isTrusted() == true }
|
||||||
|
|
||||||
if (allTrustedUserIds.isEmpty()) {
|
if (allTrustedUserIds.isEmpty()) {
|
||||||
@ -60,7 +73,7 @@ internal class DefaultComputeTrustTask @Inject constructor(
|
|||||||
if (hasWarning) {
|
if (hasWarning) {
|
||||||
RoomEncryptionTrustLevel.Warning
|
RoomEncryptionTrustLevel.Warning
|
||||||
} else {
|
} else {
|
||||||
if (params.userIds.size == allTrustedUserIds.size) {
|
if (listToCheck.size == allTrustedUserIds.size) {
|
||||||
// all users are trusted and all devices are verified
|
// all users are trusted and all devices are verified
|
||||||
RoomEncryptionTrustLevel.Trusted
|
RoomEncryptionTrustLevel.Trusted
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,6 +17,7 @@ package im.vector.matrix.android.internal.crypto.crosssigning
|
|||||||
|
|
||||||
data class SessionToCryptoRoomMembersUpdate(
|
data class SessionToCryptoRoomMembersUpdate(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
|
val isDirect: Boolean,
|
||||||
val userIds: List<String>
|
val userIds: List<String>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ internal class ShieldTrustUpdater @Inject constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
taskExecutor.executorScope.launch(BACKGROUND_HANDLER_DISPATCHER) {
|
taskExecutor.executorScope.launch(BACKGROUND_HANDLER_DISPATCHER) {
|
||||||
val updatedTrust = computeTrustTask.execute(ComputeTrustTask.Params(update.userIds))
|
val updatedTrust = computeTrustTask.execute(ComputeTrustTask.Params(update.userIds, update.isDirect))
|
||||||
// We need to send that back to session base
|
// We need to send that back to session base
|
||||||
backgroundSessionRealm.get()?.executeTransaction { realm ->
|
backgroundSessionRealm.get()?.executeTransaction { realm ->
|
||||||
roomSummaryUpdater.updateShieldTrust(realm, update.roomId, updatedTrust)
|
roomSummaryUpdater.updateShieldTrust(realm, update.roomId, updatedTrust)
|
||||||
@ -109,8 +109,9 @@ internal class ShieldTrustUpdater @Inject constructor(
|
|||||||
if (roomSummary?.isEncrypted.orFalse()) {
|
if (roomSummary?.isEncrypted.orFalse()) {
|
||||||
val allActiveRoomMembers = RoomMemberHelper(realm, roomId).getActiveRoomMemberIds()
|
val allActiveRoomMembers = RoomMemberHelper(realm, roomId).getActiveRoomMemberIds()
|
||||||
try {
|
try {
|
||||||
// Can throw if the crypto database has been closed in between, in this case log and ignore?
|
val updatedTrust = computeTrustTask.execute(
|
||||||
val updatedTrust = computeTrustTask.execute(ComputeTrustTask.Params(allActiveRoomMembers))
|
ComputeTrustTask.Params(allActiveRoomMembers, roomSummary?.isDirect == true)
|
||||||
|
)
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
roomSummaryUpdater.updateShieldTrust(it, roomId, updatedTrust)
|
roomSummaryUpdater.updateShieldTrust(it, roomId, updatedTrust)
|
||||||
}
|
}
|
||||||
|
@ -161,15 +161,7 @@ internal class RoomSummaryUpdater @Inject constructor(
|
|||||||
roomSummaryEntity.otherMemberIds.clear()
|
roomSummaryEntity.otherMemberIds.clear()
|
||||||
roomSummaryEntity.otherMemberIds.addAll(otherRoomMembers)
|
roomSummaryEntity.otherMemberIds.addAll(otherRoomMembers)
|
||||||
if (roomSummaryEntity.isEncrypted) {
|
if (roomSummaryEntity.isEncrypted) {
|
||||||
// The set of “all users” depends on the type of room:
|
eventBus.post(SessionToCryptoRoomMembersUpdate(roomId, roomSummaryEntity.isDirect, roomSummaryEntity.otherMemberIds.toList() + userId))
|
||||||
// For regular / topic rooms, all users including yourself, are considered when decorating a room
|
|
||||||
// For 1:1 and group DM rooms, all other users (i.e. excluding yourself) are considered when decorating a room
|
|
||||||
val listToCheck = if (roomSummaryEntity.isDirect) {
|
|
||||||
roomSummaryEntity.otherMemberIds.toList()
|
|
||||||
} else {
|
|
||||||
roomSummaryEntity.otherMemberIds.toList() + userId
|
|
||||||
}
|
|
||||||
eventBus.post(SessionToCryptoRoomMembersUpdate(roomId, listToCheck))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user