Skip to content

Commit

Permalink
Merge pull request #3736 from element-hq/feature/valere/stack_3_bump_…
Browse files Browse the repository at this point in the history
…sdk_0.2.57_subscription

Integrate breasking changes due to rust-sdk update 0.2.57
  • Loading branch information
BillCarsonFr authored Oct 24, 2024
2 parents f30a860 + 4f3ccf3 commit a07d102
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class RustMatrixClient(
sessionDispatcher
) {
runCatching {
client.knock(roomIdOrAlias.identifier).destroy()
client.knock(roomIdOrAlias.identifier, message, serverNames).destroy()
try {
awaitRoom(roomIdOrAlias, 10.seconds, CurrentUserMembership.KNOCKED)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,27 @@ package io.element.android.libraries.matrix.impl.room

import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.timeline.item.event.EventType
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import org.matrix.rustcomponents.sdk.RequiredState
import org.matrix.rustcomponents.sdk.RoomListService
import org.matrix.rustcomponents.sdk.RoomSubscription
import timber.log.Timber

private const val DEFAULT_TIMELINE_LIMIT = 20u

class RoomSyncSubscriber(
private val roomListService: RoomListService,
private val dispatchers: CoroutineDispatchers,
) {
private val subscribedRoomIds = mutableSetOf<RoomId>()
private val mutex = Mutex()

private val settings = RoomSubscription(
requiredState = listOf(
RequiredState(key = EventType.STATE_ROOM_NAME, value = ""),
RequiredState(key = EventType.STATE_ROOM_TOPIC, value = ""),
RequiredState(key = EventType.STATE_ROOM_AVATAR, value = ""),
RequiredState(key = EventType.STATE_ROOM_CANONICAL_ALIAS, value = ""),
RequiredState(key = EventType.STATE_ROOM_JOIN_RULES, value = ""),
RequiredState(key = EventType.STATE_ROOM_POWER_LEVELS, value = ""),
RequiredState(key = EventType.STATE_ROOM_PINNED_EVENT, value = ""),
),
timelineLimit = DEFAULT_TIMELINE_LIMIT,
// We don't need heroes here as they're already included in the `all_rooms` list
includeHeroes = false,
)

suspend fun subscribe(roomId: RoomId) {
mutex.withLock {
withContext(dispatchers.io) {
try {
if (!isSubscribedTo(roomId)) {
Timber.d("Subscribing to room $roomId}")
roomListService.subscribeToRooms(listOf(roomId.value), settings)
roomListService.subscribeToRooms(listOf(roomId.value))
}
subscribedRoomIds.add(roomId)
} catch (exception: Exception) {
Expand All @@ -65,7 +45,7 @@ class RoomSyncSubscriber(
val roomIdsToSubscribeTo = roomIds.filterNot { isSubscribedTo(it) }
if (roomIdsToSubscribeTo.isNotEmpty()) {
Timber.d("Subscribing to rooms: $roomIds")
roomListService.subscribeToRooms(roomIdsToSubscribeTo.map { it.value }, settings)
roomListService.subscribeToRooms(roomIdsToSubscribeTo.map { it.value })
subscribedRoomIds.addAll(roomIds)
}
} catch (cancellationException: CancellationException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class RustTimeline(
formattedCaption = formattedBody?.let {
FormattedBody(body = it, format = MessageFormat.Html)
},
storeInCache = true,
progressWatcher = progressCallback?.toProgressWatcher()
)
}
Expand All @@ -361,6 +362,7 @@ class RustTimeline(
formattedCaption = formattedBody?.let {
FormattedBody(body = it, format = MessageFormat.Html)
},
storeInCache = true,
progressWatcher = progressCallback?.toProgressWatcher()
)
}
Expand All @@ -374,14 +376,15 @@ class RustTimeline(
// Maybe allow a caption in the future?
caption = null,
formattedCaption = null,
storeInCache = true,
progressWatcher = progressCallback?.toProgressWatcher()
)
}
}

override suspend fun sendFile(file: File, fileInfo: FileInfo, progressCallback: ProgressCallback?): Result<MediaUploadHandler> {
return sendAttachment(listOf(file)) {
inner.sendFile(file.path, fileInfo.map(), progressCallback?.toProgressWatcher())
inner.sendFile(file.path, fileInfo.map(), false, progressCallback?.toProgressWatcher())
}
}

Expand Down Expand Up @@ -496,6 +499,7 @@ class RustTimeline(
// Maybe allow a caption in the future?
caption = null,
formattedCaption = null,
storeInCache = true,
progressWatcher = progressCallback?.toProgressWatcher(),
)
}
Expand Down

0 comments on commit a07d102

Please sign in to comment.