Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ class ChatActivity :
onForward = { forwardMessage(msg) },
onEdit = { messageInputViewModel.edit(msg) },
onCopy = { copyMessage(msg) },
onCopyMessageLink = { copyMessageLink(msg) },
onMarkAsUnread = { markAsUnread(msg) },
onRemind = { remindMeLater(msg) },
onPin = { pinMessage(msg) },
Expand Down Expand Up @@ -3512,6 +3513,27 @@ class ChatActivity :
clipboardManager.setPrimaryClip(clipData)
}

fun copyMessageLink(message: ChatMessage) {
val baseUrl = conversationUser?.baseUrl
if (baseUrl.isNullOrEmpty()) {
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
return
}

// Matches the web client link format: {baseUrl}/call/{token}#message_{messageId}
val messageLink = "$baseUrl/call/$roomToken#message_${message.jsonMessageId}"

val clipboardManager =
getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(
resources?.getString(R.string.nc_app_product_name),
messageLink
)
clipboardManager.setPrimaryClip(clipData)

Snackbar.make(binding.root, R.string.nc_common_copy_success, Snackbar.LENGTH_SHORT).show()
}

fun translateMessage(message: ChatMessage?) {
val bundle = Bundle()
bundle.putString(BundleKeys.KEY_TRANSLATE_MESSAGE, message?.getRichText())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ data class MessageActionsState(
val showForward: Boolean,
val showEdit: Boolean,
val showCopy: Boolean,
val showCopyMessageLink: Boolean,
val showMarkAsUnread: Boolean,
val showRemind: Boolean,
val showPin: Boolean,
Expand Down Expand Up @@ -242,6 +243,8 @@ internal fun buildMessageActionsState(
isOnline,
showEdit = isMessageEditable,
showCopy = !message.isDeleted,
showCopyMessageLink = !message.isDeleted &&
ChatMessage.MessageType.SYSTEM_MESSAGE != messageType,
showMarkAsUnread = hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.CHAT_READ_MARKER) &&
ChatMessage.MessageType.SYSTEM_MESSAGE != messageType &&
isOnline,
Expand Down Expand Up @@ -279,6 +282,7 @@ fun MessageActionsBottomSheet(
onForward: () -> Unit,
onEdit: () -> Unit,
onCopy: () -> Unit,
onCopyMessageLink: () -> Unit,
onMarkAsUnread: () -> Unit,
onRemind: () -> Unit,
onPin: () -> Unit,
Expand Down Expand Up @@ -306,6 +310,7 @@ fun MessageActionsBottomSheet(
onForward = onForward,
onEdit = onEdit,
onCopy = onCopy,
onCopyMessageLink = onCopyMessageLink,
onMarkAsUnread = onMarkAsUnread,
onRemind = onRemind,
onPin = onPin,
Expand All @@ -332,6 +337,7 @@ internal fun MessageActionsSheetContent(
onForward: () -> Unit,
onEdit: () -> Unit,
onCopy: () -> Unit,
onCopyMessageLink: () -> Unit,
onMarkAsUnread: () -> Unit,
onRemind: () -> Unit,
onPin: () -> Unit,
Expand Down Expand Up @@ -436,6 +442,16 @@ internal fun MessageActionsSheetContent(
}
)
}
if (actionsState.showCopyMessageLink) {
MessageActionItem(
iconRes = R.drawable.ic_link,
text = stringResource(R.string.nc_copy_message_link),
onClick = {
onCopyMessageLink()
onDismiss()
}
)
}
if (actionsState.showMarkAsUnread) {
MessageActionItem(
iconRes = R.drawable.ic_mark_chat_unread_24px,
Expand Down Expand Up @@ -808,6 +824,7 @@ private fun PreviewMessageActionsSheetContent() {
showForward = true,
showEdit = true,
showCopy = true,
showCopyMessageLink = true,
showMarkAsUnread = true,
showRemind = true,
showPin = true,
Expand All @@ -830,6 +847,7 @@ private fun PreviewMessageActionsSheetContent() {
onForward = {},
onEdit = {},
onCopy = {},
onCopyMessageLink = {},
onMarkAsUnread = {},
onRemind = {},
onPin = {},
Expand Down Expand Up @@ -864,6 +882,7 @@ private fun PreviewMessageActionsSheetPinned() {
showForward = false,
showEdit = false,
showCopy = true,
showCopyMessageLink = true,
showMarkAsUnread = false,
showRemind = false,
showPin = true,
Expand All @@ -882,6 +901,7 @@ private fun PreviewMessageActionsSheetPinned() {
onForward = {},
onEdit = {},
onCopy = {},
onCopyMessageLink = {},
onMarkAsUnread = {},
onRemind = {},
onPin = {},
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ How to translate with transifex:

<!-- Chat -->
<string name="nc_copy_message">Copy</string>
<string name="nc_copy_message_link">Copy message link</string>
<string name="nc_forward_message">Forward</string>
<string name="nc_reply">Reply</string>
<string name="nc_reply_privately">Reply privately</string>
Expand Down
Loading