mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Allow ctrl/cmd+click copy private post link.
This commit is contained in:
parent
f77fdc799d
commit
52953626a7
4 changed files with 33 additions and 9 deletions
|
@ -2101,6 +2101,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
"lng_channel_public_link_copied" = "Link copied to clipboard.";
|
||||
"lng_context_about_private_link" = "This link will only work for members of this chat.";
|
||||
"lng_public_post_private_hint_ctrl" = "Use Ctrl+Click to copy a non-public link.";
|
||||
"lng_public_post_private_hint_cmd" = "Use Cmd+Click to copy a non-public link.";
|
||||
|
||||
"lng_forwarded" = "Forwarded from {user}";
|
||||
"lng_forwarded_story" = "Story from {user}";
|
||||
|
|
|
@ -708,7 +708,8 @@ void ApiWrap::finalizeMessageDataRequest(
|
|||
|
||||
QString ApiWrap::exportDirectMessageLink(
|
||||
not_null<HistoryItem*> item,
|
||||
bool inRepliesContext) {
|
||||
bool inRepliesContext,
|
||||
bool forceNonPublicLink) {
|
||||
Expects(item->history()->peer->isChannel());
|
||||
|
||||
const auto itemId = item->fullId();
|
||||
|
@ -731,7 +732,7 @@ QString ApiWrap::exportDirectMessageLink(
|
|||
const auto sender = root
|
||||
? root->discussionPostOriginalSender()
|
||||
: nullptr;
|
||||
if (sender && sender->hasUsername()) {
|
||||
if (sender && sender->hasUsername() && !forceNonPublicLink) {
|
||||
// Comment to a public channel.
|
||||
const auto forwarded = root->Get<HistoryMessageForwarded>();
|
||||
linkItemId = forwarded->savedFromMsgId;
|
||||
|
@ -747,7 +748,7 @@ QString ApiWrap::exportDirectMessageLink(
|
|||
}
|
||||
}
|
||||
}
|
||||
const auto base = linkChannel->hasUsername()
|
||||
const auto base = (linkChannel->hasUsername() && !forceNonPublicLink)
|
||||
? linkChannel->username()
|
||||
: "c/" + QString::number(peerToChannel(linkChannel->id).bare);
|
||||
const auto post = QString::number(linkItemId.bare);
|
||||
|
@ -761,6 +762,7 @@ QString ApiWrap::exportDirectMessageLink(
|
|||
? (QString::number(linkThreadId.bare) + '/' + post)
|
||||
: post);
|
||||
if (linkChannel->hasUsername()
|
||||
&& !forceNonPublicLink
|
||||
&& !linkChannel->isMegagroup()
|
||||
&& !linkCommentId
|
||||
&& !linkThreadId) {
|
||||
|
@ -774,6 +776,9 @@ QString ApiWrap::exportDirectMessageLink(
|
|||
}
|
||||
return session().createInternalLinkFull(query);
|
||||
};
|
||||
if (forceNonPublicLink) {
|
||||
return fallback();
|
||||
}
|
||||
const auto i = _unlikelyMessageLinks.find(itemId);
|
||||
const auto current = (i != end(_unlikelyMessageLinks))
|
||||
? i->second
|
||||
|
|
|
@ -164,7 +164,8 @@ public:
|
|||
void requestMessageData(PeerData *peer, MsgId msgId, Fn<void()> done);
|
||||
QString exportDirectMessageLink(
|
||||
not_null<HistoryItem*> item,
|
||||
bool inRepliesContext);
|
||||
bool inRepliesContext,
|
||||
bool forceNonPublicLink = false);
|
||||
QString exportDirectStoryLink(not_null<Data::Story*> item);
|
||||
|
||||
void requestContacts();
|
||||
|
|
|
@ -98,6 +98,7 @@ namespace {
|
|||
|
||||
constexpr auto kRescheduleLimit = 20;
|
||||
constexpr auto kTagNameLimit = 12;
|
||||
constexpr auto kPublicPostLinkToastDuration = 4 * crl::time(1000);
|
||||
|
||||
bool HasEditMessageAction(
|
||||
const ContextMenuRequest &request,
|
||||
|
@ -1307,12 +1308,17 @@ void CopyPostLink(
|
|||
return;
|
||||
}
|
||||
const auto inRepliesContext = (context == Context::Replies);
|
||||
const auto forceNonPublicLink = base::IsCtrlPressed();
|
||||
QGuiApplication::clipboard()->setText(
|
||||
item->history()->session().api().exportDirectMessageLink(
|
||||
item,
|
||||
inRepliesContext));
|
||||
inRepliesContext,
|
||||
forceNonPublicLink));
|
||||
|
||||
const auto isPublicLink = [&] {
|
||||
if (forceNonPublicLink) {
|
||||
return false;
|
||||
}
|
||||
const auto channel = item->history()->peer->asChannel();
|
||||
Assert(channel != nullptr);
|
||||
if (const auto rootId = item->replyToTop()) {
|
||||
|
@ -1328,10 +1334,20 @@ void CopyPostLink(
|
|||
}
|
||||
return channel->hasUsername();
|
||||
}();
|
||||
|
||||
show->showToast(isPublicLink
|
||||
? tr::lng_channel_public_link_copied(tr::now)
|
||||
: tr::lng_context_about_private_link(tr::now));
|
||||
if (isPublicLink) {
|
||||
show->showToast({
|
||||
.text = tr::lng_channel_public_link_copied(
|
||||
tr::now, Ui::Text::Bold
|
||||
).append('\n').append(Platform::IsMac()
|
||||
? tr::lng_public_post_private_hint_cmd(tr::now)
|
||||
: tr::lng_public_post_private_hint_ctrl(tr::now)),
|
||||
.duration = kPublicPostLinkToastDuration,
|
||||
});
|
||||
} else {
|
||||
show->showToast(isPublicLink
|
||||
? tr::lng_channel_public_link_copied(tr::now)
|
||||
: tr::lng_context_about_private_link(tr::now));
|
||||
}
|
||||
}
|
||||
|
||||
void CopyStoryLink(
|
||||
|
|
Loading…
Add table
Reference in a new issue