Display a banner instead of the composer when user cannot post message to a room (#602)
This commit is contained in:
parent
21f59442bd
commit
dfcbb33c0a
11 changed files with 199 additions and 10 deletions
|
|
@ -19,6 +19,7 @@ package io.element.android.features.messages.impl
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
|
@ -55,6 +56,7 @@ import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
|
||||||
import io.element.android.libraries.designsystem.utils.handleSnackbarMessage
|
import io.element.android.libraries.designsystem.utils.handleSnackbarMessage
|
||||||
import io.element.android.libraries.matrix.api.core.EventId
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
|
import io.element.android.libraries.matrix.api.room.MessageEventType
|
||||||
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailInfo
|
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailInfo
|
||||||
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailType
|
import io.element.android.libraries.matrix.ui.components.AttachmentThumbnailType
|
||||||
import io.element.android.libraries.textcomposer.MessageComposerMode
|
import io.element.android.libraries.textcomposer.MessageComposerMode
|
||||||
|
|
@ -86,6 +88,7 @@ class MessagesPresenter @Inject constructor(
|
||||||
val retryState = retrySendMenuPresenter.present()
|
val retryState = retrySendMenuPresenter.present()
|
||||||
|
|
||||||
val syncUpdateFlow = room.syncUpdateFlow().collectAsState(0L)
|
val syncUpdateFlow = room.syncUpdateFlow().collectAsState(0L)
|
||||||
|
val userHasPermissionToSendMessage by getCanSendEvent(MessageEventType.ROOM_MESSAGE)
|
||||||
val roomName: MutableState<String?> = rememberSaveable {
|
val roomName: MutableState<String?> = rememberSaveable {
|
||||||
mutableStateOf(null)
|
mutableStateOf(null)
|
||||||
}
|
}
|
||||||
|
|
@ -125,6 +128,7 @@ class MessagesPresenter @Inject constructor(
|
||||||
roomId = room.roomId,
|
roomId = room.roomId,
|
||||||
roomName = roomName.value,
|
roomName = roomName.value,
|
||||||
roomAvatar = roomAvatar.value,
|
roomAvatar = roomAvatar.value,
|
||||||
|
userHasPermissionToSendMessage = userHasPermissionToSendMessage,
|
||||||
composerState = composerState,
|
composerState = composerState,
|
||||||
timelineState = timelineState,
|
timelineState = timelineState,
|
||||||
actionListState = actionListState,
|
actionListState = actionListState,
|
||||||
|
|
@ -218,4 +222,13 @@ class MessagesPresenter @Inject constructor(
|
||||||
MessageComposerEvents.SetMode(composerMode)
|
MessageComposerEvents.SetMode(composerMode)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun getCanSendEvent(type: MessageEventType): State<Boolean> {
|
||||||
|
val canSendEvent = remember(type) { mutableStateOf(false) }
|
||||||
|
LaunchedEffect(type) {
|
||||||
|
canSendEvent.value = room.canSendEvent(type).getOrElse { false }
|
||||||
|
}
|
||||||
|
return canSendEvent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ data class MessagesState(
|
||||||
val roomId: RoomId,
|
val roomId: RoomId,
|
||||||
val roomName: String?,
|
val roomName: String?,
|
||||||
val roomAvatar: AvatarData?,
|
val roomAvatar: AvatarData?,
|
||||||
|
val userHasPermissionToSendMessage: Boolean,
|
||||||
val composerState: MessageComposerState,
|
val composerState: MessageComposerState,
|
||||||
val timelineState: TimelineState,
|
val timelineState: TimelineState,
|
||||||
val actionListState: ActionListState,
|
val actionListState: ActionListState,
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ open class MessagesStateProvider : PreviewParameterProvider<MessagesState> {
|
||||||
aMessagesState(),
|
aMessagesState(),
|
||||||
aMessagesState().copy(hasNetworkConnection = false),
|
aMessagesState().copy(hasNetworkConnection = false),
|
||||||
aMessagesState().copy(composerState = aMessageComposerState().copy(showAttachmentSourcePicker = true)),
|
aMessagesState().copy(composerState = aMessageComposerState().copy(showAttachmentSourcePicker = true)),
|
||||||
|
aMessagesState().copy(userHasPermissionToSendMessage = false),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,6 +43,7 @@ fun aMessagesState() = MessagesState(
|
||||||
roomId = RoomId("!id:domain"),
|
roomId = RoomId("!id:domain"),
|
||||||
roomName = "Room name",
|
roomName = "Room name",
|
||||||
roomAvatar = AvatarData("!id:domain", "Room name"),
|
roomAvatar = AvatarData("!id:domain", "Room name"),
|
||||||
|
userHasPermissionToSendMessage = true,
|
||||||
composerState = aMessageComposerState().copy(
|
composerState = aMessageComposerState().copy(
|
||||||
text = StableCharSequence("Hello"),
|
text = StableCharSequence("Hello"),
|
||||||
isFullScreen = false,
|
isFullScreen = false,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
package io.element.android.features.messages.impl
|
package io.element.android.features.messages.impl
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
|
@ -34,6 +36,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
import androidx.compose.material.icons.filled.ArrowBack
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.SnackbarHost
|
import androidx.compose.material3.SnackbarHost
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
|
@ -41,7 +44,9 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalView
|
import androidx.compose.ui.platform.LocalView
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
|
|
@ -231,12 +236,16 @@ fun MessagesViewContent(
|
||||||
onTimestampClicked = onTimestampClicked,
|
onTimestampClicked = onTimestampClicked,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
MessageComposerView(
|
if (state.userHasPermissionToSendMessage) {
|
||||||
state = state.composerState,
|
MessageComposerView(
|
||||||
modifier = Modifier
|
state = state.composerState,
|
||||||
.fillMaxWidth()
|
modifier = Modifier
|
||||||
.wrapContentHeight(Alignment.Bottom)
|
.fillMaxWidth()
|
||||||
)
|
.wrapContentHeight(Alignment.Bottom)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
CantSendMessageBanner()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,6 +290,28 @@ fun MessagesViewTopBar(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CantSendMessageBanner(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(MaterialTheme.colorScheme.secondary)
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.screen_room_no_permission_to_post),
|
||||||
|
color = MaterialTheme.colorScheme.onSecondary,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
fontStyle = FontStyle.Italic,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
internal fun MessagesViewLightPreview(@PreviewParameter(MessagesStateProvider::class) state: MessagesState) =
|
internal fun MessagesViewLightPreview(@PreviewParameter(MessagesStateProvider::class) state: MessagesState) =
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,11 @@
|
||||||
<string name="screen_room_attachment_source_files">"Attachment"</string>
|
<string name="screen_room_attachment_source_files">"Attachment"</string>
|
||||||
<string name="screen_room_attachment_source_gallery">"Photo & Video Library"</string>
|
<string name="screen_room_attachment_source_gallery">"Photo & Video Library"</string>
|
||||||
<string name="screen_room_error_failed_retrieving_user_details">"Could not retrieve user details"</string>
|
<string name="screen_room_error_failed_retrieving_user_details">"Could not retrieve user details"</string>
|
||||||
|
<string name="screen_room_invite_again_alert_message">"Would you like to invite them back?"</string>
|
||||||
|
<string name="screen_room_invite_again_alert_title">"You are alone in this chat"</string>
|
||||||
|
<string name="screen_room_no_permission_to_post">"You do not have permission to post to this room"</string>
|
||||||
<string name="screen_room_retry_send_menu_send_again_action">"Send again"</string>
|
<string name="screen_room_retry_send_menu_send_again_action">"Send again"</string>
|
||||||
<string name="screen_room_retry_send_menu_title">"Your message failed to send"</string>
|
<string name="screen_room_retry_send_menu_title">"Your message failed to send"</string>
|
||||||
<string name="screen_room_error_failed_processing_media">"Failed processing media to upload, please try again."</string>
|
<string name="screen_room_error_failed_processing_media">"Failed processing media to upload, please try again."</string>
|
||||||
<string name="screen_room_retry_send_menu_remove_action">"Remove"</string>
|
<string name="screen_room_retry_send_menu_remove_action">"Remove"</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
|
||||||
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
||||||
import io.element.android.libraries.matrix.api.media.MediaSource
|
import io.element.android.libraries.matrix.api.media.MediaSource
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
|
import io.element.android.libraries.matrix.api.room.MessageEventType
|
||||||
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
|
import io.element.android.libraries.matrix.test.AN_AVATAR_URL
|
||||||
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
import io.element.android.libraries.matrix.test.AN_EVENT_ID
|
||||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
|
|
@ -166,7 +167,7 @@ class MessagesPresenterTest {
|
||||||
content = TimelineItemImageContent(
|
content = TimelineItemImageContent(
|
||||||
body = "image.jpg",
|
body = "image.jpg",
|
||||||
mediaSource = MediaSource(AN_AVATAR_URL),
|
mediaSource = MediaSource(AN_AVATAR_URL),
|
||||||
thumbnailSource = null,
|
thumbnailSource = null,
|
||||||
mimeType = MimeTypes.Jpeg,
|
mimeType = MimeTypes.Jpeg,
|
||||||
blurhash = null,
|
blurhash = null,
|
||||||
width = 20,
|
width = 20,
|
||||||
|
|
@ -318,6 +319,32 @@ class MessagesPresenterTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - permission to post`() = runTest {
|
||||||
|
val matrixRoom = FakeMatrixRoom()
|
||||||
|
matrixRoom.givenCanSendEventResult(MessageEventType.ROOM_MESSAGE, Result.success(true))
|
||||||
|
val presenter = createMessagePresenter(matrixRoom = matrixRoom)
|
||||||
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
|
presenter.present()
|
||||||
|
}.test {
|
||||||
|
skipItems(1)
|
||||||
|
assertThat(awaitItem().userHasPermissionToSendMessage).isTrue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - no permission to post`() = runTest {
|
||||||
|
val matrixRoom = FakeMatrixRoom()
|
||||||
|
matrixRoom.givenCanSendEventResult(MessageEventType.ROOM_MESSAGE, Result.success(false))
|
||||||
|
val presenter = createMessagePresenter(matrixRoom = matrixRoom)
|
||||||
|
moleculeFlow(RecompositionClock.Immediate) {
|
||||||
|
presenter.present()
|
||||||
|
}.test {
|
||||||
|
skipItems(1)
|
||||||
|
assertThat(awaitItem().userHasPermissionToSendMessage).isFalse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun TestScope.createMessagePresenter(
|
private fun TestScope.createMessagePresenter(
|
||||||
coroutineDispatchers: CoroutineDispatchers = testCoroutineDispatchers(),
|
coroutineDispatchers: CoroutineDispatchers = testCoroutineDispatchers(),
|
||||||
matrixRoom: MatrixRoom = FakeMatrixRoom()
|
matrixRoom: MatrixRoom = FakeMatrixRoom()
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,8 @@ interface MatrixRoom : Closeable {
|
||||||
|
|
||||||
suspend fun canSendStateEvent(type: StateEventType): Result<Boolean>
|
suspend fun canSendStateEvent(type: StateEventType): Result<Boolean>
|
||||||
|
|
||||||
|
suspend fun canSendEvent(type: MessageEventType): Result<Boolean>
|
||||||
|
|
||||||
suspend fun updateAvatar(mimeType: String, data: ByteArray): Result<Unit>
|
suspend fun updateAvatar(mimeType: String, data: ByteArray): Result<Unit>
|
||||||
|
|
||||||
suspend fun removeAvatar(): Result<Unit>
|
suspend fun removeAvatar(): Result<Unit>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* 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.room
|
||||||
|
|
||||||
|
enum class MessageEventType {
|
||||||
|
CALL_ANSWER,
|
||||||
|
CALL_INVITE,
|
||||||
|
CALL_HANGUP,
|
||||||
|
CALL_CANDIDATES,
|
||||||
|
KEY_VERIFICATION_READY,
|
||||||
|
KEY_VERIFICATION_START,
|
||||||
|
KEY_VERIFICATION_CANCEL,
|
||||||
|
KEY_VERIFICATION_ACCEPT,
|
||||||
|
KEY_VERIFICATION_KEY,
|
||||||
|
KEY_VERIFICATION_MAC,
|
||||||
|
KEY_VERIFICATION_DONE,
|
||||||
|
REACTION_SENT,
|
||||||
|
ROOM_ENCRYPTED,
|
||||||
|
ROOM_MESSAGE,
|
||||||
|
ROOM_REDACTION,
|
||||||
|
STICKER
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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.impl.room
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.room.MessageEventType
|
||||||
|
import org.matrix.rustcomponents.sdk.MessageLikeEventType
|
||||||
|
|
||||||
|
fun MessageEventType.map(): MessageLikeEventType = when (this) {
|
||||||
|
MessageEventType.CALL_ANSWER -> MessageLikeEventType.CALL_ANSWER
|
||||||
|
MessageEventType.CALL_INVITE -> MessageLikeEventType.CALL_INVITE
|
||||||
|
MessageEventType.CALL_HANGUP -> MessageLikeEventType.CALL_HANGUP
|
||||||
|
MessageEventType.CALL_CANDIDATES -> MessageLikeEventType.CALL_CANDIDATES
|
||||||
|
MessageEventType.KEY_VERIFICATION_READY -> MessageLikeEventType.KEY_VERIFICATION_READY
|
||||||
|
MessageEventType.KEY_VERIFICATION_START -> MessageLikeEventType.KEY_VERIFICATION_START
|
||||||
|
MessageEventType.KEY_VERIFICATION_CANCEL -> MessageLikeEventType.KEY_VERIFICATION_CANCEL
|
||||||
|
MessageEventType.KEY_VERIFICATION_ACCEPT -> MessageLikeEventType.KEY_VERIFICATION_ACCEPT
|
||||||
|
MessageEventType.KEY_VERIFICATION_KEY -> MessageLikeEventType.KEY_VERIFICATION_KEY
|
||||||
|
MessageEventType.KEY_VERIFICATION_MAC -> MessageLikeEventType.KEY_VERIFICATION_MAC
|
||||||
|
MessageEventType.KEY_VERIFICATION_DONE -> MessageLikeEventType.KEY_VERIFICATION_DONE
|
||||||
|
MessageEventType.REACTION_SENT -> MessageLikeEventType.REACTION_SENT
|
||||||
|
MessageEventType.ROOM_ENCRYPTED -> MessageLikeEventType.ROOM_ENCRYPTED
|
||||||
|
MessageEventType.ROOM_MESSAGE -> MessageLikeEventType.ROOM_MESSAGE
|
||||||
|
MessageEventType.ROOM_REDACTION -> MessageLikeEventType.ROOM_REDACTION
|
||||||
|
MessageEventType.STICKER -> MessageLikeEventType.STICKER
|
||||||
|
}
|
||||||
|
|
||||||
|
fun MessageLikeEventType.map(): MessageEventType = when (this) {
|
||||||
|
MessageLikeEventType.CALL_ANSWER -> MessageEventType.CALL_ANSWER
|
||||||
|
MessageLikeEventType.CALL_INVITE -> MessageEventType.CALL_INVITE
|
||||||
|
MessageLikeEventType.CALL_HANGUP -> MessageEventType.CALL_HANGUP
|
||||||
|
MessageLikeEventType.CALL_CANDIDATES -> MessageEventType.CALL_CANDIDATES
|
||||||
|
MessageLikeEventType.KEY_VERIFICATION_READY -> MessageEventType.KEY_VERIFICATION_READY
|
||||||
|
MessageLikeEventType.KEY_VERIFICATION_START -> MessageEventType.KEY_VERIFICATION_START
|
||||||
|
MessageLikeEventType.KEY_VERIFICATION_CANCEL -> MessageEventType.KEY_VERIFICATION_CANCEL
|
||||||
|
MessageLikeEventType.KEY_VERIFICATION_ACCEPT -> MessageEventType.KEY_VERIFICATION_ACCEPT
|
||||||
|
MessageLikeEventType.KEY_VERIFICATION_KEY -> MessageEventType.KEY_VERIFICATION_KEY
|
||||||
|
MessageLikeEventType.KEY_VERIFICATION_MAC -> MessageEventType.KEY_VERIFICATION_MAC
|
||||||
|
MessageLikeEventType.KEY_VERIFICATION_DONE -> MessageEventType.KEY_VERIFICATION_DONE
|
||||||
|
MessageLikeEventType.REACTION_SENT -> MessageEventType.REACTION_SENT
|
||||||
|
MessageLikeEventType.ROOM_ENCRYPTED -> MessageEventType.ROOM_ENCRYPTED
|
||||||
|
MessageLikeEventType.ROOM_MESSAGE -> MessageEventType.ROOM_MESSAGE
|
||||||
|
MessageLikeEventType.ROOM_REDACTION -> MessageEventType.ROOM_REDACTION
|
||||||
|
MessageLikeEventType.STICKER -> MessageEventType.STICKER
|
||||||
|
}
|
||||||
|
|
@ -27,6 +27,7 @@ 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.media.VideoInfo
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
|
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
|
||||||
|
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.StateEventType
|
||||||
import io.element.android.libraries.matrix.api.room.roomMembers
|
import io.element.android.libraries.matrix.api.room.roomMembers
|
||||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
|
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
|
||||||
|
|
@ -34,7 +35,6 @@ import io.element.android.libraries.matrix.impl.media.map
|
||||||
import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
|
import io.element.android.libraries.matrix.impl.timeline.RustMatrixTimeline
|
||||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
@ -235,6 +235,12 @@ class RustMatrixRoom(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun canSendEvent(type: MessageEventType): Result<Boolean> = withContext(coroutineDispatchers.io) {
|
||||||
|
runCatching {
|
||||||
|
innerRoom.member(sessionId.value).use { it.canSendMessage(type.map()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun sendImage(file: File, thumbnailFile: File, imageInfo: ImageInfo): Result<Unit> = withContext(coroutineDispatchers.io) {
|
override suspend fun sendImage(file: File, thumbnailFile: File, imageInfo: ImageInfo): Result<Unit> = withContext(coroutineDispatchers.io) {
|
||||||
runCatching {
|
runCatching {
|
||||||
innerRoom.sendImage(file.path, thumbnailFile.path, imageInfo.map())
|
innerRoom.sendImage(file.path, thumbnailFile.path, imageInfo.map())
|
||||||
|
|
@ -272,7 +278,7 @@ class RustMatrixRoom(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun cancelSend(transactionId: String): Result<Unit> =
|
override suspend fun cancelSend(transactionId: String): Result<Unit> =
|
||||||
withContext(coroutineDispatchers.io) {
|
withContext(coroutineDispatchers.io) {
|
||||||
runCatching {
|
runCatching {
|
||||||
innerRoom.cancelSend(transactionId)
|
innerRoom.cancelSend(transactionId)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ 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.media.VideoInfo
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
|
import io.element.android.libraries.matrix.api.room.MatrixRoomMembersState
|
||||||
|
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.StateEventType
|
||||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
|
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
|
||||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
|
|
@ -64,6 +65,7 @@ class FakeMatrixRoom(
|
||||||
private var inviteUserResult = Result.success(Unit)
|
private var inviteUserResult = Result.success(Unit)
|
||||||
private var canInviteResult = Result.success(true)
|
private var canInviteResult = Result.success(true)
|
||||||
private val canSendStateResults = mutableMapOf<StateEventType, Result<Boolean>>()
|
private val canSendStateResults = mutableMapOf<StateEventType, Result<Boolean>>()
|
||||||
|
private val canSendEventResults = mutableMapOf<MessageEventType, Result<Boolean>>()
|
||||||
private var sendMediaResult = Result.success(Unit)
|
private var sendMediaResult = Result.success(Unit)
|
||||||
private var setNameResult = Result.success(Unit)
|
private var setNameResult = Result.success(Unit)
|
||||||
private var setTopicResult = Result.success(Unit)
|
private var setTopicResult = Result.success(Unit)
|
||||||
|
|
@ -198,6 +200,10 @@ class FakeMatrixRoom(
|
||||||
return canSendStateResults[type] ?: Result.failure(IllegalStateException("No fake answer"))
|
return canSendStateResults[type] ?: Result.failure(IllegalStateException("No fake answer"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun canSendEvent(type: MessageEventType): Result<Boolean> {
|
||||||
|
return canSendEventResults[type] ?: Result.failure(IllegalStateException("No fake answer"))
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun sendImage(file: File, thumbnailFile: File, imageInfo: ImageInfo): Result<Unit> = fakeSendMedia()
|
override suspend fun sendImage(file: File, thumbnailFile: File, imageInfo: ImageInfo): Result<Unit> = fakeSendMedia()
|
||||||
|
|
||||||
override suspend fun sendVideo(file: File, thumbnailFile: File, videoInfo: VideoInfo): Result<Unit> = fakeSendMedia()
|
override suspend fun sendVideo(file: File, thumbnailFile: File, videoInfo: VideoInfo): Result<Unit> = fakeSendMedia()
|
||||||
|
|
@ -274,6 +280,10 @@ class FakeMatrixRoom(
|
||||||
canSendStateResults[type] = result
|
canSendStateResults[type] = result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenCanSendEventResult(type: MessageEventType, result: Result<Boolean>) {
|
||||||
|
canSendEventResults[type] = result
|
||||||
|
}
|
||||||
|
|
||||||
fun givenIgnoreResult(result: Result<Unit>) {
|
fun givenIgnoreResult(result: Result<Unit>) {
|
||||||
ignoreResult = result
|
ignoreResult = result
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue