mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Dagger: create @UserId to inject userId
This commit is contained in:
parent
5651ea515b
commit
acd7a709de
@ -20,7 +20,6 @@ import android.util.Patterns
|
|||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import im.vector.matrix.android.api.MatrixPatterns.isUserId
|
import im.vector.matrix.android.api.MatrixPatterns.isUserId
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||||
import im.vector.matrix.android.api.session.events.model.Event
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
@ -219,7 +218,7 @@ class CreateRoomParams {
|
|||||||
* @param ids the participant ids to add.
|
* @param ids the participant ids to add.
|
||||||
*/
|
*/
|
||||||
fun addParticipantIds(hsConfig: HomeServerConnectionConfig,
|
fun addParticipantIds(hsConfig: HomeServerConnectionConfig,
|
||||||
credentials: Credentials,
|
userId: String,
|
||||||
ids: List<String>) {
|
ids: List<String>) {
|
||||||
for (id in ids) {
|
for (id in ids) {
|
||||||
if (Patterns.EMAIL_ADDRESS.matcher(id).matches() && hsConfig.identityServerUri != null) {
|
if (Patterns.EMAIL_ADDRESS.matcher(id).matches() && hsConfig.identityServerUri != null) {
|
||||||
@ -233,7 +232,7 @@ class CreateRoomParams {
|
|||||||
invite3pids!!.add(pid)
|
invite3pids!!.add(pid)
|
||||||
} else if (isUserId(id)) {
|
} else if (isUserId(id)) {
|
||||||
// do not invite oneself
|
// do not invite oneself
|
||||||
if (credentials.userId != id) {
|
if (userId != id) {
|
||||||
if (null == invitedUserIds) {
|
if (null == invitedUserIds) {
|
||||||
invitedUserIds = ArrayList()
|
invitedUserIds = ArrayList()
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,15 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.crypto.actions
|
package im.vector.matrix.android.internal.crypto.actions
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup
|
import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup
|
||||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class SetDeviceVerificationAction @Inject constructor(private val cryptoStore: IMXCryptoStore,
|
internal class SetDeviceVerificationAction @Inject constructor(private val cryptoStore: IMXCryptoStore,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val keysBackup: KeysBackup) {
|
private val keysBackup: KeysBackup) {
|
||||||
|
|
||||||
fun handle(verificationStatus: Int, deviceId: String, userId: String) {
|
fun handle(verificationStatus: Int, deviceId: String, userId: String) {
|
||||||
@ -39,7 +40,7 @@ internal class SetDeviceVerificationAction @Inject constructor(private val crypt
|
|||||||
device.verified = verificationStatus
|
device.verified = verificationStatus
|
||||||
cryptoStore.storeUserDevice(userId, device)
|
cryptoStore.storeUserDevice(userId, device)
|
||||||
|
|
||||||
if (userId == credentials.userId) {
|
if (userId == this.userId) {
|
||||||
// If one of the user's own devices is being marked as verified / unverified,
|
// If one of the user's own devices is being marked as verified / unverified,
|
||||||
// check the key backup status, since whether or not we use this depends on
|
// check the key backup status, since whether or not we use this depends on
|
||||||
// whether it has a signature from a verified device
|
// whether it has a signature from a verified device
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package im.vector.matrix.android.internal.crypto.algorithms.megolm
|
package im.vector.matrix.android.internal.crypto.algorithms.megolm
|
||||||
|
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.crypto.MXCryptoError
|
import im.vector.matrix.android.api.session.crypto.MXCryptoError
|
||||||
import im.vector.matrix.android.api.session.events.model.Event
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
@ -40,7 +39,7 @@ import kotlinx.coroutines.GlobalScope
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
internal class MXMegolmDecryption(private val credentials: Credentials,
|
internal class MXMegolmDecryption(private val userId: String,
|
||||||
private val olmDevice: MXOlmDevice,
|
private val olmDevice: MXOlmDevice,
|
||||||
private val deviceListManager: DeviceListManager,
|
private val deviceListManager: DeviceListManager,
|
||||||
private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager,
|
private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager,
|
||||||
@ -146,11 +145,11 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
|
|||||||
|
|
||||||
val selfMap = HashMap<String, String>()
|
val selfMap = HashMap<String, String>()
|
||||||
// TODO Replace this hard coded keys (see OutgoingRoomKeyRequestManager)
|
// TODO Replace this hard coded keys (see OutgoingRoomKeyRequestManager)
|
||||||
selfMap["userId"] = credentials.userId
|
selfMap["userId"] = userId
|
||||||
selfMap["deviceId"] = "*"
|
selfMap["deviceId"] = "*"
|
||||||
recipients.add(selfMap)
|
recipients.add(selfMap)
|
||||||
|
|
||||||
if (!TextUtils.equals(sender, credentials.userId)) {
|
if (!TextUtils.equals(sender, userId)) {
|
||||||
val senderMap = HashMap<String, String>()
|
val senderMap = HashMap<String, String>()
|
||||||
senderMap["userId"] = sender
|
senderMap["userId"] = sender
|
||||||
senderMap["deviceId"] = encryptedEventContent.deviceId!!
|
senderMap["deviceId"] = encryptedEventContent.deviceId!!
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.crypto.algorithms.megolm
|
package im.vector.matrix.android.internal.crypto.algorithms.megolm
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.internal.crypto.DeviceListManager
|
import im.vector.matrix.android.internal.crypto.DeviceListManager
|
||||||
import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
||||||
import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequestManager
|
import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequestManager
|
||||||
@ -24,10 +23,12 @@ import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevi
|
|||||||
import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter
|
import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter
|
||||||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||||
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class MXMegolmDecryptionFactory @Inject constructor(private val credentials: Credentials,
|
internal class MXMegolmDecryptionFactory @Inject constructor(@UserId
|
||||||
|
private val userId: String,
|
||||||
private val olmDevice: MXOlmDevice,
|
private val olmDevice: MXOlmDevice,
|
||||||
private val deviceListManager: DeviceListManager,
|
private val deviceListManager: DeviceListManager,
|
||||||
private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager,
|
private val outgoingRoomKeyRequestManager: OutgoingRoomKeyRequestManager,
|
||||||
@ -39,7 +40,7 @@ internal class MXMegolmDecryptionFactory @Inject constructor(private val credent
|
|||||||
|
|
||||||
fun create(): MXMegolmDecryption {
|
fun create(): MXMegolmDecryption {
|
||||||
return MXMegolmDecryption(
|
return MXMegolmDecryption(
|
||||||
credentials,
|
userId,
|
||||||
olmDevice,
|
olmDevice,
|
||||||
deviceListManager,
|
deviceListManager,
|
||||||
outgoingRoomKeyRequestManager,
|
outgoingRoomKeyRequestManager,
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.crypto.algorithms.olm
|
package im.vector.matrix.android.internal.crypto.algorithms.olm
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.crypto.MXCryptoError
|
import im.vector.matrix.android.api.session.crypto.MXCryptoError
|
||||||
import im.vector.matrix.android.api.session.events.model.Event
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
@ -35,8 +34,8 @@ import timber.log.Timber
|
|||||||
internal class MXOlmDecryption(
|
internal class MXOlmDecryption(
|
||||||
// The olm device interface
|
// The olm device interface
|
||||||
private val olmDevice: MXOlmDevice,
|
private val olmDevice: MXOlmDevice,
|
||||||
// the matrix credentials
|
// the matrix userId
|
||||||
private val credentials: Credentials)
|
private val userId: String)
|
||||||
: IMXDecrypting {
|
: IMXDecrypting {
|
||||||
|
|
||||||
override suspend fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
|
override suspend fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
|
||||||
@ -97,9 +96,9 @@ internal class MXOlmDecryption(
|
|||||||
throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY, reason)
|
throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (olmPayloadContent.recipient != credentials.userId) {
|
if (olmPayloadContent.recipient != userId) {
|
||||||
Timber.e("## decryptEvent() : Event ${event.eventId}:" +
|
Timber.e("## decryptEvent() : Event ${event.eventId}:" +
|
||||||
" Intended recipient ${olmPayloadContent.recipient} does not match our id ${credentials.userId}")
|
" Intended recipient ${olmPayloadContent.recipient} does not match our id $userId")
|
||||||
throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT,
|
throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT,
|
||||||
String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient))
|
String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient))
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,17 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.crypto.algorithms.olm
|
package im.vector.matrix.android.internal.crypto.algorithms.olm
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
import im.vector.matrix.android.internal.crypto.MXOlmDevice
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class MXOlmDecryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice,
|
internal class MXOlmDecryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice,
|
||||||
private val credentials: Credentials) {
|
@UserId
|
||||||
|
private val userId: String) {
|
||||||
|
|
||||||
fun create(): MXOlmDecryption {
|
fun create(): MXOlmDecryption {
|
||||||
return MXOlmDecryption(
|
return MXOlmDecryption(
|
||||||
olmDevice,
|
olmDevice,
|
||||||
credentials)
|
userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.crypto.tasks
|
package im.vector.matrix.android.internal.crypto.tasks
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.internal.auth.data.LoginFlowTypes
|
import im.vector.matrix.android.internal.auth.data.LoginFlowTypes
|
||||||
import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
import im.vector.matrix.android.internal.crypto.api.CryptoApi
|
||||||
import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceAuth
|
import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceAuth
|
||||||
import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams
|
import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -34,7 +34,8 @@ internal interface DeleteDeviceWithUserPasswordTask : Task<DeleteDeviceWithUserP
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor(private val cryptoApi: CryptoApi,
|
internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor(private val cryptoApi: CryptoApi,
|
||||||
private val credentials: Credentials)
|
@UserId
|
||||||
|
private val userId: String)
|
||||||
: DeleteDeviceWithUserPasswordTask {
|
: DeleteDeviceWithUserPasswordTask {
|
||||||
|
|
||||||
override suspend fun execute(params: DeleteDeviceWithUserPasswordTask.Params) {
|
override suspend fun execute(params: DeleteDeviceWithUserPasswordTask.Params) {
|
||||||
@ -45,7 +46,7 @@ internal class DefaultDeleteDeviceWithUserPasswordTask @Inject constructor(priva
|
|||||||
.apply {
|
.apply {
|
||||||
type = LoginFlowTypes.PASSWORD
|
type = LoginFlowTypes.PASSWORD
|
||||||
session = params.authSession
|
session = params.authSession
|
||||||
user = credentials.userId
|
user = userId
|
||||||
password = params.password
|
password = params.password
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -18,6 +18,16 @@ package im.vector.matrix.android.internal.di
|
|||||||
|
|
||||||
import javax.inject.Qualifier
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to inject the userId
|
||||||
|
*/
|
||||||
@Qualifier
|
@Qualifier
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
annotation class UserMd5
|
internal annotation class UserId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to inject the md5 of the userId
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
internal annotation class UserMd5
|
||||||
|
@ -20,11 +20,11 @@ import android.content.Context
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import arrow.core.Try
|
import arrow.core.Try
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
|
||||||
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||||
import im.vector.matrix.android.api.session.file.FileService
|
import im.vector.matrix.android.api.session.file.FileService
|
||||||
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
|
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
|
||||||
import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments
|
import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachments
|
||||||
|
import im.vector.matrix.android.internal.di.UserMd5
|
||||||
import im.vector.matrix.android.internal.extensions.foldToCallback
|
import im.vector.matrix.android.internal.extensions.foldToCallback
|
||||||
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||||
import im.vector.matrix.android.internal.util.md5
|
import im.vector.matrix.android.internal.util.md5
|
||||||
@ -40,7 +40,8 @@ import java.io.IOException
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class DefaultFileService @Inject constructor(private val context: Context,
|
internal class DefaultFileService @Inject constructor(private val context: Context,
|
||||||
private val sessionParams: SessionParams,
|
@UserMd5
|
||||||
|
private val userMd5: String,
|
||||||
private val contentUrlResolver: ContentUrlResolver,
|
private val contentUrlResolver: ContentUrlResolver,
|
||||||
private val coroutineDispatchers: MatrixCoroutineDispatchers) : FileService {
|
private val coroutineDispatchers: MatrixCoroutineDispatchers) : FileService {
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ internal class DefaultFileService @Inject constructor(private val context: Conte
|
|||||||
// Create dir tree (MF stands for Matrix File):
|
// Create dir tree (MF stands for Matrix File):
|
||||||
// <cache>/MF/<md5(userId)>/<md5(id)>/
|
// <cache>/MF/<md5(userId)>/<md5(id)>/
|
||||||
val tmpFolderRoot = File(context.cacheDir, "MF")
|
val tmpFolderRoot = File(context.cacheDir, "MF")
|
||||||
val tmpFolderUser = File(tmpFolderRoot, sessionParams.credentials.userId.md5())
|
val tmpFolderUser = File(tmpFolderRoot, userMd5)
|
||||||
File(tmpFolderUser, id.md5())
|
File(tmpFolderUser, id.md5())
|
||||||
}
|
}
|
||||||
FileService.DownloadMode.TO_EXPORT -> {
|
FileService.DownloadMode.TO_EXPORT -> {
|
||||||
|
@ -67,11 +67,18 @@ internal abstract class SessionModule {
|
|||||||
return sessionParams.credentials
|
return sessionParams.credentials
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@UserId
|
||||||
|
@Provides
|
||||||
|
fun providesUserId(credentials: Credentials): String {
|
||||||
|
return credentials.userId
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@UserMd5
|
@UserMd5
|
||||||
@Provides
|
@Provides
|
||||||
fun providesUserMd5(sessionParams: SessionParams): String {
|
fun providesUserMd5(@UserId userId: String): String {
|
||||||
return sessionParams.credentials.userId.md5()
|
return userId.md5()
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.session.filter
|
package im.vector.matrix.android.internal.session.filter
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -33,7 +33,8 @@ internal interface SaveFilterTask : Task<SaveFilterTask.Params, Unit> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultSaveFilterTask @Inject constructor(private val sessionParams: SessionParams,
|
internal class DefaultSaveFilterTask @Inject constructor(@UserId
|
||||||
|
private val userId: String,
|
||||||
private val filterAPI: FilterApi,
|
private val filterAPI: FilterApi,
|
||||||
private val filterRepository: FilterRepository
|
private val filterRepository: FilterRepository
|
||||||
) : SaveFilterTask {
|
) : SaveFilterTask {
|
||||||
@ -41,7 +42,7 @@ internal class DefaultSaveFilterTask @Inject constructor(private val sessionPara
|
|||||||
override suspend fun execute(params: SaveFilterTask.Params) {
|
override suspend fun execute(params: SaveFilterTask.Params) {
|
||||||
val filterResponse = executeRequest<FilterResponse> {
|
val filterResponse = executeRequest<FilterResponse> {
|
||||||
// TODO auto retry
|
// TODO auto retry
|
||||||
apiCall = filterAPI.uploadFilter(sessionParams.credentials.userId, params.filter)
|
apiCall = filterAPI.uploadFilter(userId, params.filter)
|
||||||
}
|
}
|
||||||
filterRepository.storeFilterId(params.filter, filterResponse.filterId)
|
filterRepository.storeFilterId(params.filter, filterResponse.filterId)
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ import android.content.Context
|
|||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.room.model.Membership
|
import im.vector.matrix.android.api.session.room.model.Membership
|
||||||
import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
||||||
import im.vector.matrix.android.internal.database.model.GroupEntity
|
import im.vector.matrix.android.internal.database.model.GroupEntity
|
||||||
import im.vector.matrix.android.internal.database.model.GroupSummaryEntity
|
import im.vector.matrix.android.internal.database.model.GroupSummaryEntity
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil
|
import im.vector.matrix.android.internal.worker.WorkManagerUtil
|
||||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
||||||
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
||||||
@ -36,7 +36,8 @@ import javax.inject.Inject
|
|||||||
private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER"
|
private const val GET_GROUP_DATA_WORKER = "GET_GROUP_DATA_WORKER"
|
||||||
|
|
||||||
internal class GroupSummaryUpdater @Inject constructor(private val context: Context,
|
internal class GroupSummaryUpdater @Inject constructor(private val context: Context,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val monarchy: Monarchy)
|
private val monarchy: Monarchy)
|
||||||
: RealmLiveEntityObserver<GroupEntity>(monarchy.realmConfiguration) {
|
: RealmLiveEntityObserver<GroupEntity>(monarchy.realmConfiguration) {
|
||||||
|
|
||||||
@ -60,7 +61,8 @@ internal class GroupSummaryUpdater @Inject constructor(private val context: Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchGroupsData(groupIds: List<String>) {
|
private fun fetchGroupsData(groupIds: List<String>) {
|
||||||
val getGroupDataWorkerParams = GetGroupDataWorker.Params(credentials.userId, groupIds)
|
val getGroupDataWorkerParams = GetGroupDataWorker.Params(userId, groupIds)
|
||||||
|
|
||||||
val workData = WorkerParamsFactory.toData(getGroupDataWorkerParams)
|
val workData = WorkerParamsFactory.toData(getGroupDataWorkerParams)
|
||||||
|
|
||||||
val sendWork = matrixOneTimeWorkRequestBuilder<GetGroupDataWorker>()
|
val sendWork = matrixOneTimeWorkRequestBuilder<GetGroupDataWorker>()
|
||||||
|
@ -17,7 +17,6 @@ package im.vector.matrix.android.internal.session.notification
|
|||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
|
||||||
import im.vector.matrix.android.api.pushrules.Action
|
import im.vector.matrix.android.api.pushrules.Action
|
||||||
import im.vector.matrix.android.api.pushrules.PushRuleService
|
import im.vector.matrix.android.api.pushrules.PushRuleService
|
||||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
||||||
@ -26,6 +25,7 @@ import im.vector.matrix.android.api.util.Cancelable
|
|||||||
import im.vector.matrix.android.internal.database.mapper.PushRulesMapper
|
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.PushRulesEntity
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.SessionScope
|
import im.vector.matrix.android.internal.session.SessionScope
|
||||||
import im.vector.matrix.android.internal.session.pushers.GetPushRulesTask
|
import im.vector.matrix.android.internal.session.pushers.GetPushRulesTask
|
||||||
import im.vector.matrix.android.internal.session.pushers.UpdatePushRuleEnableStatusTask
|
import im.vector.matrix.android.internal.session.pushers.UpdatePushRuleEnableStatusTask
|
||||||
@ -36,8 +36,9 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@SessionScope
|
@SessionScope
|
||||||
internal class DefaultPushRuleService @Inject constructor(
|
internal class DefaultPushRuleService @Inject constructor(
|
||||||
private val sessionParams: SessionParams,
|
@UserId
|
||||||
private val pushRulesTask: GetPushRulesTask,
|
private val userId: String,
|
||||||
|
private val getPushRulesTask: GetPushRulesTask,
|
||||||
private val updatePushRuleEnableStatusTask: UpdatePushRuleEnableStatusTask,
|
private val updatePushRuleEnableStatusTask: UpdatePushRuleEnableStatusTask,
|
||||||
private val taskExecutor: TaskExecutor,
|
private val taskExecutor: TaskExecutor,
|
||||||
private val monarchy: Monarchy
|
private val monarchy: Monarchy
|
||||||
@ -46,7 +47,7 @@ internal class DefaultPushRuleService @Inject constructor(
|
|||||||
private var listeners = ArrayList<PushRuleService.PushRuleListener>()
|
private var listeners = ArrayList<PushRuleService.PushRuleListener>()
|
||||||
|
|
||||||
override fun fetchPushRules(scope: String) {
|
override fun fetchPushRules(scope: String) {
|
||||||
pushRulesTask
|
getPushRulesTask
|
||||||
.configureWith(GetPushRulesTask.Params(scope))
|
.configureWith(GetPushRulesTask.Params(scope))
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
@ -61,19 +62,19 @@ internal class DefaultPushRuleService @Inject constructor(
|
|||||||
|
|
||||||
// TODO Create const for ruleSetKey
|
// TODO Create const for ruleSetKey
|
||||||
monarchy.doWithRealm { realm ->
|
monarchy.doWithRealm { realm ->
|
||||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "content").findFirst()?.let { re ->
|
PushRulesEntity.where(realm, userId, scope, "content").findFirst()?.let { re ->
|
||||||
contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) }
|
contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) }
|
||||||
}
|
}
|
||||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "override").findFirst()?.let { re ->
|
PushRulesEntity.where(realm, userId, scope, "override").findFirst()?.let { re ->
|
||||||
overrideRules = re.pushRules.map { PushRulesMapper.map(it) }
|
overrideRules = re.pushRules.map { PushRulesMapper.map(it) }
|
||||||
}
|
}
|
||||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "room").findFirst()?.let { re ->
|
PushRulesEntity.where(realm, userId, scope, "room").findFirst()?.let { re ->
|
||||||
roomRules = re.pushRules.map { PushRulesMapper.mapRoomRule(it) }
|
roomRules = re.pushRules.map { PushRulesMapper.mapRoomRule(it) }
|
||||||
}
|
}
|
||||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "sender").findFirst()?.let { re ->
|
PushRulesEntity.where(realm, userId, scope, "sender").findFirst()?.let { re ->
|
||||||
senderRules = re.pushRules.map { PushRulesMapper.mapSenderRule(it) }
|
senderRules = re.pushRules.map { PushRulesMapper.mapSenderRule(it) }
|
||||||
}
|
}
|
||||||
PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "underride").findFirst()?.let { re ->
|
PushRulesEntity.where(realm, userId, scope, "underride").findFirst()?.let { re ->
|
||||||
underrideRules = re.pushRules.map { PushRulesMapper.map(it) }
|
underrideRules = re.pushRules.map { PushRulesMapper.map(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.session.notification
|
package im.vector.matrix.android.internal.session.notification
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
|
||||||
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
import im.vector.matrix.android.api.pushrules.rest.PushRule
|
||||||
import im.vector.matrix.android.api.session.events.model.Event
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.room.RoomService
|
import im.vector.matrix.android.api.session.room.RoomService
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.pushers.DefaultConditionResolver
|
import im.vector.matrix.android.internal.session.pushers.DefaultConditionResolver
|
||||||
import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse
|
import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
@ -37,7 +37,8 @@ internal interface ProcessEventForPushTask : Task<ProcessEventForPushTask.Params
|
|||||||
internal class DefaultProcessEventForPushTask @Inject constructor(
|
internal class DefaultProcessEventForPushTask @Inject constructor(
|
||||||
private val defaultPushRuleService: DefaultPushRuleService,
|
private val defaultPushRuleService: DefaultPushRuleService,
|
||||||
private val roomService: RoomService,
|
private val roomService: RoomService,
|
||||||
private val sessionParams: SessionParams
|
@UserId
|
||||||
|
private val userId: String
|
||||||
) : ProcessEventForPushTask {
|
) : ProcessEventForPushTask {
|
||||||
|
|
||||||
override suspend fun execute(params: ProcessEventForPushTask.Params) {
|
override suspend fun execute(params: ProcessEventForPushTask.Params) {
|
||||||
@ -68,7 +69,7 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
|
|||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}.filter {
|
}.filter {
|
||||||
it.senderId != sessionParams.credentials.userId
|
it.senderId != userId
|
||||||
}
|
}
|
||||||
Timber.v("[PushRules] Found ${allEvents.size} out of ${(newJoinEvents + inviteEvents).size}" +
|
Timber.v("[PushRules] Found ${allEvents.size} out of ${(newJoinEvents + inviteEvents).size}" +
|
||||||
" to check for push rules with ${params.rules.size} rules")
|
" to check for push rules with ${params.rules.size} rules")
|
||||||
@ -101,7 +102,7 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fulfilledBingRule(event: Event, rules: List<PushRule>): PushRule? {
|
private fun fulfilledBingRule(event: Event, rules: List<PushRule>): PushRule? {
|
||||||
val conditionResolver = DefaultConditionResolver(event, roomService, sessionParams)
|
val conditionResolver = DefaultConditionResolver(event, roomService, userId)
|
||||||
rules.filter { it.enabled }.forEach { rule ->
|
rules.filter { it.enabled }.forEach { rule ->
|
||||||
val isFullfilled = rule.conditions?.map {
|
val isFullfilled = rule.conditions?.map {
|
||||||
it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false
|
it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false
|
||||||
|
@ -15,15 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package im.vector.matrix.android.internal.session.pushers
|
package im.vector.matrix.android.internal.session.pushers
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
|
||||||
import im.vector.matrix.android.api.pushrules.*
|
import im.vector.matrix.android.api.pushrules.*
|
||||||
import im.vector.matrix.android.api.session.events.model.Event
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.room.RoomService
|
import im.vector.matrix.android.api.session.room.RoomService
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
internal class DefaultConditionResolver(private val event: Event,
|
internal class DefaultConditionResolver(private val event: Event,
|
||||||
private val roomService: RoomService,
|
private val roomService: RoomService,
|
||||||
private val sessionParams: SessionParams) : ConditionResolver {
|
@UserId
|
||||||
|
private val userId: String) : ConditionResolver {
|
||||||
|
|
||||||
|
|
||||||
override fun resolveEventMatchCondition(eventMatchCondition: EventMatchCondition): Boolean {
|
override fun resolveEventMatchCondition(eventMatchCondition: EventMatchCondition): Boolean {
|
||||||
@ -45,8 +46,7 @@ internal class DefaultConditionResolver(private val event: Event,
|
|||||||
override fun resolveContainsDisplayNameCondition(containsDisplayNameCondition: ContainsDisplayNameCondition): Boolean {
|
override fun resolveContainsDisplayNameCondition(containsDisplayNameCondition: ContainsDisplayNameCondition): Boolean {
|
||||||
val roomId = event.roomId ?: return false
|
val roomId = event.roomId ?: return false
|
||||||
val room = roomService.getRoom(roomId) ?: return false
|
val room = roomService.getRoom(roomId) ?: return false
|
||||||
val myDisplayName = room.getRoomMember(sessionParams.credentials.userId)?.displayName
|
val myDisplayName = room.getRoomMember(userId)?.displayName ?: return false
|
||||||
?: return false
|
|
||||||
return containsDisplayNameCondition.isSatisfied(event, myDisplayName)
|
return containsDisplayNameCondition.isSatisfied(event, myDisplayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,29 +21,29 @@ import androidx.work.BackoffPolicy
|
|||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
|
||||||
import im.vector.matrix.android.api.session.pushers.Pusher
|
import im.vector.matrix.android.api.session.pushers.Pusher
|
||||||
import im.vector.matrix.android.api.session.pushers.PushersService
|
import im.vector.matrix.android.api.session.pushers.PushersService
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.PusherEntity
|
import im.vector.matrix.android.internal.database.model.PusherEntity
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil
|
import im.vector.matrix.android.internal.worker.WorkManagerUtil
|
||||||
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
|
||||||
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
import im.vector.matrix.android.internal.worker.WorkerParamsFactory
|
||||||
import java.util.UUID
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
internal class DefaultPusherService @Inject constructor(
|
internal class DefaultPusherService @Inject constructor(private val context: Context,
|
||||||
private val context: Context,
|
private val monarchy: Monarchy,
|
||||||
private val monarchy: Monarchy,
|
@UserId
|
||||||
private val sessionParam: SessionParams,
|
private val userId: String,
|
||||||
private val getPusherTask: GetPushersTask,
|
private val getPusherTask: GetPushersTask,
|
||||||
private val removePusherTask: RemovePusherTask,
|
private val removePusherTask: RemovePusherTask,
|
||||||
private val taskExecutor: TaskExecutor
|
private val taskExecutor: TaskExecutor
|
||||||
) : PushersService {
|
) : PushersService {
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ internal class DefaultPusherService @Inject constructor(
|
|||||||
append = append)
|
append = append)
|
||||||
|
|
||||||
|
|
||||||
val params = AddHttpPusherWorker.Params(pusher, sessionParam.credentials.userId)
|
val params = AddHttpPusherWorker.Params(pusher, userId)
|
||||||
|
|
||||||
val request = matrixOneTimeWorkRequestBuilder<AddHttpPusherWorker>()
|
val request = matrixOneTimeWorkRequestBuilder<AddHttpPusherWorker>()
|
||||||
.setConstraints(WorkManagerUtil.workConstraints)
|
.setConstraints(WorkManagerUtil.workConstraints)
|
||||||
@ -82,7 +82,7 @@ internal class DefaultPusherService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun removeHttpPusher(pushkey: String, appId: String, callback: MatrixCallback<Unit>) {
|
override fun removeHttpPusher(pushkey: String, appId: String, callback: MatrixCallback<Unit>) {
|
||||||
val params = RemovePusherTask.Params(sessionParam.credentials.userId, pushkey, appId)
|
val params = RemovePusherTask.Params(userId, pushkey, appId)
|
||||||
removePusherTask
|
removePusherTask
|
||||||
.configureWith(params) {
|
.configureWith(params) {
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
@ -93,12 +93,12 @@ internal class DefaultPusherService @Inject constructor(
|
|||||||
|
|
||||||
override fun livePushers(): LiveData<List<Pusher>> {
|
override fun livePushers(): LiveData<List<Pusher>> {
|
||||||
return monarchy.findAllMappedWithChanges(
|
return monarchy.findAllMappedWithChanges(
|
||||||
{ realm -> PusherEntity.where(realm, sessionParam.credentials.userId) },
|
{ realm -> PusherEntity.where(realm, userId) },
|
||||||
{ it.asDomain() }
|
{ it.asDomain() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pushers(): List<Pusher> {
|
override fun pushers(): List<Pusher> {
|
||||||
return monarchy.fetchAllCopiedSync { PusherEntity.where(it, sessionParam.credentials.userId) }.map { it.asDomain() }
|
return monarchy.fetchAllCopiedSync { PusherEntity.where(it, userId) }.map { it.asDomain() }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,11 +16,11 @@
|
|||||||
package im.vector.matrix.android.internal.session.pushers
|
package im.vector.matrix.android.internal.session.pushers
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
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.api.pushrules.rest.GetPushRulesResponse
|
||||||
import im.vector.matrix.android.internal.database.mapper.PushRulesMapper
|
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.PushRulesEntity
|
||||||
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
import im.vector.matrix.android.internal.util.awaitTransaction
|
import im.vector.matrix.android.internal.util.awaitTransaction
|
||||||
@ -36,7 +36,8 @@ internal interface GetPushRulesTask : Task<GetPushRulesTask.Params, Unit> {
|
|||||||
|
|
||||||
internal class DefaultGetPushRulesTask @Inject constructor(private val pushRulesApi: PushRulesApi,
|
internal class DefaultGetPushRulesTask @Inject constructor(private val pushRulesApi: PushRulesApi,
|
||||||
private val monarchy: Monarchy,
|
private val monarchy: Monarchy,
|
||||||
private val sessionParams: SessionParams) : GetPushRulesTask {
|
@UserId
|
||||||
|
private val userId: String) : GetPushRulesTask {
|
||||||
|
|
||||||
override suspend fun execute(params: GetPushRulesTask.Params) {
|
override suspend fun execute(params: GetPushRulesTask.Params) {
|
||||||
val response = executeRequest<GetPushRulesResponse> {
|
val response = executeRequest<GetPushRulesResponse> {
|
||||||
@ -47,10 +48,10 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules
|
|||||||
//clear existings?
|
//clear existings?
|
||||||
//TODO
|
//TODO
|
||||||
realm.where(PushRulesEntity::class.java)
|
realm.where(PushRulesEntity::class.java)
|
||||||
.equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId)
|
.equalTo(PusherEntityFields.USER_ID, userId)
|
||||||
.findAll().deleteAllFromRealm()
|
.findAll().deleteAllFromRealm()
|
||||||
|
|
||||||
val content = PushRulesEntity(sessionParams.credentials.userId, scope, "content")
|
val content = PushRulesEntity(userId, scope, "content")
|
||||||
response.global.content?.forEach { rule ->
|
response.global.content?.forEach { rule ->
|
||||||
PushRulesMapper.map(rule).also {
|
PushRulesMapper.map(rule).also {
|
||||||
content.pushRules.add(it)
|
content.pushRules.add(it)
|
||||||
@ -58,7 +59,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules
|
|||||||
}
|
}
|
||||||
realm.insertOrUpdate(content)
|
realm.insertOrUpdate(content)
|
||||||
|
|
||||||
val override = PushRulesEntity(sessionParams.credentials.userId, scope, "override")
|
val override = PushRulesEntity(userId, scope, "override")
|
||||||
response.global.override?.forEach { rule ->
|
response.global.override?.forEach { rule ->
|
||||||
PushRulesMapper.map(rule).also {
|
PushRulesMapper.map(rule).also {
|
||||||
override.pushRules.add(it)
|
override.pushRules.add(it)
|
||||||
@ -66,7 +67,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules
|
|||||||
}
|
}
|
||||||
realm.insertOrUpdate(override)
|
realm.insertOrUpdate(override)
|
||||||
|
|
||||||
val rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room")
|
val rooms = PushRulesEntity(userId, scope, "room")
|
||||||
response.global.room?.forEach { rule ->
|
response.global.room?.forEach { rule ->
|
||||||
PushRulesMapper.map(rule).also {
|
PushRulesMapper.map(rule).also {
|
||||||
rooms.pushRules.add(it)
|
rooms.pushRules.add(it)
|
||||||
@ -74,7 +75,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules
|
|||||||
}
|
}
|
||||||
realm.insertOrUpdate(rooms)
|
realm.insertOrUpdate(rooms)
|
||||||
|
|
||||||
val senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender")
|
val senders = PushRulesEntity(userId, scope, "sender")
|
||||||
response.global.sender?.forEach { rule ->
|
response.global.sender?.forEach { rule ->
|
||||||
PushRulesMapper.map(rule).also {
|
PushRulesMapper.map(rule).also {
|
||||||
senders.pushRules.add(it)
|
senders.pushRules.add(it)
|
||||||
@ -82,7 +83,7 @@ internal class DefaultGetPushRulesTask @Inject constructor(private val pushRules
|
|||||||
}
|
}
|
||||||
realm.insertOrUpdate(senders)
|
realm.insertOrUpdate(senders)
|
||||||
|
|
||||||
val underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride")
|
val underrides = PushRulesEntity(userId, scope, "underride")
|
||||||
response.global.underride?.forEach { rule ->
|
response.global.underride?.forEach { rule ->
|
||||||
PushRulesMapper.map(rule).also {
|
PushRulesMapper.map(rule).also {
|
||||||
underrides.pushRules.add(it)
|
underrides.pushRules.add(it)
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
package im.vector.matrix.android.internal.session.pushers
|
package im.vector.matrix.android.internal.session.pushers
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
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.api.session.pushers.PusherState
|
||||||
import im.vector.matrix.android.internal.database.mapper.toEntity
|
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.PusherEntity
|
||||||
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
import im.vector.matrix.android.internal.database.model.PusherEntityFields
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
import im.vector.matrix.android.internal.util.awaitTransaction
|
import im.vector.matrix.android.internal.util.awaitTransaction
|
||||||
@ -30,7 +30,8 @@ internal interface GetPushersTask : Task<Unit, Unit>
|
|||||||
|
|
||||||
internal class DefaultGetPusherTask @Inject constructor(private val pushersAPI: PushersAPI,
|
internal class DefaultGetPusherTask @Inject constructor(private val pushersAPI: PushersAPI,
|
||||||
private val monarchy: Monarchy,
|
private val monarchy: Monarchy,
|
||||||
private val sessionParams: SessionParams) : GetPushersTask {
|
@UserId
|
||||||
|
private val userId: String) : GetPushersTask {
|
||||||
|
|
||||||
override suspend fun execute(params: Unit) {
|
override suspend fun execute(params: Unit) {
|
||||||
val response = executeRequest<GetPushersResponse> {
|
val response = executeRequest<GetPushersResponse> {
|
||||||
@ -39,10 +40,10 @@ internal class DefaultGetPusherTask @Inject constructor(private val pushersAPI:
|
|||||||
monarchy.awaitTransaction { realm ->
|
monarchy.awaitTransaction { realm ->
|
||||||
//clear existings?
|
//clear existings?
|
||||||
realm.where(PusherEntity::class.java)
|
realm.where(PusherEntity::class.java)
|
||||||
.equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId)
|
.equalTo(PusherEntityFields.USER_ID, userId)
|
||||||
.findAll().deleteAllFromRealm()
|
.findAll().deleteAllFromRealm()
|
||||||
response.pushers?.forEach { jsonPusher ->
|
response.pushers?.forEach { jsonPusher ->
|
||||||
jsonPusher.toEntity(sessionParams.credentials.userId).also {
|
jsonPusher.toEntity(userId).also {
|
||||||
it.state = PusherState.REGISTERED
|
it.state = PusherState.REGISTERED
|
||||||
realm.insertOrUpdate(it)
|
realm.insertOrUpdate(it)
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
package im.vector.matrix.android.internal.session.room
|
package im.vector.matrix.android.internal.session.room
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||||
import im.vector.matrix.android.internal.database.query.types
|
import im.vector.matrix.android.internal.database.query.types
|
||||||
import im.vector.matrix.android.internal.di.SessionDatabase
|
import im.vector.matrix.android.internal.di.SessionDatabase
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import io.realm.OrderedCollectionChangeSet
|
import io.realm.OrderedCollectionChangeSet
|
||||||
@ -38,7 +38,8 @@ import javax.inject.Inject
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
internal class EventRelationsAggregationUpdater @Inject constructor(@SessionDatabase realmConfiguration: RealmConfiguration,
|
internal class EventRelationsAggregationUpdater @Inject constructor(@SessionDatabase realmConfiguration: RealmConfiguration,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val task: EventRelationsAggregationTask,
|
private val task: EventRelationsAggregationTask,
|
||||||
private val taskExecutor: TaskExecutor) :
|
private val taskExecutor: TaskExecutor) :
|
||||||
RealmLiveEntityObserver<EventEntity>(realmConfiguration) {
|
RealmLiveEntityObserver<EventEntity>(realmConfiguration) {
|
||||||
@ -61,7 +62,7 @@ internal class EventRelationsAggregationUpdater @Inject constructor(@SessionData
|
|||||||
.toList()
|
.toList()
|
||||||
val params = EventRelationsAggregationTask.Params(
|
val params = EventRelationsAggregationTask.Params(
|
||||||
insertedDomains,
|
insertedDomains,
|
||||||
credentials.userId
|
userId
|
||||||
)
|
)
|
||||||
task.configureWith(params).executeBy(taskExecutor)
|
task.configureWith(params).executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package im.vector.matrix.android.internal.session.room
|
package im.vector.matrix.android.internal.session.room
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomAvatarContent
|
import im.vector.matrix.android.api.session.room.model.RoomAvatarContent
|
||||||
@ -27,11 +26,13 @@ import im.vector.matrix.android.internal.database.model.EventEntity
|
|||||||
import im.vector.matrix.android.internal.database.model.EventEntityFields
|
import im.vector.matrix.android.internal.database.model.EventEntityFields
|
||||||
import im.vector.matrix.android.internal.database.query.prev
|
import im.vector.matrix.android.internal.database.query.prev
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class RoomAvatarResolver @Inject constructor(private val monarchy: Monarchy,
|
internal class RoomAvatarResolver @Inject constructor(private val monarchy: Monarchy,
|
||||||
private val credentials: Credentials) {
|
@UserId
|
||||||
|
private val userId: String) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the room avatar url
|
* Compute the room avatar url
|
||||||
@ -52,7 +53,7 @@ internal class RoomAvatarResolver @Inject constructor(private val monarchy: Mona
|
|||||||
if (members.size == 1) {
|
if (members.size == 1) {
|
||||||
res = members.firstOrNull()?.toRoomMember()?.avatarUrl
|
res = members.firstOrNull()?.toRoomMember()?.avatarUrl
|
||||||
} else if (members.size == 2) {
|
} else if (members.size == 2) {
|
||||||
val firstOtherMember = members.where().notEqualTo(EventEntityFields.STATE_KEY, credentials.userId).findFirst()
|
val firstOtherMember = members.where().notEqualTo(EventEntityFields.STATE_KEY, userId).findFirst()
|
||||||
res = firstOtherMember?.toRoomMember()?.avatarUrl
|
res = firstOtherMember?.toRoomMember()?.avatarUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package im.vector.matrix.android.internal.session.room
|
package im.vector.matrix.android.internal.session.room
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.Membership
|
import im.vector.matrix.android.api.session.room.model.Membership
|
||||||
@ -31,6 +30,7 @@ import im.vector.matrix.android.internal.database.query.isEventRead
|
|||||||
import im.vector.matrix.android.internal.database.query.latestEvent
|
import im.vector.matrix.android.internal.database.query.latestEvent
|
||||||
import im.vector.matrix.android.internal.database.query.prev
|
import im.vector.matrix.android.internal.database.query.prev
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.room.membership.RoomDisplayNameResolver
|
import im.vector.matrix.android.internal.session.room.membership.RoomDisplayNameResolver
|
||||||
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
||||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary
|
import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary
|
||||||
@ -39,7 +39,8 @@ import io.realm.Realm
|
|||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class RoomSummaryUpdater @Inject constructor(private val credentials: Credentials,
|
internal class RoomSummaryUpdater @Inject constructor(@UserId
|
||||||
|
private val userId: String,
|
||||||
private val roomDisplayNameResolver: RoomDisplayNameResolver,
|
private val roomDisplayNameResolver: RoomDisplayNameResolver,
|
||||||
private val roomAvatarResolver: RoomAvatarResolver,
|
private val roomAvatarResolver: RoomAvatarResolver,
|
||||||
private val monarchy: Monarchy) {
|
private val monarchy: Monarchy) {
|
||||||
@ -92,11 +93,11 @@ internal class RoomSummaryUpdater @Inject constructor(private val credentials: C
|
|||||||
|
|
||||||
roomSummaryEntity.hasUnreadMessages = roomSummaryEntity.notificationCount > 0
|
roomSummaryEntity.hasUnreadMessages = roomSummaryEntity.notificationCount > 0
|
||||||
//avoid this call if we are sure there are unread events
|
//avoid this call if we are sure there are unread events
|
||||||
|| !isEventRead(monarchy, credentials.userId, roomId, latestPreviewableEvent?.eventId)
|
|| !isEventRead(monarchy, userId, roomId, latestPreviewableEvent?.eventId)
|
||||||
|
|
||||||
val otherRoomMembers = RoomMembers(realm, roomId)
|
val otherRoomMembers = RoomMembers(realm, roomId)
|
||||||
.queryRoomMembersEvent()
|
.queryRoomMembersEvent()
|
||||||
.notEqualTo(EventEntityFields.STATE_KEY, credentials.userId)
|
.notEqualTo(EventEntityFields.STATE_KEY, userId)
|
||||||
.findAll()
|
.findAll()
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.map { it.stateKey }
|
.map { it.stateKey }
|
||||||
|
@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.session.room.membership
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.R
|
import im.vector.matrix.android.R
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.*
|
import im.vector.matrix.android.api.session.room.model.*
|
||||||
@ -30,6 +29,7 @@ import im.vector.matrix.android.internal.database.model.RoomEntity
|
|||||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||||
import im.vector.matrix.android.internal.database.query.prev
|
import im.vector.matrix.android.internal.database.query.prev
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +37,8 @@ import javax.inject.Inject
|
|||||||
*/
|
*/
|
||||||
internal class RoomDisplayNameResolver @Inject constructor(private val context: Context,
|
internal class RoomDisplayNameResolver @Inject constructor(private val context: Context,
|
||||||
private val monarchy: Monarchy,
|
private val monarchy: Monarchy,
|
||||||
private val credentials: Credentials
|
@UserId
|
||||||
|
private val userId: String
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,7 +80,7 @@ internal class RoomDisplayNameResolver @Inject constructor(private val context:
|
|||||||
|
|
||||||
|
|
||||||
if (roomEntity?.membership == Membership.INVITE) {
|
if (roomEntity?.membership == Membership.INVITE) {
|
||||||
val inviteMeEvent = roomMembers.queryRoomMemberEvent(credentials.userId).findFirst()
|
val inviteMeEvent = roomMembers.queryRoomMemberEvent(userId).findFirst()
|
||||||
val inviterId = inviteMeEvent?.sender
|
val inviterId = inviteMeEvent?.sender
|
||||||
name = if (inviterId != null) {
|
name = if (inviterId != null) {
|
||||||
val inviterMemberEvent = loadedMembers.where()
|
val inviterMemberEvent = loadedMembers.where()
|
||||||
@ -97,7 +98,7 @@ internal class RoomDisplayNameResolver @Inject constructor(private val context:
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
loadedMembers.where()
|
loadedMembers.where()
|
||||||
.notEqualTo(EventEntityFields.STATE_KEY, credentials.userId)
|
.notEqualTo(EventEntityFields.STATE_KEY, userId)
|
||||||
.limit(3)
|
.limit(3)
|
||||||
.findAll()
|
.findAll()
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
package im.vector.matrix.android.internal.session.room.prune
|
package im.vector.matrix.android.internal.session.room.prune
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||||
import im.vector.matrix.android.internal.database.query.types
|
import im.vector.matrix.android.internal.database.query.types
|
||||||
import im.vector.matrix.android.internal.di.SessionDatabase
|
import im.vector.matrix.android.internal.di.SessionDatabase
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import io.realm.OrderedCollectionChangeSet
|
import io.realm.OrderedCollectionChangeSet
|
||||||
@ -37,7 +37,8 @@ import javax.inject.Inject
|
|||||||
* As it will actually delete the content, it should be called last in the list of listener.
|
* As it will actually delete the content, it should be called last in the list of listener.
|
||||||
*/
|
*/
|
||||||
internal class EventsPruner @Inject constructor(@SessionDatabase realmConfiguration: RealmConfiguration,
|
internal class EventsPruner @Inject constructor(@SessionDatabase realmConfiguration: RealmConfiguration,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val pruneEventTask: PruneEventTask,
|
private val pruneEventTask: PruneEventTask,
|
||||||
private val taskExecutor: TaskExecutor) :
|
private val taskExecutor: TaskExecutor) :
|
||||||
RealmLiveEntityObserver<EventEntity>(realmConfiguration) {
|
RealmLiveEntityObserver<EventEntity>(realmConfiguration) {
|
||||||
@ -54,7 +55,7 @@ internal class EventsPruner @Inject constructor(@SessionDatabase realmConfigurat
|
|||||||
|
|
||||||
val params = PruneEventTask.Params(
|
val params = PruneEventTask.Params(
|
||||||
insertedDomains,
|
insertedDomains,
|
||||||
credentials.userId
|
userId
|
||||||
)
|
)
|
||||||
pruneEventTask.configureWith(params).executeBy(taskExecutor)
|
pruneEventTask.configureWith(params).executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import com.squareup.inject.assisted.Assisted
|
|||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.room.model.ReadReceipt
|
import im.vector.matrix.android.api.session.room.model.ReadReceipt
|
||||||
import im.vector.matrix.android.api.session.room.read.ReadService
|
import im.vector.matrix.android.api.session.room.read.ReadService
|
||||||
import im.vector.matrix.android.internal.database.RealmLiveData
|
import im.vector.matrix.android.internal.database.RealmLiveData
|
||||||
@ -30,6 +29,7 @@ import im.vector.matrix.android.internal.database.mapper.ReadReceiptsSummaryMapp
|
|||||||
import im.vector.matrix.android.internal.database.model.ReadReceiptsSummaryEntity
|
import im.vector.matrix.android.internal.database.model.ReadReceiptsSummaryEntity
|
||||||
import im.vector.matrix.android.internal.database.query.isEventRead
|
import im.vector.matrix.android.internal.database.query.isEventRead
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
|
|
||||||
@ -38,7 +38,8 @@ internal class DefaultReadService @AssistedInject constructor(@Assisted private
|
|||||||
private val taskExecutor: TaskExecutor,
|
private val taskExecutor: TaskExecutor,
|
||||||
private val setReadMarkersTask: SetReadMarkersTask,
|
private val setReadMarkersTask: SetReadMarkersTask,
|
||||||
private val readReceiptsSummaryMapper: ReadReceiptsSummaryMapper,
|
private val readReceiptsSummaryMapper: ReadReceiptsSummaryMapper,
|
||||||
private val credentials: Credentials
|
@UserId
|
||||||
|
private val userId: String
|
||||||
) : ReadService {
|
) : ReadService {
|
||||||
|
|
||||||
@AssistedInject.Factory
|
@AssistedInject.Factory
|
||||||
@ -75,7 +76,7 @@ internal class DefaultReadService @AssistedInject constructor(@Assisted private
|
|||||||
|
|
||||||
|
|
||||||
override fun isEventRead(eventId: String): Boolean {
|
override fun isEventRead(eventId: String): Boolean {
|
||||||
return isEventRead(monarchy, credentials.userId, roomId, eventId)
|
return isEventRead(monarchy, userId, roomId, eventId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEventReadReceiptsLive(eventId: String): LiveData<List<ReadReceipt>> {
|
override fun getEventReadReceiptsLive(eventId: String): LiveData<List<ReadReceipt>> {
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package im.vector.matrix.android.internal.session.room.read
|
package im.vector.matrix.android.internal.session.room.read
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.internal.database.model.ChunkEntity
|
import im.vector.matrix.android.internal.database.model.ChunkEntity
|
||||||
import im.vector.matrix.android.internal.database.model.ReadReceiptEntity
|
import im.vector.matrix.android.internal.database.model.ReadReceiptEntity
|
||||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||||
@ -26,6 +25,7 @@ import im.vector.matrix.android.internal.database.query.find
|
|||||||
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
||||||
import im.vector.matrix.android.internal.database.query.latestEvent
|
import im.vector.matrix.android.internal.database.query.latestEvent
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.session.room.RoomAPI
|
import im.vector.matrix.android.internal.session.room.RoomAPI
|
||||||
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
||||||
@ -48,7 +48,8 @@ private const val READ_MARKER = "m.fully_read"
|
|||||||
private const val READ_RECEIPT = "m.read"
|
private const val READ_RECEIPT = "m.read"
|
||||||
|
|
||||||
internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI: RoomAPI,
|
internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI: RoomAPI,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val monarchy: Monarchy
|
private val monarchy: Monarchy
|
||||||
) : SetReadMarkersTask {
|
) : SetReadMarkersTask {
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(private val roomAPI
|
|||||||
private fun isEventRead(roomId: String, eventId: String): Boolean {
|
private fun isEventRead(roomId: String, eventId: String): Boolean {
|
||||||
var isEventRead = false
|
var isEventRead = false
|
||||||
monarchy.doWithRealm {
|
monarchy.doWithRealm {
|
||||||
val readReceipt = ReadReceiptEntity.where(it, roomId, credentials.userId).findFirst()
|
val readReceipt = ReadReceiptEntity.where(it, roomId, userId).findFirst()
|
||||||
?: return@doWithRealm
|
?: return@doWithRealm
|
||||||
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(it, roomId)
|
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(it, roomId)
|
||||||
?: return@doWithRealm
|
?: return@doWithRealm
|
||||||
|
@ -23,7 +23,6 @@ import com.squareup.inject.assisted.Assisted
|
|||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||||
import im.vector.matrix.android.api.session.events.model.Event
|
import im.vector.matrix.android.api.session.events.model.Event
|
||||||
import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary
|
import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary
|
||||||
@ -37,6 +36,7 @@ import im.vector.matrix.android.internal.database.mapper.asDomain
|
|||||||
import im.vector.matrix.android.internal.database.model.EventAnnotationsSummaryEntity
|
import im.vector.matrix.android.internal.database.model.EventAnnotationsSummaryEntity
|
||||||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.room.send.EncryptEventWorker
|
import im.vector.matrix.android.internal.session.room.send.EncryptEventWorker
|
||||||
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
||||||
import im.vector.matrix.android.internal.session.room.send.RedactEventWorker
|
import im.vector.matrix.android.internal.session.room.send.RedactEventWorker
|
||||||
@ -50,7 +50,8 @@ import timber.log.Timber
|
|||||||
|
|
||||||
internal class DefaultRelationService @AssistedInject constructor(@Assisted private val roomId: String,
|
internal class DefaultRelationService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val eventFactory: LocalEchoEventFactory,
|
private val eventFactory: LocalEchoEventFactory,
|
||||||
private val cryptoService: CryptoService,
|
private val cryptoService: CryptoService,
|
||||||
private val findReactionEventForUndoTask: FindReactionEventForUndoTask,
|
private val findReactionEventForUndoTask: FindReactionEventForUndoTask,
|
||||||
@ -111,7 +112,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv
|
|||||||
//TODO duplicate with send service?
|
//TODO duplicate with send service?
|
||||||
private fun createRedactEventWork(localEvent: Event, eventId: String, reason: String?): OneTimeWorkRequest {
|
private fun createRedactEventWork(localEvent: Event, eventId: String, reason: String?): OneTimeWorkRequest {
|
||||||
val sendContentWorkerParams = RedactEventWorker.Params(
|
val sendContentWorkerParams = RedactEventWorker.Params(
|
||||||
credentials.userId,
|
userId,
|
||||||
localEvent.eventId!!,
|
localEvent.eventId!!,
|
||||||
roomId,
|
roomId,
|
||||||
eventId,
|
eventId,
|
||||||
@ -199,13 +200,13 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv
|
|||||||
|
|
||||||
private fun createEncryptEventWork(event: Event, keepKeys: List<String>?): OneTimeWorkRequest {
|
private fun createEncryptEventWork(event: Event, keepKeys: List<String>?): OneTimeWorkRequest {
|
||||||
// Same parameter
|
// Same parameter
|
||||||
val params = EncryptEventWorker.Params(credentials.userId, roomId, event, keepKeys)
|
val params = EncryptEventWorker.Params(userId, roomId, event, keepKeys)
|
||||||
val sendWorkData = WorkerParamsFactory.toData(params)
|
val sendWorkData = WorkerParamsFactory.toData(params)
|
||||||
return TimelineSendEventWorkCommon.createWork<EncryptEventWorker>(sendWorkData, true)
|
return TimelineSendEventWorkCommon.createWork<EncryptEventWorker>(sendWorkData, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
|
private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
|
||||||
val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event)
|
val sendContentWorkerParams = SendEventWorker.Params(userId, roomId, event)
|
||||||
val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
|
val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
|
||||||
return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData, startChain)
|
return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData, startChain)
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,10 @@
|
|||||||
package im.vector.matrix.android.internal.session.room.send
|
package im.vector.matrix.android.internal.session.room.send
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.Transformations
|
|
||||||
import androidx.work.*
|
import androidx.work.*
|
||||||
import com.squareup.inject.assisted.Assisted
|
import com.squareup.inject.assisted.Assisted
|
||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.BuildConfig
|
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.content.ContentAttachmentData
|
import im.vector.matrix.android.api.session.content.ContentAttachmentData
|
||||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||||
import im.vector.matrix.android.api.session.events.model.*
|
import im.vector.matrix.android.api.session.events.model.*
|
||||||
@ -32,16 +28,16 @@ import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
|||||||
import im.vector.matrix.android.api.session.room.model.message.MessageType
|
import im.vector.matrix.android.api.session.room.model.message.MessageType
|
||||||
import im.vector.matrix.android.api.session.room.send.SendService
|
import im.vector.matrix.android.api.session.room.send.SendService
|
||||||
import im.vector.matrix.android.api.session.room.send.SendState
|
import im.vector.matrix.android.api.session.room.send.SendState
|
||||||
import im.vector.matrix.android.api.session.room.send.UserDraft
|
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
import im.vector.matrix.android.api.util.Cancelable
|
import im.vector.matrix.android.api.util.Cancelable
|
||||||
import im.vector.matrix.android.api.util.CancelableBag
|
import im.vector.matrix.android.api.util.CancelableBag
|
||||||
import im.vector.matrix.android.internal.database.RealmLiveData
|
|
||||||
import im.vector.matrix.android.internal.database.mapper.DraftMapper
|
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.*
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||||
|
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||||
|
import im.vector.matrix.android.internal.database.model.TimelineEventEntity
|
||||||
import im.vector.matrix.android.internal.database.query.findAllInRoomWithSendStates
|
import im.vector.matrix.android.internal.database.query.findAllInRoomWithSendStates
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
||||||
import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon
|
import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon
|
||||||
import im.vector.matrix.android.internal.util.CancelableWork
|
import im.vector.matrix.android.internal.util.CancelableWork
|
||||||
@ -59,7 +55,8 @@ private const val BACKOFF_DELAY = 10_000L
|
|||||||
|
|
||||||
internal class DefaultSendService @AssistedInject constructor(@Assisted private val roomId: String,
|
internal class DefaultSendService @AssistedInject constructor(@Assisted private val roomId: String,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val localEchoEventFactory: LocalEchoEventFactory,
|
private val localEchoEventFactory: LocalEchoEventFactory,
|
||||||
private val cryptoService: CryptoService,
|
private val cryptoService: CryptoService,
|
||||||
private val monarchy: Monarchy
|
private val monarchy: Monarchy
|
||||||
@ -292,7 +289,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private
|
|||||||
|
|
||||||
private fun createEncryptEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
|
private fun createEncryptEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
|
||||||
// Same parameter
|
// Same parameter
|
||||||
val params = EncryptEventWorker.Params(credentials.userId, roomId, event)
|
val params = EncryptEventWorker.Params(userId, roomId, event)
|
||||||
val sendWorkData = WorkerParamsFactory.toData(params)
|
val sendWorkData = WorkerParamsFactory.toData(params)
|
||||||
|
|
||||||
return matrixOneTimeWorkRequestBuilder<EncryptEventWorker>()
|
return matrixOneTimeWorkRequestBuilder<EncryptEventWorker>()
|
||||||
@ -304,7 +301,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
|
private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
|
||||||
val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event)
|
val sendContentWorkerParams = SendEventWorker.Params(userId, roomId, event)
|
||||||
val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
|
val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
|
||||||
|
|
||||||
return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData, startChain)
|
return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData, startChain)
|
||||||
@ -314,7 +311,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private
|
|||||||
val redactEvent = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason).also {
|
val redactEvent = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason).also {
|
||||||
saveLocalEcho(it)
|
saveLocalEcho(it)
|
||||||
}
|
}
|
||||||
val sendContentWorkerParams = RedactEventWorker.Params(credentials.userId, redactEvent.eventId!!, roomId, event.eventId, reason)
|
val sendContentWorkerParams = RedactEventWorker.Params(userId, redactEvent.eventId!!, roomId, event.eventId, reason)
|
||||||
val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
|
val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
|
||||||
return TimelineSendEventWorkCommon.createWork<RedactEventWorker>(redactWorkData, true)
|
return TimelineSendEventWorkCommon.createWork<RedactEventWorker>(redactWorkData, true)
|
||||||
}
|
}
|
||||||
@ -323,7 +320,7 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private
|
|||||||
attachment: ContentAttachmentData,
|
attachment: ContentAttachmentData,
|
||||||
isRoomEncrypted: Boolean,
|
isRoomEncrypted: Boolean,
|
||||||
startChain: Boolean): OneTimeWorkRequest {
|
startChain: Boolean): OneTimeWorkRequest {
|
||||||
val uploadMediaWorkerParams = UploadContentWorker.Params(credentials.userId, roomId, event, attachment, isRoomEncrypted)
|
val uploadMediaWorkerParams = UploadContentWorker.Params(userId, roomId, event, attachment, isRoomEncrypted)
|
||||||
val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams)
|
val uploadWorkData = WorkerParamsFactory.toData(uploadMediaWorkerParams)
|
||||||
|
|
||||||
return matrixOneTimeWorkRequestBuilder<UploadContentWorker>()
|
return matrixOneTimeWorkRequestBuilder<UploadContentWorker>()
|
||||||
|
@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.session.room.send
|
|||||||
import android.media.MediaMetadataRetriever
|
import android.media.MediaMetadataRetriever
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.R
|
import im.vector.matrix.android.R
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.permalinks.PermalinkFactory
|
import im.vector.matrix.android.api.permalinks.PermalinkFactory
|
||||||
import im.vector.matrix.android.api.session.content.ContentAttachmentData
|
import im.vector.matrix.android.api.session.content.ContentAttachmentData
|
||||||
import im.vector.matrix.android.api.session.events.model.*
|
import im.vector.matrix.android.api.session.events.model.*
|
||||||
@ -33,12 +32,13 @@ import im.vector.matrix.android.api.session.room.timeline.getLastMessageContent
|
|||||||
import im.vector.matrix.android.internal.database.helper.addSendingEvent
|
import im.vector.matrix.android.internal.database.helper.addSendingEvent
|
||||||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.content.ThumbnailExtractor
|
import im.vector.matrix.android.internal.session.content.ThumbnailExtractor
|
||||||
import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater
|
import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater
|
||||||
import im.vector.matrix.android.internal.util.StringProvider
|
import im.vector.matrix.android.internal.util.StringProvider
|
||||||
import org.commonmark.parser.Parser
|
import org.commonmark.parser.Parser
|
||||||
import org.commonmark.renderer.html.HtmlRenderer
|
import org.commonmark.renderer.html.HtmlRenderer
|
||||||
import java.util.UUID
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +50,8 @@ import javax.inject.Inject
|
|||||||
*
|
*
|
||||||
* The transactionID is used as loc
|
* The transactionID is used as loc
|
||||||
*/
|
*/
|
||||||
internal class LocalEchoEventFactory @Inject constructor(private val credentials: Credentials,
|
internal class LocalEchoEventFactory @Inject constructor(@UserId
|
||||||
|
private val userId: String,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val roomSummaryUpdater: RoomSummaryUpdater) {
|
private val roomSummaryUpdater: RoomSummaryUpdater) {
|
||||||
// TODO Inject
|
// TODO Inject
|
||||||
@ -163,7 +164,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
|
|||||||
return Event(
|
return Event(
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
originServerTs = dummyOriginServerTs(),
|
originServerTs = dummyOriginServerTs(),
|
||||||
senderId = credentials.userId,
|
senderId = userId,
|
||||||
eventId = localId,
|
eventId = localId,
|
||||||
type = EventType.REACTION,
|
type = EventType.REACTION,
|
||||||
content = content.toContent(),
|
content = content.toContent(),
|
||||||
@ -255,7 +256,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
|
|||||||
return Event(
|
return Event(
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
originServerTs = dummyOriginServerTs(),
|
originServerTs = dummyOriginServerTs(),
|
||||||
senderId = credentials.userId,
|
senderId = userId,
|
||||||
eventId = localID,
|
eventId = localID,
|
||||||
type = EventType.MESSAGE,
|
type = EventType.MESSAGE,
|
||||||
content = content.toContent(),
|
content = content.toContent(),
|
||||||
@ -373,7 +374,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
|
|||||||
return Event(
|
return Event(
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
originServerTs = dummyOriginServerTs(),
|
originServerTs = dummyOriginServerTs(),
|
||||||
senderId = credentials.userId,
|
senderId = userId,
|
||||||
eventId = localID,
|
eventId = localID,
|
||||||
type = EventType.REDACTION,
|
type = EventType.REDACTION,
|
||||||
redacts = eventId,
|
redacts = eventId,
|
||||||
|
@ -17,15 +17,11 @@
|
|||||||
package im.vector.matrix.android.internal.session.signout
|
package im.vector.matrix.android.internal.session.signout
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.internal.SessionManager
|
import im.vector.matrix.android.internal.SessionManager
|
||||||
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
||||||
import im.vector.matrix.android.internal.crypto.CryptoModule
|
import im.vector.matrix.android.internal.crypto.CryptoModule
|
||||||
import im.vector.matrix.android.internal.database.RealmKeysUtils
|
import im.vector.matrix.android.internal.database.RealmKeysUtils
|
||||||
import im.vector.matrix.android.internal.di.CryptoDatabase
|
import im.vector.matrix.android.internal.di.*
|
||||||
import im.vector.matrix.android.internal.di.SessionDatabase
|
|
||||||
import im.vector.matrix.android.internal.di.UserCacheDirectory
|
|
||||||
import im.vector.matrix.android.internal.di.UserMd5
|
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.session.SessionModule
|
import im.vector.matrix.android.internal.session.SessionModule
|
||||||
import im.vector.matrix.android.internal.session.cache.ClearCacheTask
|
import im.vector.matrix.android.internal.session.cache.ClearCacheTask
|
||||||
@ -38,7 +34,8 @@ import javax.inject.Inject
|
|||||||
internal interface SignOutTask : Task<Unit, Unit>
|
internal interface SignOutTask : Task<Unit, Unit>
|
||||||
|
|
||||||
internal class DefaultSignOutTask @Inject constructor(private val context: Context,
|
internal class DefaultSignOutTask @Inject constructor(private val context: Context,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val signOutAPI: SignOutAPI,
|
private val signOutAPI: SignOutAPI,
|
||||||
private val sessionManager: SessionManager,
|
private val sessionManager: SessionManager,
|
||||||
private val sessionParamsStore: SessionParamsStore,
|
private val sessionParamsStore: SessionParamsStore,
|
||||||
@ -55,13 +52,13 @@ internal class DefaultSignOutTask @Inject constructor(private val context: Conte
|
|||||||
}
|
}
|
||||||
|
|
||||||
Timber.d("SignOut: release session...")
|
Timber.d("SignOut: release session...")
|
||||||
sessionManager.releaseSession(credentials.userId)
|
sessionManager.releaseSession(userId)
|
||||||
|
|
||||||
Timber.d("SignOut: cancel pending works...")
|
Timber.d("SignOut: cancel pending works...")
|
||||||
WorkManagerUtil.cancelAllWorks(context)
|
WorkManagerUtil.cancelAllWorks(context)
|
||||||
|
|
||||||
Timber.d("SignOut: delete session params...")
|
Timber.d("SignOut: delete session params...")
|
||||||
sessionParamsStore.delete(credentials.userId)
|
sessionParamsStore.delete(userId)
|
||||||
|
|
||||||
Timber.d("SignOut: clear session data...")
|
Timber.d("SignOut: clear session data...")
|
||||||
clearSessionDataTask.execute(Unit)
|
clearSessionDataTask.execute(Unit)
|
||||||
|
@ -18,10 +18,10 @@ package im.vector.matrix.android.internal.session.sync
|
|||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.R
|
import im.vector.matrix.android.R
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.failure.Failure
|
import im.vector.matrix.android.api.failure.Failure
|
||||||
import im.vector.matrix.android.api.failure.MatrixError
|
import im.vector.matrix.android.api.failure.MatrixError
|
||||||
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
import im.vector.matrix.android.internal.auth.SessionParamsStore
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService
|
import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressService
|
||||||
import im.vector.matrix.android.internal.session.filter.FilterRepository
|
import im.vector.matrix.android.internal.session.filter.FilterRepository
|
||||||
@ -36,7 +36,8 @@ internal interface SyncTask : Task<SyncTask.Params, Unit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
|
internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val filterRepository: FilterRepository,
|
private val filterRepository: FilterRepository,
|
||||||
private val syncResponseHandler: SyncResponseHandler,
|
private val syncResponseHandler: SyncResponseHandler,
|
||||||
private val sessionParamsStore: SessionParamsStore,
|
private val sessionParamsStore: SessionParamsStore,
|
||||||
@ -70,7 +71,7 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
|
|||||||
// Intercept 401
|
// Intercept 401
|
||||||
if (throwable is Failure.ServerError
|
if (throwable is Failure.ServerError
|
||||||
&& throwable.error.code == MatrixError.UNKNOWN_TOKEN) {
|
&& throwable.error.code == MatrixError.UNKNOWN_TOKEN) {
|
||||||
sessionParamsStore.delete(credentials.userId)
|
sessionParamsStore.delete(userId)
|
||||||
}
|
}
|
||||||
throw throwable
|
throw throwable
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
package im.vector.matrix.android.internal.session.sync
|
package im.vector.matrix.android.internal.session.sync
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomMember
|
import im.vector.matrix.android.api.session.room.model.RoomMember
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
||||||
import im.vector.matrix.android.internal.database.query.getDirectRooms
|
import im.vector.matrix.android.internal.database.query.getDirectRooms
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
||||||
import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync
|
import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync
|
||||||
import im.vector.matrix.android.internal.session.sync.model.UserAccountDataDirectMessages
|
import im.vector.matrix.android.internal.session.sync.model.UserAccountDataDirectMessages
|
||||||
@ -37,7 +37,8 @@ import timber.log.Timber
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class UserAccountDataSyncHandler @Inject constructor(private val monarchy: Monarchy,
|
internal class UserAccountDataSyncHandler @Inject constructor(private val monarchy: Monarchy,
|
||||||
private val credentials: Credentials,
|
@UserId
|
||||||
|
private val userId: String,
|
||||||
private val directChatsHelper: DirectChatsHelper,
|
private val directChatsHelper: DirectChatsHelper,
|
||||||
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
|
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
|
||||||
private val taskExecutor: TaskExecutor) {
|
private val taskExecutor: TaskExecutor) {
|
||||||
@ -81,11 +82,11 @@ internal class UserAccountDataSyncHandler @Inject constructor(private val monarc
|
|||||||
val directChats = directChatsHelper.getLocalUserAccount()
|
val directChats = directChatsHelper.getLocalUserAccount()
|
||||||
var hasUpdate = false
|
var hasUpdate = false
|
||||||
invites.forEach { (roomId, _) ->
|
invites.forEach { (roomId, _) ->
|
||||||
val myUserStateEvent = RoomMembers(realm, roomId).getStateEvent(credentials.userId)
|
val myUserStateEvent = RoomMembers(realm, roomId).getStateEvent(userId)
|
||||||
val inviterId = myUserStateEvent?.sender
|
val inviterId = myUserStateEvent?.sender
|
||||||
val myUserRoomMember: RoomMember? = myUserStateEvent?.let { it.asDomain().content?.toModel() }
|
val myUserRoomMember: RoomMember? = myUserStateEvent?.let { it.asDomain().content?.toModel() }
|
||||||
val isDirect = myUserRoomMember?.isDirect
|
val isDirect = myUserRoomMember?.isDirect
|
||||||
if (inviterId != null && inviterId != credentials.userId && isDirect == true) {
|
if (inviterId != null && inviterId != userId && isDirect == true) {
|
||||||
directChats
|
directChats
|
||||||
.getOrPut(inviterId, { arrayListOf() })
|
.getOrPut(inviterId, { arrayListOf() })
|
||||||
.apply {
|
.apply {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.session.user.accountdata
|
package im.vector.matrix.android.internal.session.user.accountdata
|
||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.Credentials
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.network.executeRequest
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
import im.vector.matrix.android.internal.session.sync.model.UserAccountData
|
import im.vector.matrix.android.internal.session.sync.model.UserAccountData
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
@ -42,11 +42,12 @@ internal interface UpdateUserAccountDataTask : Task<UpdateUserAccountDataTask.Pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class DefaultUpdateUserAccountDataTask @Inject constructor(private val accountDataApi: AccountDataAPI,
|
internal class DefaultUpdateUserAccountDataTask @Inject constructor(private val accountDataApi: AccountDataAPI,
|
||||||
private val credentials: Credentials) : UpdateUserAccountDataTask {
|
@UserId
|
||||||
|
private val userId: String) : UpdateUserAccountDataTask {
|
||||||
|
|
||||||
override suspend fun execute(params: UpdateUserAccountDataTask.Params) {
|
override suspend fun execute(params: UpdateUserAccountDataTask.Params) {
|
||||||
return executeRequest {
|
return executeRequest {
|
||||||
apiCall = accountDataApi.setAccountData(credentials.userId, params.type, params.getData())
|
apiCall = accountDataApi.setAccountData(userId, params.type, params.getData())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
|
|||||||
Runnable {
|
Runnable {
|
||||||
alert.weakCurrentActivity?.get()?.let {
|
alert.weakCurrentActivity?.get()?.let {
|
||||||
val intent = SASVerificationActivity.outgoingIntent(it,
|
val intent = SASVerificationActivity.outgoingIntent(it,
|
||||||
session?.sessionParams?.credentials?.userId ?: "",
|
session?.myUserId ?: "",
|
||||||
userId, deviceId)
|
userId, deviceId)
|
||||||
it.startActivity(intent)
|
it.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class IncomingVerificationRequestHandler @Inject constructor(private val context
|
|||||||
.apply {
|
.apply {
|
||||||
contentAction = Runnable {
|
contentAction = Runnable {
|
||||||
val intent = SASVerificationActivity.incomingIntent(context,
|
val intent = SASVerificationActivity.incomingIntent(context,
|
||||||
session?.sessionParams?.credentials?.userId ?: "",
|
session?.myUserId ?: "",
|
||||||
tx.otherUserId,
|
tx.otherUserId,
|
||||||
tx.transactionId)
|
tx.transactionId)
|
||||||
weakCurrentActivity?.get()?.startActivity(intent)
|
weakCurrentActivity?.get()?.startActivity(intent)
|
||||||
@ -78,7 +78,7 @@ class IncomingVerificationRequestHandler @Inject constructor(private val context
|
|||||||
context.getString(R.string.action_open),
|
context.getString(R.string.action_open),
|
||||||
Runnable {
|
Runnable {
|
||||||
val intent = SASVerificationActivity.incomingIntent(context,
|
val intent = SASVerificationActivity.incomingIntent(context,
|
||||||
session?.sessionParams?.credentials?.userId ?: "",
|
session?.myUserId ?: "",
|
||||||
tx.otherUserId,
|
tx.otherUserId,
|
||||||
tx.transactionId)
|
tx.transactionId)
|
||||||
weakCurrentActivity?.get()?.startActivity(intent)
|
weakCurrentActivity?.get()?.startActivity(intent)
|
||||||
|
Loading…
Reference in New Issue
Block a user