Skip to content

Commit 323d8cf

Browse files
committed
fix (event action): allow to edit only if permission to send message
1 parent 7bde9bc commit 323d8cf

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class DefaultActionListPresenter @AssistedInject constructor(
169169
if (timelineItem.isRemote && timelineItem.content.canBeForwarded()) {
170170
add(TimelineItemAction.Forward)
171171
}
172-
if (timelineItem.isEditable) {
172+
if (timelineItem.isEditable && usersEventPermissions.canSendMessage) {
173173
if (timelineItem.content is TimelineItemEventContentWithAttachment) {
174174
// Caption
175175
if (timelineItem.content.caption == null) {

features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,51 @@ class ActionListPresenterTest {
525525
}
526526
}
527527

528+
@Test
529+
fun `present - compute for my message no permission `() = runTest {
530+
val presenter = createActionListPresenter(isDeveloperModeEnabled = true, isPinFeatureEnabled = true)
531+
moleculeFlow(RecompositionMode.Immediate) {
532+
presenter.present()
533+
}.test {
534+
val initialState = awaitItem()
535+
val messageEvent = aMessageEvent(
536+
isMine = true,
537+
content = TimelineItemTextContent(body = A_MESSAGE, htmlDocument = null, isEdited = false, formattedBody = A_MESSAGE)
538+
)
539+
initialState.eventSink.invoke(
540+
ActionListEvents.ComputeForMessage(
541+
event = messageEvent,
542+
userEventPermissions = aUserEventPermissions(
543+
canRedactOwn = false,
544+
canRedactOther = false,
545+
canSendMessage = false,
546+
canSendReaction = false,
547+
canPinUnpin = false,
548+
)
549+
)
550+
)
551+
// val loadingState = awaitItem()
552+
// assertThat(loadingState.target).isEqualTo(ActionListState.Target.Loading(messageEvent))
553+
val successState = awaitItem()
554+
assertThat(successState.target).isEqualTo(
555+
ActionListState.Target.Success(
556+
event = messageEvent,
557+
sentTimeFull = "0 Full true",
558+
displayEmojiReactions = false,
559+
verifiedUserSendFailure = VerifiedUserSendFailure.None,
560+
actions = persistentListOf(
561+
TimelineItemAction.Forward,
562+
TimelineItemAction.CopyLink,
563+
TimelineItemAction.CopyText,
564+
TimelineItemAction.ViewSource,
565+
)
566+
)
567+
)
568+
initialState.eventSink.invoke(ActionListEvents.Clear)
569+
assertThat(awaitItem().target).isEqualTo(ActionListState.Target.None)
570+
}
571+
}
572+
528573
@Test
529574
fun `present - compute for a media item`() = runTest {
530575
val presenter = createActionListPresenter(isDeveloperModeEnabled = true, isPinFeatureEnabled = true)

0 commit comments

Comments
 (0)