crypto: Remove the UploadKeysTask copy

This commit is contained in:
Damir Jelić 2021-03-24 16:15:52 +01:00
parent 36451e5410
commit 6bc825b0bc
4 changed files with 6 additions and 50 deletions

View File

@ -71,7 +71,6 @@ import org.matrix.android.sdk.internal.crypto.tasks.DefaultSendToDeviceTask
import org.matrix.android.sdk.internal.crypto.tasks.DefaultSendVerificationMessageTask
import org.matrix.android.sdk.internal.crypto.tasks.DefaultSetDeviceNameTask
import org.matrix.android.sdk.internal.crypto.tasks.DefaultUploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.NewDefaultUploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.DefaultUploadSignaturesTask
import org.matrix.android.sdk.internal.crypto.tasks.DefaultUploadSigningKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.DeleteDeviceTask
@ -85,7 +84,6 @@ import org.matrix.android.sdk.internal.crypto.tasks.SendToDeviceTask
import org.matrix.android.sdk.internal.crypto.tasks.SendVerificationMessageTask
import org.matrix.android.sdk.internal.crypto.tasks.SetDeviceNameTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.NewUploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadSignaturesTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadSigningKeysTask
import org.matrix.android.sdk.internal.database.RealmKeysUtils
@ -177,9 +175,6 @@ internal abstract class CryptoModule {
@Binds
abstract fun bindUploadKeysTask(task: DefaultUploadKeysTask): UploadKeysTask
@Binds
abstract fun bindNewUploadKeysTask(task: NewDefaultUploadKeysTask): NewUploadKeysTask
@Binds
abstract fun bindUploadSigningKeysTask(task: DefaultUploadSigningKeysTask): UploadSigningKeysTask

View File

@ -88,10 +88,9 @@ import org.matrix.android.sdk.internal.crypto.tasks.DeleteDeviceTask
import org.matrix.android.sdk.internal.crypto.tasks.DownloadKeysForUsersTask
import org.matrix.android.sdk.internal.crypto.tasks.GetDeviceInfoTask
import org.matrix.android.sdk.internal.crypto.tasks.GetDevicesTask
import org.matrix.android.sdk.internal.crypto.tasks.NewUploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.SetDeviceNameTask
import org.matrix.android.sdk.internal.crypto.tasks.SendToDeviceTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadKeysTask
import org.matrix.android.sdk.internal.crypto.tasks.ClaimOneTimeKeysForUsersDeviceTask
import org.matrix.android.sdk.internal.crypto.verification.DefaultVerificationService
import org.matrix.android.sdk.internal.di.DeviceId
@ -168,7 +167,6 @@ internal class DefaultCryptoService @Inject constructor(
private val getDeviceInfoTask: GetDeviceInfoTask,
private val setDeviceNameTask: SetDeviceNameTask,
private val uploadKeysTask: UploadKeysTask,
private val newUploadKeysTask: NewUploadKeysTask,
private val loadRoomMembersTask: LoadRoomMembersTask,
private val cryptoSessionInfoProvider: CryptoSessionInfoProvider,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
@ -890,9 +888,9 @@ internal class DefaultCryptoService @Inject constructor(
is Request.KeysUpload -> {
Timber.v("HELLO UPLOADING RUSTY KEYS")
val body = MoshiProvider.providesMoshi().adapter<JsonDict>(Map::class.java).fromJson(outgoingRequest.body)!!
val request = NewUploadKeysTask.Params(body)
val request = UploadKeysTask.Params(body)
val response = newUploadKeysTask.execute(request)
val response = uploadKeysTask.execute(request)
val adapter = MoshiProvider.providesMoshi().adapter<KeysUploadResponse>(KeysUploadResponse::class.java)
val json_response = adapter.toJson(response)!!
olmMachine!!.markRequestAsSent(outgoingRequest.requestId, RequestType.KEYS_UPLOAD, json_response)

View File

@ -56,21 +56,12 @@ internal interface CryptoApi {
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "devices/{deviceId}")
fun getDeviceInfo(@Path("deviceId") deviceId: String): Call<DeviceInfo>
/**
* Upload device and/or one-time keys.
* Doc: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-keys-upload
*
* @param body the keys to be sent.
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload")
fun uploadKeys(@Body body: KeysUploadBody): Call<KeysUploadResponse>
/**
* Upload device and one-time keys
* @param body the keys to be sent.
*/
@POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload")
fun newUploadKeys(@Body body: JsonDict): Call<KeysUploadResponse>
fun UploadKeys(@Body body: JsonDict): Call<KeysUploadResponse>
/**
* Download device keys.

View File

@ -29,10 +29,7 @@ import javax.inject.Inject
internal interface UploadKeysTask : Task<UploadKeysTask.Params, KeysUploadResponse> {
data class Params(
// the device keys to send.
val deviceKeys: DeviceKeys?,
// the one-time keys to send.
val oneTimeKeys: JsonDict?
val body: JsonDict
)
}
@ -42,35 +39,10 @@ internal class DefaultUploadKeysTask @Inject constructor(
) : UploadKeysTask {
override suspend fun execute(params: UploadKeysTask.Params): KeysUploadResponse {
val body = KeysUploadBody(
deviceKeys = params.deviceKeys,
oneTimeKeys = params.oneTimeKeys
)
Timber.i("## Uploading device keys -> $body")
return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.uploadKeys(body)
}
}
}
internal interface NewUploadKeysTask : Task<NewUploadKeysTask.Params, KeysUploadResponse> {
data class Params(
val body: JsonDict
)
}
internal class NewDefaultUploadKeysTask @Inject constructor(
private val cryptoApi: CryptoApi,
private val globalErrorReceiver: GlobalErrorReceiver
) : NewUploadKeysTask {
override suspend fun execute(params: NewUploadKeysTask.Params): KeysUploadResponse {
Timber.i("## Uploading device keys -> $params.body")
return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.newUploadKeys(params.body)
apiCall = cryptoApi.UploadKeys(params.body)
}
}
}