forked from GitHub-Mirror/riotX-android
Perf: try to get better
This commit is contained in:
@ -25,6 +25,7 @@ import android.text.TextUtils
|
||||
import arrow.core.Try
|
||||
import com.squareup.moshi.Types
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import dagger.Lazy
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
@ -98,7 +99,7 @@ internal class CryptoManager @Inject constructor(
|
||||
private val olmManager: OlmManager,
|
||||
// The credentials,
|
||||
private val credentials: Credentials,
|
||||
private val myDeviceInfoHolder: MyDeviceInfoHolder,
|
||||
private val myDeviceInfoHolder: Lazy<MyDeviceInfoHolder>,
|
||||
// the crypto store
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
// Olm device
|
||||
@ -190,7 +191,7 @@ internal class CryptoManager @Inject constructor(
|
||||
}
|
||||
|
||||
override fun getMyDevice(): MXDeviceInfo {
|
||||
return myDeviceInfoHolder.myDevice
|
||||
return myDeviceInfoHolder.get().myDevice
|
||||
}
|
||||
|
||||
override fun getDevicesList(callback: MatrixCallback<DevicesListResponse>) {
|
||||
|
@ -18,6 +18,7 @@ package im.vector.matrix.android.internal.crypto.verification
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import dagger.Lazy
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
@ -55,7 +56,7 @@ import kotlin.collections.HashMap
|
||||
@SessionScope
|
||||
internal class DefaultSasVerificationService @Inject constructor(private val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val myDeviceInfoHolder: MyDeviceInfoHolder,
|
||||
private val myDeviceInfoHolder: Lazy<MyDeviceInfoHolder>,
|
||||
private val deviceListManager: DeviceListManager,
|
||||
private val setDeviceVerificationAction: SetDeviceVerificationAction,
|
||||
private val sendToDeviceTask: SendToDeviceTask,
|
||||
@ -197,7 +198,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
||||
cryptoStore,
|
||||
sendToDeviceTask,
|
||||
taskExecutor,
|
||||
myDeviceInfoHolder.myDevice.fingerprint()!!,
|
||||
myDeviceInfoHolder.get().myDevice.fingerprint()!!,
|
||||
startReq.transactionID!!,
|
||||
otherUserId)
|
||||
addTransaction(tx)
|
||||
@ -366,7 +367,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
||||
cryptoStore,
|
||||
sendToDeviceTask,
|
||||
taskExecutor,
|
||||
myDeviceInfoHolder.myDevice.fingerprint()!!,
|
||||
myDeviceInfoHolder.get().myDevice.fingerprint()!!,
|
||||
txID,
|
||||
userId,
|
||||
deviceID)
|
||||
|
@ -48,58 +48,7 @@ internal class DefaultPushRuleService @Inject constructor(
|
||||
|
||||
override fun fetchPushRules(scope: String) {
|
||||
pushRulesTask
|
||||
.configureWith(Unit)
|
||||
.dispatchTo(object : MatrixCallback<GetPushRulesResponse> {
|
||||
override fun onSuccess(data: GetPushRulesResponse) {
|
||||
monarchy.runTransactionSync { realm ->
|
||||
//clear existings?
|
||||
//TODO
|
||||
realm.where(PushRulesEntity::class.java)
|
||||
.equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId)
|
||||
.findAll().deleteAllFromRealm()
|
||||
|
||||
val content = PushRulesEntity(sessionParams.credentials.userId, scope, "content")
|
||||
data.global.content?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
content.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(content)
|
||||
|
||||
val override = PushRulesEntity(sessionParams.credentials.userId, scope, "override")
|
||||
data.global.override?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
override.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(override)
|
||||
|
||||
val rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room")
|
||||
data.global.room?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
rooms.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(rooms)
|
||||
|
||||
val senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender")
|
||||
data.global.sender?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
senders.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(senders)
|
||||
|
||||
val underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride")
|
||||
data.global.underride?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
underrides.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(underrides)
|
||||
}
|
||||
}
|
||||
})
|
||||
.configureWith(GetPushRulesTask.Params(scope))
|
||||
.executeBy(taskExecutor)
|
||||
}
|
||||
|
||||
|
@ -54,22 +54,6 @@ internal class DefaultPusherService @Inject constructor(
|
||||
override fun refreshPushers() {
|
||||
getPusherTask
|
||||
.configureWith(Unit)
|
||||
.dispatchTo(object : MatrixCallback<GetPushersResponse> {
|
||||
override fun onSuccess(data: GetPushersResponse) {
|
||||
monarchy.runTransactionSync { realm ->
|
||||
//clear existings?
|
||||
realm.where(PusherEntity::class.java)
|
||||
.equalTo(PusherEntityFields.USER_ID, sessionParam.credentials.userId)
|
||||
.findAll().deleteAllFromRealm()
|
||||
data.pushers?.forEach { jsonPusher ->
|
||||
jsonPusher.toEntity(sessionParam.credentials.userId).also {
|
||||
it.state = PusherState.REGISTERED
|
||||
realm.insertOrUpdate(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.executeBy(taskExecutor)
|
||||
}
|
||||
|
||||
|
@ -16,19 +16,81 @@
|
||||
package im.vector.matrix.android.internal.session.pushers
|
||||
|
||||
import arrow.core.Try
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse
|
||||
import im.vector.matrix.android.internal.database.mapper.PushRulesMapper
|
||||
import im.vector.matrix.android.internal.database.model.PushRulesEntity
|
||||
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
internal interface GetPushRulesTask : Task<Unit, GetPushRulesResponse>
|
||||
internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> {
|
||||
|
||||
internal class DefaultGetPushRulesTask @Inject constructor(private val pushRulesApi: PushRulesApi) : GetPushRulesTask {
|
||||
data class Params(val scope: String)
|
||||
|
||||
override suspend fun execute(params: Unit): Try<GetPushRulesResponse> {
|
||||
return executeRequest {
|
||||
}
|
||||
|
||||
|
||||
internal class DefaultGetPushRulesTask @Inject constructor(private val pushRulesApi: PushRulesApi,
|
||||
private val monarchy: Monarchy,
|
||||
private val sessionParams: SessionParams) : GetPushRulesTask {
|
||||
|
||||
override suspend fun execute(params: GetPushRulesTask.Params): Try<Unit> {
|
||||
return executeRequest<GetPushRulesResponse> {
|
||||
apiCall = pushRulesApi.getAllRules()
|
||||
}.flatMap { response ->
|
||||
val scope = params.scope
|
||||
return monarchy.tryTransactionSync { realm ->
|
||||
//clear existings?
|
||||
//TODO
|
||||
realm.where(PushRulesEntity::class.java)
|
||||
.equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId)
|
||||
.findAll().deleteAllFromRealm()
|
||||
|
||||
val content = PushRulesEntity(sessionParams.credentials.userId, scope, "content")
|
||||
response.global.content?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
content.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(content)
|
||||
|
||||
val override = PushRulesEntity(sessionParams.credentials.userId, scope, "override")
|
||||
response.global.override?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
override.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(override)
|
||||
|
||||
val rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room")
|
||||
response.global.room?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
rooms.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(rooms)
|
||||
|
||||
val senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender")
|
||||
response.global.sender?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
senders.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(senders)
|
||||
|
||||
val underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride")
|
||||
response.global.underride?.forEach { rule ->
|
||||
PushRulesMapper.map(rule).also {
|
||||
underrides.pushRules.add(it)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(underrides)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,17 +16,39 @@
|
||||
package im.vector.matrix.android.internal.session.pushers
|
||||
|
||||
import arrow.core.Try
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.session.pushers.PusherState
|
||||
import im.vector.matrix.android.internal.database.mapper.toEntity
|
||||
import im.vector.matrix.android.internal.database.model.PusherEntity
|
||||
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
||||
import im.vector.matrix.android.internal.network.executeRequest
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface GetPushersTask : Task<Unit, GetPushersResponse>
|
||||
internal interface GetPushersTask : Task<Unit, Unit>
|
||||
|
||||
internal class DefaultGetPusherTask @Inject constructor(private val pushersAPI: PushersAPI) : GetPushersTask {
|
||||
internal class DefaultGetPusherTask @Inject constructor(private val pushersAPI: PushersAPI,
|
||||
private val monarchy: Monarchy,
|
||||
private val sessionParams: SessionParams) : GetPushersTask {
|
||||
|
||||
override suspend fun execute(params: Unit): Try<GetPushersResponse> {
|
||||
return executeRequest {
|
||||
override suspend fun execute(params: Unit): Try<Unit> {
|
||||
return executeRequest<GetPushersResponse> {
|
||||
apiCall = pushersAPI.getPushers()
|
||||
}.flatMap { response ->
|
||||
monarchy.tryTransactionSync { realm ->
|
||||
//clear existings?
|
||||
realm.where(PusherEntity::class.java)
|
||||
.equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId)
|
||||
.findAll().deleteAllFromRealm()
|
||||
response.pushers?.forEach { jsonPusher ->
|
||||
jsonPusher.toEntity(sessionParams.credentials.userId).also {
|
||||
it.state = PusherState.REGISTERED
|
||||
realm.insertOrUpdate(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user