mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Update the Matrix client info when configuring the Session
This commit is contained in:
parent
0c6d49856c
commit
c0e9d5124c
4 changed files with 42 additions and 42 deletions
|
@ -19,6 +19,7 @@ package im.vector.app.core.session
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import im.vector.app.core.extensions.startSyncing
|
import im.vector.app.core.extensions.startSyncing
|
||||||
|
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.sync.FilterService
|
import org.matrix.android.sdk.api.session.sync.FilterService
|
||||||
|
@ -28,6 +29,7 @@ import javax.inject.Inject
|
||||||
class ConfigureAndStartSessionUseCase @Inject constructor(
|
class ConfigureAndStartSessionUseCase @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val webRtcCallManager: WebRtcCallManager,
|
private val webRtcCallManager: WebRtcCallManager,
|
||||||
|
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// TODO add unit tests
|
// TODO add unit tests
|
||||||
|
@ -40,5 +42,6 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
|
||||||
}
|
}
|
||||||
session.pushersService().refreshPushers()
|
session.pushersService().refreshPushers()
|
||||||
webRtcCallManager.checkForProtocolsSupportIfNeeded()
|
webRtcCallManager.checkForProtocolsSupportIfNeeded()
|
||||||
|
updateMatrixClientInfoUseCase.execute(session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package im.vector.app.core.session.clientinfo
|
package im.vector.app.core.session.clientinfo
|
||||||
|
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -24,17 +24,11 @@ import javax.inject.Inject
|
||||||
* This use case retrieves the current account data event containing extended client info
|
* This use case retrieves the current account data event containing extended client info
|
||||||
* for a given deviceId.
|
* for a given deviceId.
|
||||||
*/
|
*/
|
||||||
class GetMatrixClientInfoUseCase @Inject constructor(
|
class GetMatrixClientInfoUseCase @Inject constructor() {
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
|
||||||
) {
|
|
||||||
|
|
||||||
fun execute(deviceId: String): MatrixClientInfoContent? {
|
fun execute(session: Session, deviceId: String): MatrixClientInfoContent? {
|
||||||
return activeSessionHolder
|
|
||||||
.getSafeActiveSession()
|
|
||||||
?.let { session ->
|
|
||||||
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + deviceId
|
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + deviceId
|
||||||
val content = session.accountDataService().getUserAccountDataEvent(type)?.content
|
val content = session.accountDataService().getUserAccountDataEvent(type)?.content
|
||||||
content.toModel()
|
return content.toModel()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,20 +16,16 @@
|
||||||
|
|
||||||
package im.vector.app.core.session.clientinfo
|
package im.vector.app.core.session.clientinfo
|
||||||
|
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This use case sets the account data event containing extended client info.
|
* This use case sets the account data event containing extended client info.
|
||||||
*/
|
*/
|
||||||
class SetMatrixClientInfoUseCase @Inject constructor(
|
class SetMatrixClientInfoUseCase @Inject constructor() {
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
|
||||||
) {
|
|
||||||
|
|
||||||
suspend fun execute(clientInfo: MatrixClientInfoContent): Result<Unit> = runCatching {
|
suspend fun execute(session: Session, clientInfo: MatrixClientInfoContent): Result<Unit> = runCatching {
|
||||||
activeSessionHolder.getSafeActiveSession()
|
|
||||||
?.let { session ->
|
|
||||||
val deviceId = session.sessionParams.deviceId.orEmpty()
|
val deviceId = session.sessionParams.deviceId.orEmpty()
|
||||||
if (deviceId.isNotEmpty()) {
|
if (deviceId.isNotEmpty()) {
|
||||||
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + deviceId
|
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + deviceId
|
||||||
|
@ -40,4 +36,3 @@ class SetMatrixClientInfoUseCase @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -16,35 +16,43 @@
|
||||||
|
|
||||||
package im.vector.app.core.session.clientinfo
|
package im.vector.app.core.session.clientinfo
|
||||||
|
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
|
||||||
import im.vector.app.core.resources.AppNameProvider
|
import im.vector.app.core.resources.AppNameProvider
|
||||||
import im.vector.app.core.resources.BuildMeta
|
import im.vector.app.core.resources.BuildMeta
|
||||||
|
import im.vector.app.features.session.coroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This use case updates if needed the account data event containing extended client info.
|
* This use case updates if needed the account data event containing extended client info.
|
||||||
*/
|
*/
|
||||||
class UpdateMatrixClientInfoUseCase @Inject constructor(
|
class UpdateMatrixClientInfoUseCase @Inject constructor(
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
|
||||||
private val appNameProvider: AppNameProvider,
|
private val appNameProvider: AppNameProvider,
|
||||||
private val buildMeta: BuildMeta,
|
private val buildMeta: BuildMeta,
|
||||||
private val getMatrixClientInfoUseCase: GetMatrixClientInfoUseCase,
|
private val getMatrixClientInfoUseCase: GetMatrixClientInfoUseCase,
|
||||||
private val setMatrixClientInfoUseCase: SetMatrixClientInfoUseCase,
|
private val setMatrixClientInfoUseCase: SetMatrixClientInfoUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun execute(): Result<Unit> = runCatching {
|
fun execute(session: Session) {
|
||||||
|
session.coroutineScope.launch {
|
||||||
|
runCatching {
|
||||||
val clientInfo = MatrixClientInfoContent(
|
val clientInfo = MatrixClientInfoContent(
|
||||||
name = appNameProvider.getAppName(),
|
name = appNameProvider.getAppName(),
|
||||||
version = buildMeta.versionName
|
version = buildMeta.versionName
|
||||||
)
|
)
|
||||||
val deviceId = activeSessionHolder.getActiveSession().sessionParams.deviceId.orEmpty()
|
val deviceId = session.sessionParams.deviceId.orEmpty()
|
||||||
if (deviceId.isNotEmpty()) {
|
if (deviceId.isNotEmpty()) {
|
||||||
val storedClientInfo = getMatrixClientInfoUseCase.execute(deviceId)
|
val storedClientInfo = getMatrixClientInfoUseCase.execute(session, deviceId)
|
||||||
|
Timber.d("storedClientInfo=$storedClientInfo, current client info=$clientInfo")
|
||||||
if (clientInfo != storedClientInfo) {
|
if (clientInfo != storedClientInfo) {
|
||||||
setMatrixClientInfoUseCase.execute(clientInfo)
|
Timber.d("client info need to be updated")
|
||||||
|
setMatrixClientInfoUseCase.execute(session, clientInfo)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw NoDeviceIdError()
|
throw NoDeviceIdError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue