Hide reaction is user do not have permission to send reaction #2093

This commit is contained in:
Benoit Marty 2023-12-26 14:57:47 +01:00
parent 29d23cbeee
commit 52c2e8ea08
7 changed files with 60 additions and 18 deletions

View file

@ -139,6 +139,7 @@ class MessagesPresenter @AssistedInject constructor(
val syncUpdateFlow = room.syncUpdateFlow.collectAsState()
val userHasPermissionToSendMessage by room.canSendMessageAsState(type = MessageEventType.ROOM_MESSAGE, updateKey = syncUpdateFlow.value)
val userHasPermissionToRedact by room.canRedactAsState(updateKey = syncUpdateFlow.value)
val userHasPermissionToSendReaction by room.canSendMessageAsState(type = MessageEventType.REACTION_SENT, updateKey = syncUpdateFlow.value)
val roomName: Async<String> by remember {
derivedStateOf { roomInfo?.name?.let { Async.Success(it) } ?: Async.Uninitialized }
}
@ -219,6 +220,7 @@ class MessagesPresenter @AssistedInject constructor(
roomAvatar = roomAvatar,
userHasPermissionToSendMessage = userHasPermissionToSendMessage,
userHasPermissionToRedact = userHasPermissionToRedact,
userHasPermissionToSendReaction = userHasPermissionToSendReaction,
composerState = composerState,
voiceMessageComposerState = voiceMessageComposerState,
timelineState = timelineState,

View file

@ -37,6 +37,7 @@ data class MessagesState(
val roomAvatar: Async<AvatarData>,
val userHasPermissionToSendMessage: Boolean,
val userHasPermissionToRedact: Boolean,
val userHasPermissionToSendReaction: Boolean,
val composerState: MessageComposerState,
val voiceMessageComposerState: VoiceMessageComposerState,
val timelineState: TimelineState,

View file

@ -87,6 +87,7 @@ fun aMessagesState() = MessagesState(
roomAvatar = Async.Success(AvatarData("!id:domain", "Room name", size = AvatarSize.TimelineRoom)),
userHasPermissionToSendMessage = true,
userHasPermissionToRedact = false,
userHasPermissionToSendReaction = true,
composerState = aMessageComposerState().copy(
richTextEditorState = RichTextEditorState("Hello", initialFocus = true),
isFullScreen = false,

View file

@ -159,6 +159,7 @@ fun MessagesView(
event = event,
canRedact = state.userHasPermissionToRedact,
canSendMessage = state.userHasPermissionToSendMessage,
canSendReaction = state.userHasPermissionToSendReaction,
)
)
}

View file

@ -24,5 +24,6 @@ sealed interface ActionListEvents {
val event: TimelineItem.Event,
val canRedact: Boolean,
val canSendMessage: Boolean,
val canSendReaction: Boolean,
) : ActionListEvents
}

View file

@ -59,6 +59,7 @@ class ActionListPresenter @Inject constructor(
timelineItem = event.event,
userCanRedact = event.canRedact,
userCanSendMessage = event.canSendMessage,
userCanSendReaction = event.canSendReaction,
isDeveloperModeEnabled = isDeveloperModeEnabled,
target = target,
)
@ -75,6 +76,7 @@ class ActionListPresenter @Inject constructor(
timelineItem: TimelineItem.Event,
userCanRedact: Boolean,
userCanSendMessage: Boolean,
userCanSendReaction: Boolean,
isDeveloperModeEnabled: Boolean,
target: MutableState<ActionListState.Target>
) = launch {
@ -169,7 +171,9 @@ class ActionListPresenter @Inject constructor(
}
}
}
val displayEmojiReactions = timelineItem.isRemote && timelineItem.content.canReact()
val displayEmojiReactions = userCanSendReaction &&
timelineItem.isRemote
&& timelineItem.content.canReact()
if (actions.isNotEmpty() || displayEmojiReactions) {
target.value = ActionListState.Target.Success(
event = timelineItem,