Toggle reactions from the timeline (#707)

This commit is contained in:
jonnyandrew 2023-06-28 13:02:04 +00:00 committed by GitHub
parent b66801a022
commit 366a800a2c
13 changed files with 84 additions and 33 deletions

View file

@ -26,7 +26,6 @@ import io.element.android.libraries.matrix.api.media.FileInfo
import io.element.android.libraries.matrix.api.media.ImageInfo
import io.element.android.libraries.matrix.api.media.VideoInfo
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
import io.element.android.libraries.matrix.api.timeline.item.event.MessageContent
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import java.io.Closeable
@ -83,7 +82,7 @@ interface MatrixRoom : Closeable {
suspend fun sendFile(file: File, fileInfo: FileInfo, progressCallback: ProgressCallback?): Result<Unit>
suspend fun sendReaction(emoji: String, eventId: EventId): Result<Unit>
suspend fun toggleReaction(emoji: String, eventId: EventId): Result<Unit>
suspend fun forwardEvent(eventId: EventId, rooms: List<RoomId>): Result<Unit>

View file

@ -63,7 +63,8 @@ class RustMatrixAuthenticationService @Inject constructor(
passphrase = null,
// TODO Oidc
// oidcClientMetadata = oidcClientMetadata,
customSlidingSyncProxy = null
customSlidingSyncProxy = null,
userAgent = null, // TODO
)
private var currentHomeserver = MutableStateFlow<MatrixHomeServerDetails?>(null)

View file

@ -273,9 +273,9 @@ class RustMatrixRoom(
}
}
override suspend fun sendReaction(emoji: String, eventId: EventId): Result<Unit> = withContext(coroutineDispatchers.io) {
override suspend fun toggleReaction(emoji: String, eventId: EventId): Result<Unit> = withContext(coroutineDispatchers.io) {
runCatching {
innerRoom.sendReaction(key = emoji, eventId = eventId.value)
innerRoom.toggleReaction(key = emoji, eventId = eventId.value)
}
}

View file

@ -72,7 +72,7 @@ class FakeMatrixRoom(
private var setTopicResult = Result.success(Unit)
private var updateAvatarResult = Result.success(Unit)
private var removeAvatarResult = Result.success(Unit)
private var sendReactionResult = Result.success(Unit)
private var toggleReactionResult = Result.success(Unit)
private var retrySendMessageResult = Result.success(Unit)
private var cancelSendResult = Result.success(Unit)
private var forwardEventResult = Result.success(Unit)
@ -82,8 +82,8 @@ class FakeMatrixRoom(
var sendMediaCount = 0
private set
var sendReactionCount = 0
private set
private val _myReactions = mutableSetOf<String>()
val myReactions: Set<String> = _myReactions
var retrySendMessageCount: Int = 0
private set
@ -146,9 +146,19 @@ class FakeMatrixRoom(
Result.success(Unit)
}
override suspend fun sendReaction(emoji: String, eventId: EventId): Result<Unit> {
sendReactionCount++
return sendReactionResult
override suspend fun toggleReaction(emoji: String, eventId: EventId): Result<Unit> {
if (toggleReactionResult.isFailure) {
// Don't do the toggle if we failed
return toggleReactionResult
}
if(_myReactions.contains(emoji)) {
_myReactions.remove(emoji)
} else {
_myReactions.add(emoji)
}
return toggleReactionResult
}
override suspend fun retrySendMessage(transactionId: String): Result<Unit> {
@ -348,8 +358,8 @@ class FakeMatrixRoom(
setTopicResult = result
}
fun givenSendReactionResult(result: Result<Unit>) {
sendReactionResult = result
fun givenToggleReactionResult(result: Result<Unit>) {
toggleReactionResult = result
}
fun givenRetrySendMessageResult(result: Result<Unit>) {