Skip to content

Commit

Permalink
feat: Get transfer flow from TransferManager
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Nov 13, 2024
1 parent 0375bd9 commit 503ab7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class TransferManager internal constructor(
.flowOn(Dispatchers.IO)
}

@Throws(RealmException::class)
fun getTransferFlow(transferUUID: String): Flow<Transfer?> {
return transferController.getTransferFlow(transferUUID)
}

/**
* Update all pending transfers in database, most transfers are in [TransferStatus.WAIT_VIRUS_CHECK] status.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.TransferStatus
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider
import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB
import com.infomaniak.multiplatform_swisstransfer.database.utils.RealmUtils.runThrowingRealm
import io.realm.kotlin.Realm
import io.realm.kotlin.UpdatePolicy
import io.realm.kotlin.ext.query
import io.realm.kotlin.query.RealmResults
import io.realm.kotlin.query.RealmSingleQuery
import io.realm.kotlin.query.Sort
import io.realm.kotlin.query.TRUE_PREDICATE
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -55,9 +57,14 @@ class TransferController(private val realmProvider: RealmProvider) {
return getTransfers(transferDirection).asFlow().mapLatest { it.list }
}

@Throws(RealmException::class)
fun getTransferFlow(linkUUID: String): Flow<TransferDB?> = runThrowingRealm {
return getTransferQuery(realm, linkUUID).asFlow().mapLatest { it.obj }
}

@Throws(RealmException::class)
fun getTransfer(linkUUID: String): Transfer? = runThrowingRealm {
return realm.query<TransferDB>("${TransferDB::linkUUID.name} == '$linkUUID'").first().find()
return getTransferQuery(realm, linkUUID).find()
}

@Throws(RealmException::class)
Expand Down Expand Up @@ -93,4 +100,11 @@ class TransferController(private val realmProvider: RealmProvider) {
realm.write { deleteAll() }
}
//endregion

private companion object {

private fun getTransferQuery(realm: Realm, linkUUID: String): RealmSingleQuery<TransferDB> {
return realm.query<TransferDB>("${TransferDB::linkUUID.name} == '$linkUUID'").first()
}
}
}

0 comments on commit 503ab7d

Please sign in to comment.