Moar cleanup after rebase and before merge

This commit is contained in:
Benoit Marty 2021-03-02 19:18:19 +01:00
parent 91872fe673
commit 5c9750fb07
5 changed files with 35 additions and 41 deletions

View file

@ -10,6 +10,7 @@ Improvements 🙌:
- Improve initial sync performance (#983)
- PIP support for Jitsi call (#2418)
- Add tooltip for room quick actions
- Pre-share session keys when opening a room or start typing (#2771)
Bugfix 🐛:
- Try to fix crash about UrlPreview (#2640)
@ -41,7 +42,6 @@ Improvements 🙌:
- Improve room profile UX
- Upgrade Jitsi library from 2.9.3 to 3.1.0
- a11y improvements
- Pre-share session keys when opening a room or start typing (#2771)
Bugfix 🐛:
- VoIP : fix audio devices output

View file

@ -33,7 +33,6 @@ interface RoomCryptoService {
/**
* Ensures all members of the room are loaded and outbound session keys are shared.
* Call this method according to [OutboundSessionKeySharingStrategy].
* If this method is not called, CryptoService will ensure it before sending events.
*/
suspend fun prepareToEncrypt()

View file

@ -18,8 +18,6 @@ package org.matrix.android.sdk.internal.crypto.algorithms.megolm
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.events.model.Event
@ -40,8 +38,6 @@ import org.matrix.android.sdk.internal.crypto.model.forEach
import org.matrix.android.sdk.internal.crypto.repository.WarnOnUnknownDeviceRepository
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
import org.matrix.android.sdk.internal.crypto.tasks.SendToDeviceTask
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith
import org.matrix.android.sdk.internal.util.JsonCanonicalizer
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
import org.matrix.android.sdk.internal.util.convertToUTF8
@ -55,11 +51,11 @@ internal class MXMegolmEncryption(
private val cryptoStore: IMXCryptoStore,
private val deviceListManager: DeviceListManager,
private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction,
private val credentials: Credentials,
private val userId: String,
private val deviceId: String,
private val sendToDeviceTask: SendToDeviceTask,
private val messageEncrypter: MessageEncrypter,
private val warnOnUnknownDevicesRepository: WarnOnUnknownDeviceRepository,
private val taskExecutor: TaskExecutor,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val cryptoCoroutineScope: CoroutineScope
) : IMXEncrypting, IMXGroupEncryption {
@ -282,7 +278,7 @@ internal class MXMegolmEncryption(
gossipingEventBuffer.add(
Event(
type = EventType.ROOM_KEY,
senderId = credentials.userId,
senderId = this.userId,
content = submap.apply {
this["session_key"] = ""
// we add a fake key for trail
@ -310,8 +306,11 @@ internal class MXMegolmEncryption(
}
}
private fun notifyKeyWithHeld(targets: List<UserDevice>, sessionId: String, senderKey: String?, code: WithHeldCode) {
Timber.i("## CRYPTO | notifyKeyWithHeld() :sending withheld key for $targets session:$sessionId and code $code ")
private suspend fun notifyKeyWithHeld(targets: List<UserDevice>,
sessionId: String,
senderKey: String?,
code: WithHeldCode) {
Timber.i("## CRYPTO | notifyKeyWithHeld() :sending withheld key for $targets session:$sessionId and code $code")
val withHeldContent = RoomKeyWithHeldContent(
roomId = roomId,
senderKey = senderKey,
@ -327,14 +326,12 @@ internal class MXMegolmEncryption(
}
}
)
sendToDeviceTask.configureWith(params) {
callback = object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) {
try {
sendToDeviceTask.execute(params)
} catch (failure: Throwable) {
Timber.e("## CRYPTO | notifyKeyWithHeld() : Failed to notify withheld key for $targets session: $sessionId ")
}
}
}.executeBy(taskExecutor)
}
/**
* process the pending encryptions
@ -359,7 +356,7 @@ internal class MXMegolmEncryption(
// Include our device ID so that recipients can send us a
// m.new_device message if they don't have our session key.
map["device_id"] = credentials.deviceId!!
map["device_id"] = deviceId
session.useCount++
return map
}

View file

@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.crypto.algorithms.megolm
import kotlinx.coroutines.CoroutineScope
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.internal.crypto.DeviceListManager
import org.matrix.android.sdk.internal.crypto.MXOlmDevice
import org.matrix.android.sdk.internal.crypto.actions.EnsureOlmSessionsForDevicesAction
@ -26,7 +25,8 @@ import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupServic
import org.matrix.android.sdk.internal.crypto.repository.WarnOnUnknownDeviceRepository
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
import org.matrix.android.sdk.internal.crypto.tasks.SendToDeviceTask
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.di.DeviceId
import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
import javax.inject.Inject
@ -36,29 +36,29 @@ internal class MXMegolmEncryptionFactory @Inject constructor(
private val cryptoStore: IMXCryptoStore,
private val deviceListManager: DeviceListManager,
private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction,
private val credentials: Credentials,
@UserId private val userId: String,
@DeviceId private val deviceId: String?,
private val sendToDeviceTask: SendToDeviceTask,
private val messageEncrypter: MessageEncrypter,
private val warnOnUnknownDevicesRepository: WarnOnUnknownDeviceRepository,
private val taskExecutor: TaskExecutor,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val cryptoCoroutineScope: CoroutineScope) {
fun create(roomId: String): MXMegolmEncryption {
return MXMegolmEncryption(
roomId,
olmDevice,
defaultKeysBackupService,
cryptoStore,
deviceListManager,
ensureOlmSessionsForDevicesAction,
credentials,
sendToDeviceTask,
messageEncrypter,
warnOnUnknownDevicesRepository,
taskExecutor,
coroutineDispatchers,
cryptoCoroutineScope
roomId = roomId,
olmDevice = olmDevice,
defaultKeysBackupService = defaultKeysBackupService,
cryptoStore = cryptoStore,
deviceListManager = deviceListManager,
ensureOlmSessionsForDevicesAction = ensureOlmSessionsForDevicesAction,
userId = userId,
deviceId = deviceId!!,
sendToDeviceTask = sendToDeviceTask,
messageEncrypter = messageEncrypter,
warnOnUnknownDevicesRepository = warnOnUnknownDevicesRepository,
coroutineDispatchers = coroutineDispatchers,
cryptoCoroutineScope = cryptoCoroutineScope
)
}
}

View file

@ -195,11 +195,11 @@ class RoomDetailViewModel @AssistedInject constructor(
}
private fun prepareForEncryption() {
// check if there is not already a call made
if (prepareToEncrypt !is Loading) {
// check if there is not already a call made, or if there has been an error
if (prepareToEncrypt.shouldLoad) {
prepareToEncrypt = Loading()
viewModelScope.launch {
kotlin.runCatching {
runCatching {
room.prepareToEncrypt()
}.fold({
prepareToEncrypt = Success(Unit)
@ -629,8 +629,6 @@ class RoomDetailViewModel @AssistedInject constructor(
if (action.focused) {
// Should we add some rate limit here, or do it only once per model lifecycle?
prepareForEncryption()
} else {
// we could eventually cancel here :/
}
}
}