diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c8af411131..0d52d1e0df 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -146,7 +146,7 @@ jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" } appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" } molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" } timber = "com.jakewharton.timber:timber:5.0.1" -matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.47" +matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.48" sqldelight-driver-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" } sqldelight-driver-jvm = { module = "com.squareup.sqldelight:sqlite-driver", version.ref = "sqldelight" } sqldelight-coroutines = { module = "com.squareup.sqldelight:coroutines-extensions", version.ref = "sqldelight" } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt index 88d35c83d4..41f105df8e 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt @@ -157,6 +157,22 @@ interface MatrixRoom : Closeable { pollKind: PollKind, ): Result + /** + * Send a response to a poll. + * + * @param pollStartId The event ID of the poll start event. + * @param answers The list of answer ids to send. + */ + suspend fun sendPollResponse(pollStartId: EventId, answers: List): Result + + /** + * Ends a poll in the room. + * + * @param pollStartId The event ID of the poll start event. + * @param text Fallback text of the poll end event. + */ + suspend fun endPoll(pollStartId: EventId, text: String): Result + override fun close() = destroy() } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt index 401fa0ce83..dae032f516 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt @@ -23,6 +23,7 @@ val oidcConfiguration: OidcConfiguration = OidcConfiguration( clientName = "Element", redirectUri = OidcConfig.redirectUri, clientUri = "https://element.io", + logoUri = "https://element.io/mobile-icon.png", tosUri = "https://element.io/user-terms-of-service", policyUri = "https://element.io/privacy", /** diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt index ffe06379d3..71caed8f19 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt @@ -215,7 +215,7 @@ class RustMatrixRoom( override suspend fun editMessage(originalEventId: EventId?, transactionId: TransactionId?, message: String): Result = withContext(roomDispatcher) { if (originalEventId != null) { runCatching { - innerRoom.edit(/* TODO use content */ message, originalEventId.value, transactionId?.value) + innerRoom.edit(messageEventContentFromMarkdown(message), originalEventId.value, transactionId?.value) } } else { runCatching { @@ -226,10 +226,8 @@ class RustMatrixRoom( } override suspend fun replyMessage(eventId: EventId, message: String): Result = withContext(roomDispatcher) { - val transactionId = genTransactionId() - // val content = messageEventContentFromMarkdown(message) runCatching { - innerRoom.sendReply(/* TODO use content */ message, eventId.value, transactionId) + innerRoom.sendReply(messageEventContentFromMarkdown(message), eventId.value, genTransactionId()) } } @@ -402,6 +400,32 @@ class RustMatrixRoom( } } + override suspend fun sendPollResponse( + pollStartId: EventId, + answers: List + ): Result = withContext(roomDispatcher) { + runCatching { + innerRoom.sendPollResponse( + pollStartId = pollStartId.value, + answers = answers, + txnId = genTransactionId(), + ) + } + } + + override suspend fun endPoll( + pollStartId: EventId, + text: String + ): Result = withContext(roomDispatcher) { + runCatching { + innerRoom.endPoll( + pollStartId = pollStartId.value, + text = text, + txnId = genTransactionId(), + ) + } + } + private suspend fun sendAttachment(files: List, handle: () -> SendAttachmentJoinHandle): Result { return runCatching { MediaUploadHandlerImpl(files, handle()) diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt index 88f705162e..7bffb985bb 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt @@ -85,6 +85,8 @@ class FakeMatrixRoom( private var reportContentResult = Result.success(Unit) private var sendLocationResult = Result.success(Unit) private var createPollResult = Result.success(Unit) + private var sendPollResponseResult = Result.success(Unit) + private var endPollResult = Result.success(Unit) private var progressCallbackValues = emptyList>() val editMessageCalls = mutableListOf() @@ -109,6 +111,12 @@ class FakeMatrixRoom( private val _createPollInvocations = mutableListOf() val createPollInvocations: List = _createPollInvocations + private val _sendPollResponseInvocations = mutableListOf() + val sendPollResponseInvocations: List = _sendPollResponseInvocations + + private val _endPollInvocations = mutableListOf() + val endPollInvocations: List = _endPollInvocations + var invitedUserId: UserId? = null private set @@ -320,6 +328,22 @@ class FakeMatrixRoom( return createPollResult } + override suspend fun sendPollResponse( + pollStartId: EventId, + answers: List + ): Result = simulateLongTask { + _sendPollResponseInvocations.add(SendPollResponseInvocation(pollStartId, answers)) + return sendPollResponseResult + } + + override suspend fun endPoll( + pollStartId: EventId, + text: String + ): Result = simulateLongTask { + _endPollInvocations.add(EndPollInvocation(pollStartId, text)) + return endPollResult + } + fun givenLeaveRoomError(throwable: Throwable?) { this.leaveRoomError = throwable } @@ -416,6 +440,14 @@ class FakeMatrixRoom( createPollResult = result } + fun givenSendPollResponseResult(result: Result) { + sendPollResponseResult = result + } + + fun givenEndPollResult(result: Result) { + endPollResult = result + } + fun givenProgressCallbackValues(values: List>) { progressCallbackValues = values } @@ -435,3 +467,13 @@ data class CreatePollInvocation( val maxSelections: Int, val pollKind: PollKind, ) + +data class SendPollResponseInvocation( + val pollStartId: EventId, + val answers: List, +) + +data class EndPollInvocation( + val pollStartId: EventId, + val text: String, +)