feature: copy channel link menu action (#12482)

This commit is contained in:
Igor Sirotin 2023-10-24 16:13:25 +01:00 committed by GitHub
parent 3050e97c9c
commit b9867c2463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -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 {

View File

@ -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) {