Merge branch 'develop' into feature/fga/clean_up
This commit is contained in:
commit
f001460a3a
252 changed files with 5060 additions and 1618 deletions
|
|
@ -19,6 +19,7 @@ package io.element.android.libraries.matrix.api
|
|||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.createroom.CreateRoomParameters
|
||||
import io.element.android.libraries.matrix.api.media.MediaResolver
|
||||
import io.element.android.libraries.matrix.api.notification.NotificationService
|
||||
import io.element.android.libraries.matrix.api.pusher.PushersService
|
||||
|
|
@ -32,8 +33,9 @@ interface MatrixClient : Closeable {
|
|||
val sessionId: SessionId
|
||||
val roomSummaryDataSource: RoomSummaryDataSource
|
||||
fun getRoom(roomId: RoomId): MatrixRoom?
|
||||
suspend fun createDM(userId: UserId): Result<RoomId>
|
||||
fun findDM(userId: UserId): MatrixRoom?
|
||||
suspend fun createRoom(createRoomParams: CreateRoomParameters): Result<RoomId>
|
||||
suspend fun createDM(userId: UserId): Result<RoomId>
|
||||
fun startSync()
|
||||
fun stopSync()
|
||||
fun mediaResolver(): MediaResolver
|
||||
|
|
|
|||
|
|
@ -16,9 +16,14 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.core
|
||||
|
||||
import io.element.android.libraries.matrix.api.BuildConfig
|
||||
import java.io.Serializable
|
||||
|
||||
@JvmInline
|
||||
value class EventId(val value: String) : Serializable
|
||||
|
||||
fun String.asEventId() = EventId(this)
|
||||
fun String.asEventId() = if (BuildConfig.DEBUG && !MatrixPatterns.isEventId(this)) {
|
||||
error("`$this` is not a valid event Id")
|
||||
} else {
|
||||
EventId(this)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,14 @@ object MatrixPatterns {
|
|||
PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER
|
||||
)
|
||||
|
||||
/**
|
||||
* Tells if a string is a valid session Id. This is an alias for [isUserId]
|
||||
*
|
||||
* @param str the string to test
|
||||
* @return true if the string is a valid session id
|
||||
*/
|
||||
fun isSessionId(str: String?) = isUserId(str)
|
||||
|
||||
/**
|
||||
* Tells if a string is a valid user Id.
|
||||
*
|
||||
|
|
@ -101,6 +109,14 @@ object MatrixPatterns {
|
|||
return str != null && str matches PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if a string is a valid space id. This is an alias for [isRoomId]
|
||||
*
|
||||
* @param str the string to test
|
||||
* @return true if the string is a valid space Id
|
||||
*/
|
||||
fun isSpaceId(str: String?) = isRoomId(str)
|
||||
|
||||
/**
|
||||
* Tells if a string is a valid room id.
|
||||
*
|
||||
|
|
@ -134,6 +150,14 @@ object MatrixPatterns {
|
|||
str matches PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER_V4)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if a string is a valid thread id. This is an alias for [isEventId].
|
||||
*
|
||||
* @param str the string to test
|
||||
* @return true if the string is a valid thread id.
|
||||
*/
|
||||
fun isThreadId(str: String?) = isEventId(str)
|
||||
|
||||
/**
|
||||
* Tells if a string is a valid group id.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,9 +16,18 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.core
|
||||
|
||||
import io.element.android.libraries.matrix.api.BuildConfig
|
||||
import java.io.Serializable
|
||||
|
||||
@JvmInline
|
||||
value class RoomId(val value: String) : Serializable
|
||||
value class RoomId(val value: String) : Serializable {
|
||||
override fun toString(): String {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
fun String.asRoomId() = RoomId(this)
|
||||
fun String.asRoomId() = if (BuildConfig.DEBUG && !MatrixPatterns.isRoomId(this)) {
|
||||
error("`$this` is not a valid room Id")
|
||||
} else {
|
||||
RoomId(this)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,12 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.core
|
||||
|
||||
import io.element.android.libraries.matrix.api.BuildConfig
|
||||
|
||||
typealias SessionId = UserId
|
||||
|
||||
fun String.asSessionId() = SessionId(this)
|
||||
fun String.asSessionId() = if (BuildConfig.DEBUG && !MatrixPatterns.isSessionId(this)) {
|
||||
error("`$this` is not a valid session Id")
|
||||
} else {
|
||||
SessionId(this)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.core
|
||||
|
||||
import io.element.android.libraries.matrix.api.BuildConfig
|
||||
import java.io.Serializable
|
||||
|
||||
@JvmInline
|
||||
|
|
@ -26,4 +27,8 @@ value class SpaceId(val value: String) : Serializable
|
|||
*/
|
||||
val MAIN_SPACE = SpaceId("!mainSpace")
|
||||
|
||||
fun String.asSpaceId() = SpaceId(this)
|
||||
fun String.asSpaceId() = if (BuildConfig.DEBUG && !MatrixPatterns.isSpaceId(this)) {
|
||||
error("`$this` is not a valid space Id")
|
||||
} else {
|
||||
SpaceId(this)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,14 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.core
|
||||
|
||||
import io.element.android.libraries.matrix.api.BuildConfig
|
||||
import java.io.Serializable
|
||||
|
||||
@JvmInline
|
||||
value class ThreadId(val value: String) : Serializable
|
||||
|
||||
fun String.asThreadId() = ThreadId(this)
|
||||
fun String.asThreadId() = if (BuildConfig.DEBUG && !MatrixPatterns.isThreadId(this)) {
|
||||
error("`$this` is not a valid thread Id")
|
||||
} else {
|
||||
ThreadId(this)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,18 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.core
|
||||
|
||||
import io.element.android.libraries.matrix.api.BuildConfig
|
||||
import java.io.Serializable
|
||||
|
||||
@JvmInline
|
||||
value class UserId(val value: String) : Serializable
|
||||
value class UserId(val value: String) : Serializable {
|
||||
override fun toString(): String {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
fun String.asUserId() = UserId(this)
|
||||
fun String.asUserId() = if (BuildConfig.DEBUG && !MatrixPatterns.isUserId(this)) {
|
||||
error("`$this` is not a valid user Id")
|
||||
} else {
|
||||
UserId(this)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.createroom
|
||||
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
|
||||
data class CreateRoomParameters(
|
||||
val name: String?,
|
||||
val topic: String? = null,
|
||||
val isEncrypted: Boolean,
|
||||
val isDirect: Boolean = false,
|
||||
val visibility: RoomVisibility,
|
||||
val preset: RoomPreset,
|
||||
val invite: List<UserId>? = null,
|
||||
val avatar: String? = null,
|
||||
)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.element.android.libraries.matrix.api.createroom
|
||||
|
||||
enum class RoomPreset {
|
||||
PRIVATE_CHAT,
|
||||
PUBLIC_CHAT,
|
||||
TRUSTED_PRIVATE_CHAT,
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.element.android.libraries.matrix.api.createroom
|
||||
|
||||
enum class RoomVisibility {
|
||||
PUBLIC,
|
||||
PRIVATE,
|
||||
}
|
||||
|
|
@ -19,8 +19,14 @@ package io.element.android.libraries.matrix.api.permalink
|
|||
import io.element.android.libraries.matrix.api.config.MatrixConfiguration
|
||||
import io.element.android.libraries.matrix.api.core.MatrixPatterns
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
|
||||
object PermalinkBuilder {
|
||||
|
||||
private const val ROOM_PATH = "room/"
|
||||
private const val USER_PATH = "user/"
|
||||
private const val GROUP_PATH = "group/"
|
||||
|
||||
private val permalinkBaseUrl get() = (MatrixConfiguration.clientPermalinkBaseUrl ?: MatrixConfiguration.matrixToPermalinkBaseUrl).also {
|
||||
var baseUrl = it
|
||||
if (!baseUrl.endsWith("/")) {
|
||||
|
|
@ -31,6 +37,21 @@ object PermalinkBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
fun permalinkForUser(userId: UserId): Result<String> {
|
||||
return if (MatrixPatterns.isUserId(userId.value)) {
|
||||
val url = buildString {
|
||||
append(permalinkBaseUrl)
|
||||
if (!isMatrixTo()) {
|
||||
append(USER_PATH)
|
||||
}
|
||||
append(userId.value)
|
||||
}
|
||||
Result.success(url)
|
||||
} else {
|
||||
Result.failure(PermalinkBuilderError.InvalidRoomAlias)
|
||||
}
|
||||
}
|
||||
|
||||
fun permalinkForRoomAlias(roomAlias: String): Result<String> {
|
||||
return if (MatrixPatterns.isRoomAlias(roomAlias)) {
|
||||
Result.success(permalinkForRoomAliasOrId(roomAlias))
|
||||
|
|
@ -49,10 +70,18 @@ object PermalinkBuilder {
|
|||
|
||||
private fun permalinkForRoomAliasOrId(value: String): String {
|
||||
val id = escapeId(value)
|
||||
return permalinkBaseUrl + id
|
||||
return buildString {
|
||||
append(permalinkBaseUrl)
|
||||
if (!isMatrixTo()) {
|
||||
append(ROOM_PATH)
|
||||
}
|
||||
append(id)
|
||||
}
|
||||
}
|
||||
|
||||
private fun escapeId(value: String) = value.replace("/", "%2F")
|
||||
|
||||
private fun isMatrixTo(): Boolean = permalinkBaseUrl.startsWith(MatrixConfiguration.matrixToPermalinkBaseUrl)
|
||||
}
|
||||
|
||||
sealed class PermalinkBuilderError : Throwable() {
|
||||
|
|
|
|||
|
|
@ -18,4 +18,5 @@ package io.element.android.libraries.matrix.api.pusher
|
|||
|
||||
interface PushersService {
|
||||
suspend fun setHttpPusher(setHttpPusherData: SetHttpPusherData): Result<Unit>
|
||||
suspend fun unsetHttpPusher(): Result<Unit>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.element.android.libraries.matrix.api.room
|
|||
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
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.timeline.MatrixTimeline
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import java.io.Closeable
|
||||
|
|
@ -38,6 +39,8 @@ interface MatrixRoom: Closeable {
|
|||
|
||||
suspend fun memberCount(): Int
|
||||
|
||||
fun getMember(userId: UserId): RoomMember?
|
||||
|
||||
fun syncUpdateFlow(): Flow<Long>
|
||||
|
||||
fun timeline(): MatrixTimeline
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.room
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class RoomMember(
|
||||
val userId: String,
|
||||
val displayName: String?,
|
||||
|
|
@ -23,8 +27,9 @@ data class RoomMember(
|
|||
val membership: RoomMembershipState,
|
||||
val isNameAmbiguous: Boolean,
|
||||
val powerLevel: Long,
|
||||
val normalizedPowerLevel: Long
|
||||
)
|
||||
val normalizedPowerLevel: Long,
|
||||
val isIgnored: Boolean,
|
||||
) : Parcelable
|
||||
|
||||
enum class RoomMembershipState {
|
||||
BAN, INVITE, JOIN, KNOCK, LEAVE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue