Merge branch 'develop' into feature/fga/csam_preferences_server
This commit is contained in:
commit
773fa1657a
623 changed files with 4661 additions and 2049 deletions
|
|
@ -131,7 +131,7 @@ class RustMatrixClient(
|
|||
private val sessionStore: SessionStore,
|
||||
private val appCoroutineScope: CoroutineScope,
|
||||
private val sessionDelegate: RustClientSessionDelegate,
|
||||
innerSyncService: ClientSyncService,
|
||||
private val innerSyncService: ClientSyncService,
|
||||
dispatchers: CoroutineDispatchers,
|
||||
baseCacheDirectory: File,
|
||||
clock: SystemClock,
|
||||
|
|
@ -541,7 +541,7 @@ class RustMatrixClient(
|
|||
}
|
||||
|
||||
override suspend fun clearCache() {
|
||||
innerClient.clearCaches()
|
||||
innerClient.clearCaches(innerSyncService)
|
||||
destroy()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.matrix.rustcomponents.sdk.SlidingSyncVersionBuilder
|
|||
import org.matrix.rustcomponents.sdk.use
|
||||
import timber.log.Timber
|
||||
import uniffi.matrix_sdk_crypto.CollectStrategy
|
||||
import uniffi.matrix_sdk_crypto.DecryptionSettings
|
||||
import uniffi.matrix_sdk_crypto.TrustRequirement
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
|
@ -120,12 +121,14 @@ class RustMatrixClientFactory @Inject constructor(
|
|||
CollectStrategy.ERROR_ON_VERIFIED_USER_PROBLEM
|
||||
}
|
||||
)
|
||||
.roomDecryptionTrustRequirement(
|
||||
trustRequirement = if (featureFlagService.isFeatureEnabled(FeatureFlags.OnlySignedDeviceIsolationMode)) {
|
||||
TrustRequirement.CROSS_SIGNED_OR_LEGACY
|
||||
} else {
|
||||
TrustRequirement.UNTRUSTED
|
||||
}
|
||||
.decryptionSettings(
|
||||
DecryptionSettings(
|
||||
senderDeviceTrustRequirement = if (featureFlagService.isFeatureEnabled(FeatureFlags.OnlySignedDeviceIsolationMode)) {
|
||||
TrustRequirement.CROSS_SIGNED_OR_LEGACY
|
||||
} else {
|
||||
TrustRequirement.UNTRUSTED
|
||||
}
|
||||
)
|
||||
)
|
||||
.enableShareHistoryOnInvite(featureFlagService.isFeatureEnabled(FeatureFlags.EnableKeyShareOnInvite))
|
||||
.run {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ class JoinedRustRoom(
|
|||
}
|
||||
|
||||
init {
|
||||
val powerLevelChanges = roomInfoFlow.map { it.userPowerLevels }.distinctUntilChanged()
|
||||
val powerLevelChanges = roomInfoFlow.map { it.roomPowerLevels }.distinctUntilChanged()
|
||||
val membershipChanges = liveTimeline.membershipChangeEventReceived.onStart { emit(Unit) }
|
||||
combine(membershipChanges, powerLevelChanges) { _, _ -> }
|
||||
// Skip initial one
|
||||
|
|
|
|||
|
|
@ -14,12 +14,13 @@ import io.element.android.libraries.matrix.api.core.UserId
|
|||
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||
import io.element.android.libraries.matrix.api.room.RoomInfo
|
||||
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
|
||||
import io.element.android.libraries.matrix.api.room.powerlevels.RoomPowerLevels
|
||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||
import io.element.android.libraries.matrix.impl.room.history.map
|
||||
import io.element.android.libraries.matrix.impl.room.join.map
|
||||
import io.element.android.libraries.matrix.impl.room.member.RoomMemberMapper
|
||||
import io.element.android.libraries.matrix.impl.room.powerlevels.RoomPowerLevelsValuesMapper
|
||||
import io.element.android.libraries.matrix.impl.room.tombstone.map
|
||||
import kotlinx.collections.immutable.ImmutableMap
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.collections.immutable.toPersistentMap
|
||||
import org.matrix.rustcomponents.sdk.Membership
|
||||
|
|
@ -28,6 +29,7 @@ import uniffi.matrix_sdk_base.EncryptionState
|
|||
import org.matrix.rustcomponents.sdk.Membership as RustMembership
|
||||
import org.matrix.rustcomponents.sdk.RoomInfo as RustRoomInfo
|
||||
import org.matrix.rustcomponents.sdk.RoomNotificationMode as RustRoomNotificationMode
|
||||
import org.matrix.rustcomponents.sdk.RoomPowerLevels as RustRoomPowerLevels
|
||||
|
||||
class RoomInfoMapper {
|
||||
fun map(rustRoomInfo: RustRoomInfo): RoomInfo = rustRoomInfo.let {
|
||||
|
|
@ -55,7 +57,7 @@ class RoomInfoMapper {
|
|||
activeMembersCount = it.activeMembersCount.toLong(),
|
||||
invitedMembersCount = it.invitedMembersCount.toLong(),
|
||||
joinedMembersCount = it.joinedMembersCount.toLong(),
|
||||
userPowerLevels = mapPowerLevels(it.userPowerLevels),
|
||||
roomPowerLevels = it.powerLevels?.let(::mapPowerLevels),
|
||||
highlightCount = it.highlightCount.toLong(),
|
||||
notificationCount = it.notificationCount.toLong(),
|
||||
userDefinedNotificationMode = it.cachedUserDefinedNotificationMode?.map(),
|
||||
|
|
@ -96,6 +98,9 @@ fun RoomHero.map(): MatrixUser = MatrixUser(
|
|||
avatarUrl = avatarUrl
|
||||
)
|
||||
|
||||
fun mapPowerLevels(powerLevels: Map<String, Long>): ImmutableMap<UserId, Long> {
|
||||
return powerLevels.mapKeys { (key, _) -> UserId(key) }.toPersistentMap()
|
||||
fun mapPowerLevels(roomPowerLevels: RustRoomPowerLevels): RoomPowerLevels {
|
||||
return RoomPowerLevels(
|
||||
values = RoomPowerLevelsValuesMapper.map(roomPowerLevels.values()),
|
||||
users = roomPowerLevels.userPowerLevels().mapKeys { (key, _) -> UserId(key) }.toPersistentMap()
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ object RoomPreviewInfoMapper {
|
|||
roomType = info.roomType.map(),
|
||||
isHistoryWorldReadable = info.isHistoryWorldReadable.orFalse(),
|
||||
membership = info.membership?.map(),
|
||||
joinRule = info.joinRule.map(),
|
||||
joinRule = info.joinRule?.map(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,6 @@ internal class MatrixTimelineDiffProcessor(
|
|||
private val _membershipChangeEventReceived = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
||||
val membershipChangeEventReceived: Flow<Unit> = _membershipChangeEventReceived
|
||||
|
||||
suspend fun postItems(items: List<TimelineItem>) {
|
||||
updateTimelineItems {
|
||||
Timber.v("Update timeline items from postItems (with ${items.size} items) on ${Thread.currentThread()}")
|
||||
val mappedItems = items.map { it.asMatrixTimelineItem() }
|
||||
addAll(0, mappedItems)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun postDiffs(diffs: List<TimelineDiff>) {
|
||||
updateTimelineItems {
|
||||
Timber.v("Update timeline items from postDiffs (with ${diffs.size} items) on ${Thread.currentThread()}")
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ import io.element.android.libraries.matrix.impl.timeline.postprocessor.TypingNot
|
|||
import io.element.android.libraries.matrix.impl.timeline.reply.InReplyToMapper
|
||||
import io.element.android.libraries.matrix.impl.util.MessageEventContent
|
||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -95,9 +94,6 @@ class RustTimeline(
|
|||
private val featureFlagsService: FeatureFlagService,
|
||||
onNewSyncedEvent: () -> Unit,
|
||||
) : Timeline {
|
||||
private val initLatch = CompletableDeferred<Unit>()
|
||||
private val isTimelineInitialized = MutableStateFlow(false)
|
||||
|
||||
private val _timelineItems: MutableSharedFlow<List<MatrixTimelineItem>> =
|
||||
MutableSharedFlow(replay = 1, extraBufferCapacity = Int.MAX_VALUE)
|
||||
|
||||
|
|
@ -119,8 +115,6 @@ class RustTimeline(
|
|||
timeline = inner,
|
||||
timelineCoroutineScope = coroutineScope,
|
||||
timelineDiffProcessor = timelineDiffProcessor,
|
||||
initLatch = initLatch,
|
||||
isTimelineInitialized = isTimelineInitialized,
|
||||
dispatcher = dispatcher,
|
||||
onNewSyncedEvent = onNewSyncedEvent,
|
||||
)
|
||||
|
|
@ -181,7 +175,6 @@ class RustTimeline(
|
|||
// Use NonCancellable to avoid breaking the timeline when the coroutine is cancelled.
|
||||
override suspend fun paginate(direction: Timeline.PaginationDirection): Result<Boolean> = withContext(NonCancellable) {
|
||||
withContext(dispatcher) {
|
||||
initLatch.await()
|
||||
runCatchingExceptions {
|
||||
if (!canPaginate(direction)) throw TimelineException.CannotPaginate
|
||||
updatePaginationStatus(direction) { it.copy(isPaginating = true) }
|
||||
|
|
@ -203,7 +196,6 @@ class RustTimeline(
|
|||
}
|
||||
|
||||
private fun canPaginate(direction: Timeline.PaginationDirection): Boolean {
|
||||
if (!isTimelineInitialized.value) return false
|
||||
return when (direction) {
|
||||
Timeline.PaginationDirection.BACKWARDS -> backwardPaginationStatus.value.canPaginate
|
||||
Timeline.PaginationDirection.FORWARDS -> forwardPaginationStatus.value.canPaginate
|
||||
|
|
@ -215,12 +207,10 @@ class RustTimeline(
|
|||
backwardPaginationStatus,
|
||||
forwardPaginationStatus,
|
||||
joinedRoom.roomInfoFlow.map { it.creator to it.isDm }.distinctUntilChanged(),
|
||||
isTimelineInitialized,
|
||||
) { timelineItems,
|
||||
backwardPaginationStatus,
|
||||
forwardPaginationStatus,
|
||||
(roomCreator, isDm),
|
||||
isTimelineInitialized ->
|
||||
(roomCreator, isDm) ->
|
||||
withContext(dispatcher) {
|
||||
timelineItems
|
||||
.let { items ->
|
||||
|
|
@ -234,7 +224,6 @@ class RustTimeline(
|
|||
.let { items ->
|
||||
loadingIndicatorsPostProcessor.process(
|
||||
items = items,
|
||||
isTimelineInitialized = isTimelineInitialized,
|
||||
hasMoreToLoadBackward = backwardPaginationStatus.hasMoreToLoad,
|
||||
hasMoreToLoadForward = forwardPaginationStatus.hasMoreToLoad,
|
||||
)
|
||||
|
|
@ -244,10 +233,7 @@ class RustTimeline(
|
|||
}
|
||||
// Keep lastForwardIndicatorsPostProcessor last
|
||||
.let { items ->
|
||||
lastForwardIndicatorsPostProcessor.process(
|
||||
items = items,
|
||||
isTimelineInitialized = isTimelineInitialized,
|
||||
)
|
||||
lastForwardIndicatorsPostProcessor.process(items = items)
|
||||
}
|
||||
}
|
||||
}.onStart {
|
||||
|
|
@ -262,7 +248,6 @@ class RustTimeline(
|
|||
}
|
||||
|
||||
private fun CoroutineScope.fetchMembers() = launch(dispatcher) {
|
||||
initLatch.await()
|
||||
try {
|
||||
inner.fetchMembers()
|
||||
} catch (exception: Exception) {
|
||||
|
|
|
|||
|
|
@ -8,37 +8,26 @@
|
|||
package io.element.android.libraries.matrix.impl.timeline
|
||||
|
||||
import io.element.android.libraries.core.coroutine.childScope
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.cancelChildren
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import org.matrix.rustcomponents.sdk.Timeline
|
||||
import org.matrix.rustcomponents.sdk.TimelineChange
|
||||
import org.matrix.rustcomponents.sdk.TimelineDiff
|
||||
import org.matrix.rustcomponents.sdk.TimelineItem
|
||||
import uniffi.matrix_sdk_ui.EventItemOrigin
|
||||
|
||||
private const val INITIAL_MAX_SIZE = 50
|
||||
|
||||
/**
|
||||
* This class is responsible for subscribing to a timeline and post the items/diffs to the timelineDiffProcessor.
|
||||
* It will also trigger a callback when a new synced event is received.
|
||||
* It will also handle the initial items and make sure they are posted before any diff.
|
||||
*/
|
||||
internal class TimelineItemsSubscriber(
|
||||
timelineCoroutineScope: CoroutineScope,
|
||||
dispatcher: CoroutineDispatcher,
|
||||
private val timeline: Timeline,
|
||||
private val timelineDiffProcessor: MatrixTimelineDiffProcessor,
|
||||
private val initLatch: CompletableDeferred<Unit>,
|
||||
private val isTimelineInitialized: MutableStateFlow<Boolean>,
|
||||
private val onNewSyncedEvent: () -> Unit,
|
||||
) {
|
||||
private var subscriptionCount = 0
|
||||
|
|
@ -57,7 +46,7 @@ internal class TimelineItemsSubscriber(
|
|||
if (diffs.any { diff -> diff.eventOrigin() == EventItemOrigin.SYNC }) {
|
||||
onNewSyncedEvent()
|
||||
}
|
||||
postDiffs(diffs)
|
||||
timelineDiffProcessor.postDiffs(diffs)
|
||||
}
|
||||
.launchIn(coroutineScope)
|
||||
}
|
||||
|
|
@ -78,35 +67,4 @@ internal class TimelineItemsSubscriber(
|
|||
}
|
||||
subscriptionCount--
|
||||
}
|
||||
|
||||
private suspend fun postItems(items: List<TimelineItem>) = coroutineScope {
|
||||
if (items.isEmpty()) {
|
||||
// Makes sure to post empty list if there is no item, so you can handle empty state.
|
||||
timelineDiffProcessor.postItems(emptyList())
|
||||
} else {
|
||||
// Split the initial items in multiple list as there is no pagination in the cached data, so we can post timelineItems asap.
|
||||
items.chunked(INITIAL_MAX_SIZE).reversed().forEach {
|
||||
ensureActive()
|
||||
timelineDiffProcessor.postItems(it)
|
||||
}
|
||||
}
|
||||
isTimelineInitialized.value = true
|
||||
initLatch.complete(Unit)
|
||||
}
|
||||
|
||||
private suspend fun postDiffs(diffs: List<TimelineDiff>) {
|
||||
val diffsToProcess = diffs.toMutableList()
|
||||
if (!isTimelineInitialized.value) {
|
||||
val resetDiff = diffsToProcess.firstOrNull { it.change() == TimelineChange.RESET }
|
||||
if (resetDiff != null) {
|
||||
// Keep using the postItems logic so we can post the timelineItems asap.
|
||||
postItems(resetDiff.reset() ?: emptyList())
|
||||
diffsToProcess.remove(resetDiff)
|
||||
}
|
||||
}
|
||||
initLatch.await()
|
||||
if (diffsToProcess.isNotEmpty()) {
|
||||
timelineDiffProcessor.postDiffs(diffsToProcess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,7 @@ class LastForwardIndicatorsPostProcessor(
|
|||
|
||||
fun process(
|
||||
items: List<MatrixTimelineItem>,
|
||||
isTimelineInitialized: Boolean,
|
||||
): List<MatrixTimelineItem> {
|
||||
if (!isTimelineInitialized) return items
|
||||
// We don't need to add the last forward indicator if we are not in the FOCUSED_ON_EVENT mode
|
||||
if (mode != Timeline.Mode.FOCUSED_ON_EVENT) {
|
||||
return items
|
||||
|
|
|
|||
|
|
@ -16,11 +16,9 @@ import io.element.android.services.toolbox.api.systemclock.SystemClock
|
|||
class LoadingIndicatorsPostProcessor(private val systemClock: SystemClock) {
|
||||
fun process(
|
||||
items: List<MatrixTimelineItem>,
|
||||
isTimelineInitialized: Boolean,
|
||||
hasMoreToLoadBackward: Boolean,
|
||||
hasMoreToLoadForward: Boolean,
|
||||
): List<MatrixTimelineItem> {
|
||||
if (!isTimelineInitialized) return items
|
||||
val shouldAddForwardLoadingIndicator = hasMoreToLoadForward && items.isNotEmpty()
|
||||
val currentTimestamp = systemClock.epochMillis()
|
||||
return buildList {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@ import io.element.android.libraries.matrix.api.widget.CallWidgetSettingsProvider
|
|||
import io.element.android.libraries.matrix.api.widget.MatrixWidgetSettings
|
||||
import io.element.android.services.analytics.api.AnalyticsService
|
||||
import kotlinx.coroutines.flow.first
|
||||
import org.matrix.rustcomponents.sdk.EncryptionSystem
|
||||
import org.matrix.rustcomponents.sdk.VirtualElementCallWidgetOptions
|
||||
import org.matrix.rustcomponents.sdk.newVirtualElementCallWidget
|
||||
import uniffi.matrix_sdk.EncryptionSystem
|
||||
import uniffi.matrix_sdk.HeaderStyle
|
||||
import uniffi.matrix_sdk.VirtualElementCallWidgetOptions
|
||||
import javax.inject.Inject
|
||||
import org.matrix.rustcomponents.sdk.Intent as CallIntent
|
||||
import uniffi.matrix_sdk.Intent as CallIntent
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class DefaultCallWidgetSettingsProvider @Inject constructor(
|
||||
|
|
@ -48,8 +49,10 @@ class DefaultCallWidgetSettingsProvider @Inject constructor(
|
|||
sentryDsn = callAnalyticsCredentialsProvider.sentryDsn.takeIf { isAnalyticsEnabled },
|
||||
sentryEnvironment = if (buildMeta.buildType == BuildType.RELEASE) "RELEASE" else "DEBUG",
|
||||
parentUrl = null,
|
||||
// For backwards compatibility, it'll be ignored in recent versions of Element Call
|
||||
hideHeader = true,
|
||||
controlledMediaDevices = true,
|
||||
header = HeaderStyle.APP_BAR,
|
||||
)
|
||||
val rustWidgetSettings = newVirtualElementCallWidget(options)
|
||||
return MatrixWidgetSettings.fromRustWidgetSettings(rustWidgetSettings)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue