Merge pull request #2653 from element-hq/feature/bma/copyPermalink

Copy permalink
This commit is contained in:
Benoit Marty 2024-04-03 17:38:38 +02:00 committed by GitHub
commit 68ababa0be
28 changed files with 122 additions and 36 deletions

View file

@ -89,6 +89,7 @@ import io.element.android.libraries.matrix.ui.room.canRedactOtherAsState
import io.element.android.libraries.matrix.ui.room.canRedactOwnAsState
import io.element.android.libraries.matrix.ui.room.canSendMessageAsState
import io.element.android.libraries.textcomposer.model.MessageComposerMode
import io.element.android.libraries.ui.strings.CommonStrings
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -273,6 +274,7 @@ class MessagesPresenter @AssistedInject constructor(
) = launch {
when (action) {
TimelineItemAction.Copy -> handleCopyContents(targetEvent)
TimelineItemAction.CopyLink -> handleCopyLink(targetEvent)
TimelineItemAction.Redact -> handleActionRedact(targetEvent)
TimelineItemAction.Edit -> handleActionEdit(targetEvent, composerState, enableTextFormatting)
TimelineItemAction.Reply,
@ -435,6 +437,20 @@ class MessagesPresenter @AssistedInject constructor(
event.eventId?.let { timelineState.eventSink(TimelineEvents.PollEndClicked(it)) }
}
private suspend fun handleCopyLink(event: TimelineItem.Event) {
event.eventId ?: return
room.getPermalinkFor(event.eventId).fold(
onSuccess = { permalink ->
clipboardHelper.copyPlainText(permalink)
snackbarDispatcher.post(SnackbarMessage(CommonStrings.common_link_copied_to_clipboard))
},
onFailure = {
Timber.e(it, "Failed to get permalink for event ${event.eventId}")
snackbarDispatcher.post(SnackbarMessage(CommonStrings.common_error))
}
)
}
private suspend fun handleCopyContents(event: TimelineItem.Event) {
val content = when (event.content) {
is TimelineItemTextBasedContent -> event.content.body

View file

@ -96,6 +96,7 @@ class ActionListPresenter @Inject constructor(
is TimelineItemStateContent -> {
buildList {
add(TimelineItemAction.Copy)
add(TimelineItemAction.CopyLink)
if (isDeveloperModeEnabled) {
add(TimelineItemAction.ViewSource)
}
@ -119,6 +120,7 @@ class ActionListPresenter @Inject constructor(
if (timelineItem.content.canBeCopied()) {
add(TimelineItemAction.Copy)
}
add(TimelineItemAction.CopyLink)
if (isDeveloperModeEnabled) {
add(TimelineItemAction.ViewSource)
}
@ -136,6 +138,7 @@ class ActionListPresenter @Inject constructor(
add(TimelineItemAction.Reply)
add(TimelineItemAction.Forward)
}
add(TimelineItemAction.CopyLink)
if (isDeveloperModeEnabled) {
add(TimelineItemAction.ViewSource)
}
@ -176,6 +179,7 @@ class ActionListPresenter @Inject constructor(
if (timelineItem.content.canBeCopied()) {
add(TimelineItemAction.Copy)
}
add(TimelineItemAction.CopyLink)
if (isDeveloperModeEnabled) {
add(TimelineItemAction.ViewSource)
}

View file

@ -135,6 +135,7 @@ fun aTimelineItemActionList(): ImmutableList<TimelineItemAction> {
TimelineItemAction.Reply,
TimelineItemAction.Forward,
TimelineItemAction.Copy,
TimelineItemAction.CopyLink,
TimelineItemAction.Edit,
TimelineItemAction.Redact,
TimelineItemAction.ReportContent,
@ -146,6 +147,7 @@ fun aTimelineItemPollActionList(): ImmutableList<TimelineItemAction> {
TimelineItemAction.EndPoll,
TimelineItemAction.Reply,
TimelineItemAction.Copy,
TimelineItemAction.CopyLink,
TimelineItemAction.ViewSource,
TimelineItemAction.ReportContent,
TimelineItemAction.Redact,

View file

@ -31,6 +31,7 @@ sealed class TimelineItemAction(
) {
data object Forward : TimelineItemAction(CommonStrings.action_forward, CompoundDrawables.ic_compound_forward)
data object Copy : TimelineItemAction(CommonStrings.action_copy, CompoundDrawables.ic_compound_copy)
data object CopyLink : TimelineItemAction(CommonStrings.action_copy_link_to_message, CompoundDrawables.ic_compound_link)
data object Redact : TimelineItemAction(CommonStrings.action_remove, CompoundDrawables.ic_compound_delete, destructive = true)
data object Reply : TimelineItemAction(CommonStrings.action_reply, CompoundDrawables.ic_compound_reply)
data object ReplyInThread : TimelineItemAction(CommonStrings.action_reply_in_thread, CompoundDrawables.ic_compound_reply)