From b9867c2463d61f9bd88cc33022aec5cbd4d08d1c Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Tue, 24 Oct 2023 16:13:25 +0100 Subject: [PATCH] feature: copy channel link menu action (#12482) --- .../shared/views/chat/ChatContextMenuView.qml | 12 +++++++++- ui/imports/utils/Utils.qml | 23 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ui/imports/shared/views/chat/ChatContextMenuView.qml b/ui/imports/shared/views/chat/ChatContextMenuView.qml index 782ef8a29b3..f5cf3c7d597 100644 --- a/ui/imports/shared/views/chat/ChatContextMenuView.qml +++ b/ui/imports/shared/views/chat/ChatContextMenuView.qml @@ -59,8 +59,18 @@ StatusMenu { onTriggered: { root.addRemoveGroupMember() } } + StatusAction { + text: qsTr("Copy channel link") + icon.name: "copy" + enabled: root.isCommunityChat + onTriggered: { + const link = Utils.getCommunityChannelShareLinkWithChatId(root.chatId) + Utils.copyToClipboard(link) + } + } + StatusMenuSeparator { - visible: root.chatType === Constants.chatType.oneToOne || root.chatType === Constants.chatType.privateGroupChat + visible: root.chatType === Constants.chatType.oneToOne || root.chatType === Constants.chatType.privateGroupChat || root.isCommunityChat } StatusAction { diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index bd0eb1cebf5..1bb2448aa8e 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -15,6 +15,7 @@ QtObject { property var communitiesModuleInst: typeof communitiesModule !== "undefined" ? communitiesModule : null readonly property int maxImgSizeBytes: Constants.maxUploadFilesizeMB * 1048576 /* 1 MB in bytes */ + readonly property int communityIdLength: 68 function isDigit(value) { return /^\d$/.test(value); @@ -33,13 +34,21 @@ QtObject { } function isCommunityPublicKey(value) { - return (startsWith0x(value) && isHex(value) && value.length === 68) || globalUtilsInst.isCompressedPubKey(value) + return (startsWith0x(value) && isHex(value) && value.length === communityIdLength) || globalUtilsInst.isCompressedPubKey(value) } function isCompressedPubKey(pubKey) { return globalUtilsInst.isCompressedPubKey(pubKey) } + function getCommunityIdFromFullChatId(fullChatId) { + return fullChatId.substr(0, communityIdLength) + } + + function getChannelUuidFromFullChatId(fullChatId) { + return fullChatId.substr(communityIdLength, fullChatId.length) + } + function isValidETHNamePrefix(value) { return !(value.trim() === "" || value.endsWith(".") || value.indexOf("..") > -1) } @@ -492,6 +501,18 @@ QtObject { return communitiesModuleInst.shareCommunityUrlWithData(communityId) } + function getCommunityChannelShareLink(communityId, channelId) { + if (communityId === "" || channelId === "") + return "" + return communitiesModuleInst.shareCommunityChannelUrlWithData(communityId, channelId) + } + + function getCommunityChannelShareLinkWithChatId(chatId) { + const communityId = getCommunityIdFromFullChatId(chatId) + const channelId = getChannelUuidFromFullChatId(chatId) + return getCommunityChannelShareLink(communityId, channelId) + } + function getChatKeyFromShareLink(link) { let index = link.lastIndexOf("/u/") if (index === -1) {