Skip to content

Commit

Permalink
feature: copy channel link menu action (#12482)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Oct 24, 2023
1 parent 3050e97 commit b9867c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 11 additions & 1 deletion ui/imports/shared/views/chat/ChatContextMenuView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 22 additions & 1 deletion ui/imports/utils/Utils.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b9867c2

Please sign in to comment.