Skip to content

Commit 52a643f

Browse files
committed
Pin : expose the new rust sdk apis
1 parent bcfda2e commit 52a643f

File tree

8 files changed

+62
-1
lines changed

8 files changed

+62
-1
lines changed

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ interface MatrixRoom : Closeable {
180180

181181
suspend fun canUserTriggerRoomNotification(userId: UserId): Result<Boolean>
182182

183+
suspend fun canUserPinUnpin(userId: UserId): Result<Boolean>
184+
183185
suspend fun canUserJoinCall(userId: UserId): Result<Boolean> =
184186
canUserSendState(userId, StateEventType.CALL_MEMBER)
185187

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoomInfo.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.element.android.libraries.matrix.api.room
1818

1919
import androidx.compose.runtime.Immutable
20+
import io.element.android.libraries.matrix.api.core.EventId
2021
import io.element.android.libraries.matrix.api.core.RoomAlias
2122
import io.element.android.libraries.matrix.api.core.RoomId
2223
import io.element.android.libraries.matrix.api.core.UserId
@@ -52,4 +53,5 @@ data class MatrixRoomInfo(
5253
val hasRoomCall: Boolean,
5354
val activeRoomCallParticipants: ImmutableList<String>,
5455
val heroes: ImmutableList<MatrixUser>,
56+
val pinnedEventIds: ImmutableList<EventId>
5557
)

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/Timeline.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,23 @@ interface Timeline : AutoCloseable {
169169
): Result<MediaUploadHandler>
170170

171171
suspend fun loadReplyDetails(eventId: EventId): InReplyTo
172+
173+
/**
174+
* Adds a new pinned event by sending an updated `m.room.pinned_events`
175+
* event containing the new event id.
176+
*
177+
* Returns `true` if we sent the request, `false` if the event was already
178+
* pinned.
179+
*/
180+
suspend fun pinEvent(eventId: EventId): Result<Boolean>
181+
182+
/**
183+
* Adds a new pinned event by sending an updated `m.room.pinned_events`
184+
* event without the event id we want to remove.
185+
*
186+
* Returns `true` if we sent the request, `false` if the event wasn't
187+
* pinned
188+
*/
189+
suspend fun unpinEvent(eventId: EventId): Result<Boolean>
190+
172191
}

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/MatrixRoomInfoMapper.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.element.android.libraries.matrix.impl.room
1818

19+
import io.element.android.libraries.matrix.api.core.EventId
1920
import io.element.android.libraries.matrix.api.core.RoomAlias
2021
import io.element.android.libraries.matrix.api.core.RoomId
2122
import io.element.android.libraries.matrix.api.core.UserId
@@ -58,7 +59,8 @@ class MatrixRoomInfoMapper {
5859
userDefinedNotificationMode = it.userDefinedNotificationMode?.map(),
5960
hasRoomCall = it.hasRoomCall,
6061
activeRoomCallParticipants = it.activeRoomCallParticipants.toImmutableList(),
61-
heroes = it.elementHeroes().toImmutableList()
62+
heroes = it.elementHeroes().toImmutableList(),
63+
pinnedEventIds = it.pinnedEventIds.map(::EventId).toImmutableList(),
6264
)
6365
}
6466
}

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ class RustMatrixRoom(
403403
}
404404
}
405405

406+
override suspend fun canUserPinUnpin(userId: UserId): Result<Boolean> {
407+
return runCatching {
408+
innerRoom.canUserPinUnpin(userId.value)
409+
}
410+
}
411+
406412
override suspend fun sendImage(
407413
file: File,
408414
thumbnailFile: File?,

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ class RustTimeline(
525525
}
526526
}
527527

