Pin : expose the new rust sdk apis
This commit is contained in:
parent
8ab74a7e9c
commit
2605ddec7a
8 changed files with 62 additions and 1 deletions
|
|
@ -180,6 +180,8 @@ interface MatrixRoom : Closeable {
|
||||||
|
|
||||||
suspend fun canUserTriggerRoomNotification(userId: UserId): Result<Boolean>
|
suspend fun canUserTriggerRoomNotification(userId: UserId): Result<Boolean>
|
||||||
|
|
||||||
|
suspend fun canUserPinUnpin(userId: UserId): Result<Boolean>
|
||||||
|
|
||||||
suspend fun canUserJoinCall(userId: UserId): Result<Boolean> =
|
suspend fun canUserJoinCall(userId: UserId): Result<Boolean> =
|
||||||
canUserSendState(userId, StateEventType.CALL_MEMBER)
|
canUserSendState(userId, StateEventType.CALL_MEMBER)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package io.element.android.libraries.matrix.api.room
|
package io.element.android.libraries.matrix.api.room
|
||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomAlias
|
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.core.UserId
|
import io.element.android.libraries.matrix.api.core.UserId
|
||||||
|
|
@ -52,4 +53,5 @@ data class MatrixRoomInfo(
|
||||||
val hasRoomCall: Boolean,
|
val hasRoomCall: Boolean,
|
||||||
val activeRoomCallParticipants: ImmutableList<String>,
|
val activeRoomCallParticipants: ImmutableList<String>,
|
||||||
val heroes: ImmutableList<MatrixUser>,
|
val heroes: ImmutableList<MatrixUser>,
|
||||||
|
val pinnedEventIds: ImmutableList<EventId>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -169,4 +169,23 @@ interface Timeline : AutoCloseable {
|
||||||
): Result<MediaUploadHandler>
|
): Result<MediaUploadHandler>
|
||||||
|
|
||||||
suspend fun loadReplyDetails(eventId: EventId): InReplyTo
|
suspend fun loadReplyDetails(eventId: EventId): InReplyTo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new pinned event by sending an updated `m.room.pinned_events`
|
||||||
|
* event containing the new event id.
|
||||||
|
*
|
||||||
|
* Returns `true` if we sent the request, `false` if the event was already
|
||||||
|
* pinned.
|
||||||
|
*/
|
||||||
|
suspend fun pinEvent(eventId: EventId): Result<Boolean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new pinned event by sending an updated `m.room.pinned_events`
|
||||||
|
* event without the event id we want to remove.
|
||||||
|
*
|
||||||
|
* Returns `true` if we sent the request, `false` if the event wasn't
|
||||||
|
* pinned
|
||||||
|
*/
|
||||||
|
suspend fun unpinEvent(eventId: EventId): Result<Boolean>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package io.element.android.libraries.matrix.impl.room
|
package io.element.android.libraries.matrix.impl.room
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomAlias
|
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.core.UserId
|
import io.element.android.libraries.matrix.api.core.UserId
|
||||||
|
|
@ -58,7 +59,8 @@ class MatrixRoomInfoMapper {
|
||||||
userDefinedNotificationMode = it.userDefinedNotificationMode?.map(),
|
userDefinedNotificationMode = it.userDefinedNotificationMode?.map(),
|
||||||
hasRoomCall = it.hasRoomCall,
|
hasRoomCall = it.hasRoomCall,
|
||||||
activeRoomCallParticipants = it.activeRoomCallParticipants.toImmutableList(),
|
activeRoomCallParticipants = it.activeRoomCallParticipants.toImmutableList(),
|
||||||
heroes = it.elementHeroes().toImmutableList()
|
heroes = it.elementHeroes().toImmutableList(),
|
||||||
|
pinnedEventIds = it.pinnedEventIds.map(::EventId).toImmutableList(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -403,6 +403,12 @@ class RustMatrixRoom(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun canUserPinUnpin(userId: UserId): Result<Boolean> {
|
||||||
|
return runCatching {
|
||||||
|
innerRoom.canUserPinUnpin(userId.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun sendImage(
|
override suspend fun sendImage(
|
||||||
file: File,
|
file: File,
|
||||||
thumbnailFile: File?,
|
thumbnailFile: File?,
|
||||||
|
|
|
||||||
|
|
@ -525,6 +525,18 @@ class RustTimeline(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun pinEvent(eventId: EventId): Result<Boolean> = withContext(dispatcher) {
|
||||||
|
runCatching {
|
||||||
|
inner.pinEvent(eventId = eventId.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun unpinEvent(eventId: EventId): Result<Boolean> = withContext(dispatcher) {
|
||||||
|
runCatching {
|
||||||
|
inner.unpinEvent(eventId = eventId.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun fetchDetailsForEvent(eventId: EventId): Result<Unit> {
|
private suspend fun fetchDetailsForEvent(eventId: EventId): Result<Unit> {
|
||||||
return runCatching {
|
return runCatching {
|
||||||
inner.fetchDetailsForEvent(eventId.value)
|
inner.fetchDetailsForEvent(eventId.value)
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ class FakeMatrixRoom(
|
||||||
private val getWidgetDriverResult: (MatrixWidgetSettings) -> Result<MatrixWidgetDriver> = { lambdaError() },
|
private val getWidgetDriverResult: (MatrixWidgetSettings) -> Result<MatrixWidgetDriver> = { lambdaError() },
|
||||||
private val canUserTriggerRoomNotificationResult: (UserId) -> Result<Boolean> = { lambdaError() },
|
private val canUserTriggerRoomNotificationResult: (UserId) -> Result<Boolean> = { lambdaError() },
|
||||||
private val canUserJoinCallResult: (UserId) -> Result<Boolean> = { lambdaError() },
|
private val canUserJoinCallResult: (UserId) -> Result<Boolean> = { lambdaError() },
|
||||||
|
private val canUserPinUnpinResult: (UserId) -> Result<Boolean> = { lambdaError() },
|
||||||
private val setIsFavoriteResult: (Boolean) -> Result<Unit> = { lambdaError() },
|
private val setIsFavoriteResult: (Boolean) -> Result<Unit> = { lambdaError() },
|
||||||
private val powerLevelsResult: () -> Result<MatrixRoomPowerLevels> = { lambdaError() },
|
private val powerLevelsResult: () -> Result<MatrixRoomPowerLevels> = { lambdaError() },
|
||||||
private val updatePowerLevelsResult: () -> Result<Unit> = { lambdaError() },
|
private val updatePowerLevelsResult: () -> Result<Unit> = { lambdaError() },
|
||||||
|
|
@ -289,6 +290,10 @@ class FakeMatrixRoom(
|
||||||
return canUserJoinCallResult(userId)
|
return canUserJoinCallResult(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun canUserPinUnpin(userId: UserId): Result<Boolean> {
|
||||||
|
return canUserPinUnpinResult(userId)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun sendImage(
|
override suspend fun sendImage(
|
||||||
file: File,
|
file: File,
|
||||||
thumbnailFile: File?,
|
thumbnailFile: File?,
|
||||||
|
|
@ -517,6 +522,7 @@ fun aRoomInfo(
|
||||||
userPowerLevels: ImmutableMap<UserId, Long> = persistentMapOf(),
|
userPowerLevels: ImmutableMap<UserId, Long> = persistentMapOf(),
|
||||||
activeRoomCallParticipants: List<String> = emptyList(),
|
activeRoomCallParticipants: List<String> = emptyList(),
|
||||||
heroes: List<MatrixUser> = emptyList(),
|
heroes: List<MatrixUser> = emptyList(),
|
||||||
|
pinnedEventIds: List<EventId> = emptyList(),
|
||||||
) = MatrixRoomInfo(
|
) = MatrixRoomInfo(
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
|
|
@ -542,6 +548,7 @@ fun aRoomInfo(
|
||||||
userPowerLevels = userPowerLevels,
|
userPowerLevels = userPowerLevels,
|
||||||
activeRoomCallParticipants = activeRoomCallParticipants.toImmutableList(),
|
activeRoomCallParticipants = activeRoomCallParticipants.toImmutableList(),
|
||||||
heroes = heroes.toImmutableList(),
|
heroes = heroes.toImmutableList(),
|
||||||
|
pinnedEventIds = pinnedEventIds.toImmutableList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun defaultRoomPowerLevels() = MatrixRoomPowerLevels(
|
fun defaultRoomPowerLevels() = MatrixRoomPowerLevels(
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import io.element.android.libraries.matrix.api.timeline.ReceiptType
|
||||||
import io.element.android.libraries.matrix.api.timeline.Timeline
|
import io.element.android.libraries.matrix.api.timeline.Timeline
|
||||||
import io.element.android.libraries.matrix.api.timeline.item.event.InReplyTo
|
import io.element.android.libraries.matrix.api.timeline.item.event.InReplyTo
|
||||||
import io.element.android.libraries.matrix.test.media.FakeMediaUploadHandler
|
import io.element.android.libraries.matrix.test.media.FakeMediaUploadHandler
|
||||||
|
import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
@ -371,6 +372,16 @@ class FakeTimeline(
|
||||||
|
|
||||||
override suspend fun loadReplyDetails(eventId: EventId) = loadReplyDetailsLambda(eventId)
|
override suspend fun loadReplyDetails(eventId: EventId) = loadReplyDetailsLambda(eventId)
|
||||||
|
|
||||||
|
var pinEventLambda: (eventId: EventId) -> Result<Boolean> = lambdaError()
|
||||||
|
override suspend fun pinEvent(eventId: EventId): Result<Boolean> {
|
||||||
|
return pinEventLambda(eventId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var unpinEventLambda: (eventId: EventId) -> Result<Boolean> = lambdaError()
|
||||||
|
override suspend fun unpinEvent(eventId: EventId): Result<Boolean> {
|
||||||
|
return unpinEventLambda(eventId)
|
||||||
|
}
|
||||||
|
|
||||||
var closeCounter = 0
|
var closeCounter = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue