Pinned event: add action on timeline

This commit is contained in:
ganfra
2024-07-26 18:20:17 +02:00
parent 3adc6d0be8
commit 233a1ff09e
8 changed files with 26 additions and 3 deletions

View File

@@ -245,6 +245,7 @@ class MessagesPresenter @AssistedInject constructor(
canRedactOwn = userHasPermissionToRedactOwn,
canRedactOther = userHasPermissionToRedactOther,
canSendReaction = userHasPermissionToSendReaction,
canPin = false,
)
}
}
@@ -283,6 +284,7 @@ class MessagesPresenter @AssistedInject constructor(
TimelineItemAction.Forward -> handleForwardAction(targetEvent)
TimelineItemAction.ReportContent -> handleReportAction(targetEvent)
TimelineItemAction.EndPoll -> handleEndPollAction(targetEvent, timelineState)
TimelineItemAction.Pin -> Timber.d("Pin action not implemented")
}
}

View File

@@ -144,11 +144,13 @@ fun aUserEventPermissions(
canRedactOther: Boolean = false,
canSendMessage: Boolean = true,
canSendReaction: Boolean = true,
canPin: Boolean = false,
) = UserEventPermissions(
canRedactOwn = canRedactOwn,
canRedactOther = canRedactOther,
canSendMessage = canSendMessage,
canSendReaction = canSendReaction,
canPin = canPin,
)
fun aReactionSummaryState(

View File

@@ -25,4 +25,5 @@ data class UserEventPermissions(
val canRedactOther: Boolean,
val canSendMessage: Boolean,
val canSendReaction: Boolean,
val canPin: Boolean,
)

View File

@@ -36,6 +36,8 @@ import io.element.android.features.messages.impl.timeline.model.event.canBeCopie
import io.element.android.features.messages.impl.timeline.model.event.canBeForwarded
import io.element.android.features.messages.impl.timeline.model.event.canReact
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.featureflag.api.FeatureFlags
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
@@ -44,6 +46,7 @@ import javax.inject.Inject
class ActionListPresenter @Inject constructor(
private val appPreferencesStore: AppPreferencesStore,
private val featureFlagsService: FeatureFlagService,
) : Presenter<ActionListState> {
@Composable
override fun present(): ActionListState {
@@ -54,6 +57,7 @@ class ActionListPresenter @Inject constructor(
}
val isDeveloperModeEnabled by appPreferencesStore.isDeveloperModeEnabledFlow().collectAsState(initial = false)
val isPinnedEventsEnabled by featureFlagsService.isFeatureEnabledFlow(FeatureFlags.PinnedEvents).collectAsState(initial = false)
fun handleEvents(event: ActionListEvents) {
when (event) {
@@ -62,6 +66,7 @@ class ActionListPresenter @Inject constructor(
timelineItem = event.event,
usersEventPermissions = event.userEventPermissions,
isDeveloperModeEnabled = isDeveloperModeEnabled,
isPinnedEventsEnabled = isPinnedEventsEnabled,
target = target,
)
}
@@ -77,6 +82,7 @@ class ActionListPresenter @Inject constructor(
timelineItem: TimelineItem.Event,
usersEventPermissions: UserEventPermissions,
isDeveloperModeEnabled: Boolean,
isPinnedEventsEnabled: Boolean,
target: MutableState<ActionListState.Target>
) = launch {
target.value = ActionListState.Target.Loading(timelineItem)
@@ -85,6 +91,7 @@ class ActionListPresenter @Inject constructor(
timelineItem = timelineItem,
usersEventPermissions = usersEventPermissions,
isDeveloperModeEnabled = isDeveloperModeEnabled,
isPinnedEventsEnabled = isPinnedEventsEnabled,
)
val displayEmojiReactions = usersEventPermissions.canSendReaction &&
timelineItem.isRemote &&
@@ -105,6 +112,7 @@ private fun buildActions(
timelineItem: TimelineItem.Event,
usersEventPermissions: UserEventPermissions,
isDeveloperModeEnabled: Boolean,
isPinnedEventsEnabled: Boolean,
): List<TimelineItemAction> {
val canRedact = timelineItem.isMine && usersEventPermissions.canRedactOwn || !timelineItem.isMine && usersEventPermissions.canRedactOther
return buildList {
@@ -124,6 +132,11 @@ private fun buildActions(
if (canRedact && timelineItem.content is TimelineItemPollContent && !timelineItem.content.isEnded) {
add(TimelineItemAction.EndPoll)
}
// TODO: handle unpin
val canPin = isPinnedEventsEnabled && usersEventPermissions.canPin && timelineItem.isRemote
if (canPin) {
add(TimelineItemAction.Pin)
}
if (timelineItem.content.canBeCopied()) {
add(TimelineItemAction.Copy)
}

View File

@@ -39,4 +39,5 @@ sealed class TimelineItemAction(
data object ViewSource : TimelineItemAction(CommonStrings.action_view_source, CommonDrawables.ic_developer_options)
data object ReportContent : TimelineItemAction(CommonStrings.action_report_content, CompoundDrawables.ic_compound_chat_problem, destructive = true)
data object EndPoll : TimelineItemAction(CommonStrings.action_end_poll, CompoundDrawables.ic_compound_polls_end)
data object Pin : TimelineItemAction(CommonStrings.action_pin, CompoundDrawables.ic_compound_pin)
}

View File

@@ -958,7 +958,8 @@ class MessagesPresenterTest {
return timelinePresenter
}
}
val actionListPresenter = ActionListPresenter(appPreferencesStore = appPreferencesStore)
val featureFlagService = FakeFeatureFlagService()
val actionListPresenter = ActionListPresenter(appPreferencesStore = appPreferencesStore, featureFlagsService = featureFlagService)
val typingNotificationPresenter = TypingNotificationPresenter(
room = matrixRoom,
sessionPreferencesStore = sessionPreferencesStore,
@@ -981,7 +982,7 @@ class MessagesPresenterTest {
snackbarDispatcher = SnackbarDispatcher(),
navigator = navigator,
clipboardHelper = clipboardHelper,
featureFlagsService = FakeFeatureFlagService(),
featureFlagsService = featureFlagService,
buildMeta = aBuildMeta(),
dispatchers = coroutineDispatchers,
htmlConverterProvider = FakeHtmlConverterProvider(),

View File

@@ -169,6 +169,7 @@ class MessagesViewTest {
userHasPermissionToRedactOwn: Boolean = false,
userHasPermissionToRedactOther: Boolean = false,
userHasPermissionToSendReaction: Boolean = false,
userCanPinEvent: Boolean = false,
) {
val eventsRecorder = EventsRecorder<ActionListEvents>()
val state = aMessagesState(
@@ -180,6 +181,7 @@ class MessagesViewTest {
canRedactOwn = userHasPermissionToRedactOwn,
canRedactOther = userHasPermissionToRedactOther,
canSendReaction = userHasPermissionToSendReaction,
canPin = userCanPinEvent,
),
)
val timelineItem = state.timelineState.timelineItems.first() as TimelineItem.Event

View File

@@ -835,5 +835,6 @@ class ActionListPresenterTest {
private fun createActionListPresenter(isDeveloperModeEnabled: Boolean): ActionListPresenter {
val preferencesStore = InMemoryAppPreferencesStore(isDeveloperModeEnabled = isDeveloperModeEnabled)
return ActionListPresenter(appPreferencesStore = preferencesStore)
val featureFlagsService = FakeFeatureFlagService()
return ActionListPresenter(appPreferencesStore = preferencesStore, featureFlagsService = featureFlagsService)
}