528+
override suspend fun pinEvent(eventId: EventId): Result<Boolean> = withContext(dispatcher) {
529+
runCatching {
530+
inner.pinEvent(eventId = eventId.value)
531+
}
532+
}
533+
534+
override suspend fun unpinEvent(eventId: EventId): Result<Boolean> = withContext(dispatcher) {
535+
runCatching {
536+
inner.unpinEvent(eventId = eventId.value)
537+
}
538+
}
539+
528540
private suspend fun fetchDetailsForEvent(eventId: EventId): Result<Unit> {
529541
return runCatching {
530542
inner.fetchDetailsForEvent(eventId.value)

libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class FakeMatrixRoom(
125125
private val getWidgetDriverResult: (MatrixWidgetSettings) -> Result<MatrixWidgetDriver> = { lambdaError() },
126126
private val canUserTriggerRoomNotificationResult: (UserId) -> Result<Boolean> = { lambdaError() },
127127
private val canUserJoinCallResult: (UserId) -> Result<Boolean> = { lambdaError() },
128+
private val canUserPinUnpinResult: (UserId) -> Result<Boolean> = { lambdaError() },
128129
private val setIsFavoriteResult: (Boolean) -> Result<Unit> = { lambdaError() },
129130
private val powerLevelsResult: () -> Result<MatrixRoomPowerLevels> = { lambdaError() },
130131
private val updatePowerLevelsResult: () -> Result<Unit> = { lambdaError() },
@@ -289,6 +290,10 @@ class FakeMatrixRoom(
289290
return canUserJoinCallResult(userId)
290291
}
291292

293+
override suspend fun canUserPinUnpin(userId: UserId): Result<Boolean> {
294+
return canUserPinUnpinResult(userId)
295+
}
296+
292297
override suspend fun sendImage(
293298
file: File,
294299
thumbnailFile: File?,
@@ -517,6 +522,7 @@ fun aRoomInfo(
517522
userPowerLevels: ImmutableMap<UserId, Long> = persistentMapOf(),
518523
activeRoomCallParticipants: List<String> = emptyList(),
519524
heroes: List<MatrixUser> = emptyList(),
525+
pinnedEventIds: List<EventId> = emptyList(),
520526
) = MatrixRoomInfo(
521527
id = id,
522528
name = name,
@@ -542,6 +548,7 @@ fun aRoomInfo(
542548
userPowerLevels = userPowerLevels,
543549
activeRoomCallParticipants = activeRoomCallParticipants.toImmutableList(),
544550
heroes = heroes.toImmutableList(),
551+
pinnedEventIds = pinnedEventIds.toImmutableList(),
545552
)
546553

547554
fun defaultRoomPowerLevels() = MatrixRoomPowerLevels(

libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/timeline/FakeTimeline.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import io.element.android.libraries.matrix.api.timeline.ReceiptType
3333
import io.element.android.libraries.matrix.api.timeline.Timeline
3434
import io.element.android.libraries.matrix.api.timeline.item.event.InReplyTo
3535
import io.element.android.libraries.matrix.test.media.FakeMediaUploadHandler
36+
import io.element.android.tests.testutils.lambda.lambdaError
3637
import kotlinx.coroutines.flow.Flow
3738
import kotlinx.coroutines.flow.MutableSharedFlow
3839
import kotlinx.coroutines.flow.MutableStateFlow
@@ -371,6 +372,16 @@ class FakeTimeline(
371372

372373
override suspend fun loadReplyDetails(eventId: EventId) = loadReplyDetailsLambda(eventId)
373374

375+
var pinEventLambda: (eventId: EventId) -> Result<Boolean> = lambdaError()
376+
override suspend fun pinEvent(eventId: EventId): Result<Boolean> {
377+
return pinEventLambda(eventId)
378+
}
379+
380+
var unpinEventLambda: (eventId: EventId) -> Result<Boolean> = lambdaError()
381+
override suspend fun unpinEvent(eventId: EventId): Result<Boolean> {
382+
return unpinEventLambda(eventId)
383+
}
384+
374385
var closeCounter = 0
375386
private set
376387

0 commit comments

Comments
 (0)