Merge branch 'develop' into feature/fga/mark_room_as_favorite

This commit is contained in:
ganfra 2024-02-15 10:16:43 +01:00
commit e00311a739
282 changed files with 718 additions and 300 deletions

View file

@ -29,7 +29,6 @@ import io.element.android.libraries.matrix.api.media.MediaUploadHandler
import io.element.android.libraries.matrix.api.media.VideoInfo
import io.element.android.libraries.matrix.api.poll.PollKind
import io.element.android.libraries.matrix.api.room.location.AssetType
import io.element.android.libraries.matrix.api.room.tags.RoomNotableTags
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
import io.element.android.libraries.matrix.api.timeline.ReceiptType
import io.element.android.libraries.matrix.api.widget.MatrixWidgetDriver
@ -60,11 +59,6 @@ interface MatrixRoom : Closeable {
val roomInfoFlow: Flow<MatrixRoomInfo>
val roomTypingMembersFlow: Flow<List<UserId>>
/**
* The current notable tags as a Flow.
*/
val notableTagsFlow: Flow<RoomNotableTags>
/**
* A one-to-one is a room with exactly 2 members.
* See [the Matrix spec](https://spec.matrix.org/latest/client-server-api/#default-underride-rules).
@ -161,15 +155,17 @@ interface MatrixRoom : Closeable {
suspend fun setIsFavorite(isFavorite: Boolean): Result<Unit>
/**
* Reverts a previously set unread flag, and eventually send a Read Receipt.
* @param receiptType The type of receipt to send. If null, no Read Receipt will be sent.
* Mark the room as read by trying to attach an unthreaded read receipt to the latest room event.
* @param receiptType The type of receipt to send.
*/
suspend fun markAsRead(receiptType: ReceiptType?): Result<Unit>
suspend fun markAsRead(receiptType: ReceiptType): Result<Unit>
/**
* Sets a flag on the room to indicate that the user has explicitly marked it as unread.
* Sets a flag on the room to indicate that the user has explicitly marked it as unread, or reverts the flag.
* @param isUnread true to mark the room as unread, false to remove the flag.
*
*/
suspend fun markAsUnread(): Result<Unit>
suspend fun setUnreadFlag(isUnread: Boolean): Result<Unit>
/**
* Share a location message in the room.

View file

@ -30,6 +30,7 @@ data class MatrixRoomInfo(
val isPublic: Boolean,
val isSpace: Boolean,
val isTombstoned: Boolean,
val isFavorite: Boolean,
val canonicalAlias: String?,
val alternativeAliases: ImmutableList<String>,
val currentUserMembership: CurrentUserMembership,

View file

@ -1,27 +0,0 @@
/*
* Copyright (c) 2024 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.room.tags
/**
* Represents the notable tags of a room.
* @param isFavorite true if the room is marked as favorite.
* @param isLowPriority true if the room is marked as low priority.
*/
data class RoomNotableTags(
val isFavorite: Boolean = false,
val isLowPriority: Boolean = false,
)

View file

@ -48,6 +48,7 @@ data class RoomSummaryDetails(
val userDefinedNotificationMode: RoomNotificationMode?,
val hasRoomCall: Boolean,
val isDm: Boolean,
val isFavorite: Boolean,
) {
val lastMessageTimestamp = lastMessage?.originServerTs
}

View file

@ -40,6 +40,7 @@ class MatrixRoomInfoMapper(
isPublic = it.isPublic,
isSpace = it.isSpace,
isTombstoned = it.isTombstoned,
isFavorite = it.isFavourite,
canonicalAlias = it.canonicalAlias,
alternativeAliases = it.alternativeAliases.toImmutableList(),
currentUserMembership = it.membership.map(),

View file

@ -39,7 +39,6 @@ import io.element.android.libraries.matrix.api.room.MessageEventType
import io.element.android.libraries.matrix.api.room.StateEventType
import io.element.android.libraries.matrix.api.room.location.AssetType
import io.element.android.libraries.matrix.api.room.roomNotificationSettings
import io.element.android.libraries.matrix.api.room.tags.RoomNotableTags
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
import io.element.android.libraries.matrix.api.timeline.ReceiptType
import io.element.android.libraries.matrix.api.widget.MatrixWidgetDriver
@ -52,7 +51,6 @@ import io.element.android.libraries.matrix.impl.notificationsettings.RustNotific
import io.element.android.libraries.matrix.impl.poll.toInner
import io.element.android.libraries.matrix.impl.room.location.toInner
import io.element.android.libraries.matrix.impl.room.member.RoomMemberListFetcher
import io.element.android.libraries.matrix.impl.room.tags.map
import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
import io.element.android.libraries.matrix.impl.timeline.toRustReceiptType
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
@ -74,7 +72,6 @@ import org.matrix.rustcomponents.sdk.RoomInfo
import org.matrix.rustcomponents.sdk.RoomInfoListener
import org.matrix.rustcomponents.sdk.RoomListItem
import org.matrix.rustcomponents.sdk.RoomMessageEventContentWithoutRelation
import org.matrix.rustcomponents.sdk.RoomNotableTagsListener
import org.matrix.rustcomponents.sdk.SendAttachmentJoinHandle
import org.matrix.rustcomponents.sdk.TypingNotificationsListener
import org.matrix.rustcomponents.sdk.WidgetCapabilities
@ -86,7 +83,6 @@ import timber.log.Timber
import java.io.File
import org.matrix.rustcomponents.sdk.Room as InnerRoom
import org.matrix.rustcomponents.sdk.Timeline as InnerTimeline
import uniffi.matrix_sdk_base.RoomNotableTags as RustRoomNotableTags
@OptIn(ExperimentalCoroutinesApi::class)
class RustMatrixRoom(
@ -118,15 +114,6 @@ class RustMatrixRoom(
})
}
override val notableTagsFlow: Flow<RoomNotableTags> = mxCallbackFlow {
innerRoom.subscribeToNotableTags(object : RoomNotableTagsListener {
override fun call(notableTags: RustRoomNotableTags) {
channel.trySend(notableTags.map())
}
})
}
override val roomTypingMembersFlow: Flow<List<UserId>> = mxCallbackFlow {
launch {
val initial = emptyList<UserId>()
@ -457,23 +444,19 @@ class RustMatrixRoom(
override suspend fun setIsFavorite(isFavorite: Boolean): Result<Unit> = withContext(roomDispatcher) {
runCatching {
innerRoom.setIsFavorite(isFavorite, null)
innerRoom.setIsFavourite(isFavorite, null)
}
}
override suspend fun markAsRead(receiptType: ReceiptType?): Result<Unit> = withContext(roomDispatcher) {
override suspend fun markAsRead(receiptType: ReceiptType): Result<Unit> = withContext(roomDispatcher) {
runCatching {
if (receiptType != null) {
innerRoom.markAsReadAndSendReadReceipt(receiptType.toRustReceiptType())
} else {
innerRoom.markAsRead()
}
innerRoom.markAsRead(receiptType.toRustReceiptType())
}
}
override suspend fun markAsUnread(): Result<Unit> = withContext(roomDispatcher) {
override suspend fun setUnreadFlag(isUnread: Boolean): Result<Unit> = withContext(roomDispatcher) {
runCatching {
innerRoom.markAsUnread()
innerRoom.setUnreadFlag(isUnread)
}
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2024 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.impl.room.tags
import io.element.android.libraries.matrix.api.room.tags.RoomNotableTags
import uniffi.matrix_sdk_base.RoomNotableTags as RustRoomNotableTags
fun RustRoomNotableTags.map() = RoomNotableTags(
isFavorite = isFavorite,
isLowPriority = isLowPriority
)
fun RoomNotableTags.map() = RustRoomNotableTags(
isFavorite = isFavorite,
isLowPriority = isLowPriority
)

View file

@ -44,6 +44,7 @@ class RoomSummaryDetailsFactory(private val roomMessageFactory: RoomMessageFacto
userDefinedNotificationMode = roomInfo.userDefinedNotificationMode?.let(RoomNotificationSettingsMapper::mapMode),
hasRoomCall = roomInfo.hasRoomCall,
isDm = roomInfo.isDirect && roomInfo.activeMembersCount.toLong() == 2L,
isFavorite = roomInfo.isFavourite,
)
}
}

View file

@ -40,7 +40,6 @@ import io.element.android.libraries.matrix.api.room.RoomMember
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
import io.element.android.libraries.matrix.api.room.StateEventType
import io.element.android.libraries.matrix.api.room.location.AssetType
import io.element.android.libraries.matrix.api.room.tags.RoomNotableTags
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
import io.element.android.libraries.matrix.api.timeline.ReceiptType
import io.element.android.libraries.matrix.api.timeline.item.event.EventTimelineItem
@ -172,9 +171,6 @@ class FakeMatrixRoom(
private val _roomInfoFlow: MutableSharedFlow<MatrixRoomInfo> = MutableSharedFlow(replay = 1)
override val roomInfoFlow: Flow<MatrixRoomInfo> = _roomInfoFlow
private val _notableTagsFlow: MutableStateFlow<RoomNotableTags> = MutableStateFlow(aRoomNotableTags())
override val notableTagsFlow: Flow<RoomNotableTags> = _notableTagsFlow
private val _roomTypingMembersFlow: MutableSharedFlow<List<UserId>> = MutableSharedFlow(replay = 1)
override val roomTypingMembersFlow: Flow<List<UserId>> = _roomTypingMembersFlow
@ -383,33 +379,26 @@ class FakeMatrixRoom(
return reportContentResult
}
val setIsFavoriteCalls = mutableListOf<Boolean>()
override suspend fun setIsFavorite(isFavorite: Boolean): Result<Unit> {
return setIsFavoriteResult.also { result ->
if (result.isSuccess) {
val lowPriority = if (isFavorite) {
false
} else {
_notableTagsFlow.value.isLowPriority
}
val notableTags = RoomNotableTags(isFavorite, lowPriority)
_notableTagsFlow.emit(notableTags)
}
return setIsFavoriteResult.also {
setIsFavoriteCalls.add(isFavorite)
}
}
val markAsReadCalls = mutableListOf<ReceiptType>()
val markAsReadCalls = mutableListOf<ReceiptType?>()
override suspend fun markAsRead(receiptType: ReceiptType?): Result<Unit> {
override suspend fun markAsRead(receiptType: ReceiptType): Result<Unit> {
markAsReadCalls.add(receiptType)
return Result.success(Unit)
}
var markAsUnreadReadCallCount = 0
var setUnreadFlagCalls = mutableListOf<Boolean>()
private set
override suspend fun markAsUnread(): Result<Unit> {
markAsUnreadReadCallCount++
override suspend fun setUnreadFlag(isUnread: Boolean): Result<Unit> {
setUnreadFlagCalls.add(isUnread)
return Result.success(Unit)
}
@ -657,6 +646,7 @@ fun aRoomInfo(
isPublic: Boolean = true,
isSpace: Boolean = false,
isTombstoned: Boolean = false,
isFavorite: Boolean = false,
canonicalAlias: String? = null,
alternativeAliases: List<String> = emptyList(),
currentUserMembership: CurrentUserMembership = CurrentUserMembership.JOINED,
@ -679,6 +669,7 @@ fun aRoomInfo(
isPublic = isPublic,
isSpace = isSpace,
isTombstoned = isTombstoned,
isFavorite = isFavorite,
canonicalAlias = canonicalAlias,
alternativeAliases = alternativeAliases.toImmutableList(),
currentUserMembership = currentUserMembership,
@ -693,9 +684,3 @@ fun aRoomInfo(
hasRoomCall = hasRoomCall,
activeRoomCallParticipants = activeRoomCallParticipants.toImmutableList(),
)
fun aRoomNotableTags(
isFavorite: Boolean = false,
) = RoomNotableTags(
isFavorite = isFavorite,
)

View file

@ -68,6 +68,7 @@ fun aRoomSummaryDetails(
canonicalAlias: String? = null,
hasRoomCall: Boolean = false,
isDm: Boolean = false,
isFavorite: Boolean = false,
) = RoomSummaryDetails(
roomId = roomId,
name = name,
@ -83,6 +84,7 @@ fun aRoomSummaryDetails(
canonicalAlias = canonicalAlias,
hasRoomCall = hasRoomCall,
isDm = isDm,
isFavorite = isFavorite,
)
fun aRoomMessage(

View file

@ -117,6 +117,7 @@ fun aRoomSummaryDetails(
numUnreadMessages: Int = 0,
numUnreadNotifications: Int = 0,
isMarkedUnread: Boolean = false,
isFavorite: Boolean = false,
) = RoomSummaryDetails(
roomId = roomId,
name = name,
@ -132,4 +133,5 @@ fun aRoomSummaryDetails(
numUnreadMessages = numUnreadMessages,
numUnreadNotifications = numUnreadNotifications,
isMarkedUnread = isMarkedUnread,
isFavorite = isFavorite,
)