mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Convert UploadsService to suspend functions
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
This commit is contained in:
parent
4c599d3d40
commit
a3a2c0a9a8
3 changed files with 4 additions and 21 deletions
|
@ -16,9 +16,6 @@
|
|||
|
||||
package org.matrix.android.sdk.api.session.room.uploads
|
||||
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
|
||||
/**
|
||||
* This interface defines methods to get event with uploads (= attachments) sent to a room. It's implemented at the room level.
|
||||
*/
|
||||
|
@ -29,7 +26,5 @@ interface UploadsService {
|
|||
* @param numberOfEvents the expected number of events to retrieve. The result can contain less events.
|
||||
* @param since token to get next page, or null to get the first page
|
||||
*/
|
||||
fun getUploads(numberOfEvents: Int,
|
||||
since: String?,
|
||||
callback: MatrixCallback<GetUploadsResult>): Cancelable
|
||||
suspend fun getUploads(numberOfEvents: Int, since: String?): GetUploadsResult
|
||||
}
|
||||
|
|
|
@ -18,17 +18,12 @@ package org.matrix.android.sdk.internal.session.room.uploads
|
|||
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import org.matrix.android.sdk.api.MatrixCallback
|
||||
import org.matrix.android.sdk.api.session.crypto.CryptoService
|
||||
import org.matrix.android.sdk.api.session.room.uploads.GetUploadsResult
|
||||
import org.matrix.android.sdk.api.session.room.uploads.UploadsService
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
import org.matrix.android.sdk.internal.task.TaskExecutor
|
||||
import org.matrix.android.sdk.internal.task.configureWith
|
||||
|
||||
internal class DefaultUploadsService @AssistedInject constructor(
|
||||
@Assisted private val roomId: String,
|
||||
private val taskExecutor: TaskExecutor,
|
||||
private val getUploadsTask: GetUploadsTask,
|
||||
private val cryptoService: CryptoService
|
||||
) : UploadsService {
|
||||
|
@ -38,11 +33,7 @@ internal class DefaultUploadsService @AssistedInject constructor(
|
|||
fun create(roomId: String): UploadsService
|
||||
}
|
||||
|
||||
override fun getUploads(numberOfEvents: Int, since: String?, callback: MatrixCallback<GetUploadsResult>): Cancelable {
|
||||
return getUploadsTask
|
||||
.configureWith(GetUploadsTask.Params(roomId, cryptoService.isRoomEncrypted(roomId), numberOfEvents, since)) {
|
||||
this.callback = callback
|
||||
}
|
||||
.executeBy(taskExecutor)
|
||||
override suspend fun getUploads(numberOfEvents: Int, since: String?): GetUploadsResult {
|
||||
return getUploadsTask.execute(GetUploadsTask.Params(roomId, cryptoService.isRoomEncrypted(roomId), numberOfEvents, since))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.matrix.android.sdk.api.session.Session
|
|||
import org.matrix.android.sdk.api.session.file.FileService
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageType
|
||||
import org.matrix.android.sdk.api.session.room.model.message.getFileUrl
|
||||
import org.matrix.android.sdk.api.session.room.uploads.GetUploadsResult
|
||||
import org.matrix.android.sdk.internal.crypto.attachments.toElementToDecrypt
|
||||
import org.matrix.android.sdk.internal.util.awaitCallback
|
||||
import org.matrix.android.sdk.rx.rx
|
||||
|
@ -90,9 +89,7 @@ class RoomUploadsViewModel @AssistedInject constructor(
|
|||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val result = awaitCallback<GetUploadsResult> {
|
||||
room.getUploads(20, token, it)
|
||||
}
|
||||
val result = room.getUploads(20, token)
|
||||
|
||||
token = result.nextToken
|
||||
|
||||
|
|
Loading…
Reference in a new issue