From 48bd693679d8e85b80b118948147421f7eafd78a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 11 Jul 2017 20:21:24 +0300 Subject: [PATCH] Allow to copy message links in public supergroups. --- .../history/history_inner_widget.cpp | 4 ++-- Telegram/SourceFiles/history/history_item.cpp | 24 +++++++++++++++---- Telegram/SourceFiles/history/history_item.h | 4 +--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index ba3ef666c..a3f823e56 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1221,7 +1221,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } } if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) { - _menu->addAction(lang(lng_context_copy_post_link), _widget, SLOT(onCopyPostLink())); + _menu->addAction(lang(item->history()->peer->isMegagroup() ? lng_context_copy_link : lng_context_copy_post_link), _widget, SLOT(onCopyPostLink())); } if (isUponSelected > 1) { if (selectedState.count > 0 && selectedState.canForwardCount == selectedState.count) { @@ -1329,7 +1329,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(linkCopyToClipboardText, this, SLOT(copyContextUrl()))->setEnabled(true); } if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) { - _menu->addAction(lang(lng_context_copy_post_link), _widget, SLOT(onCopyPostLink())); + _menu->addAction(lang(item->history()->peer->isMegagroup() ? lng_context_copy_link : lng_context_copy_post_link), _widget, SLOT(onCopyPostLink())); } if (isUponSelected > 1) { if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) { diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index fe5170a45..c9a427b9c 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -929,13 +929,27 @@ bool HistoryItem::suggestDeleteAllReport() const { return !isPost() && !out() && from()->isUser() && toHistoryMessage(); } +bool HistoryItem::hasDirectLink() const { + if (id <= 0) { + return false; + } + if (auto channel = _history->peer->asChannel()) { + return channel->isPublic(); + } + return false; +} + QString HistoryItem::directLink() const { if (hasDirectLink()) { - auto query = _history->peer->asChannel()->username + '/' + QString::number(id); - if (auto media = getMedia()) { - if (auto document = media->getDocument()) { - if (document->isRoundVideo()) { - return qsl("https://telesco.pe/") + query; + auto channel = _history->peer->asChannel(); + t_assert(channel != nullptr); + auto query = channel->username + '/' + QString::number(id); + if (!channel->isMegagroup()) { + if (auto media = getMedia()) { + if (auto document = media->getDocument()) { + if (document->isRoundVideo()) { + return qsl("https://telesco.pe/") + query; + } } } } diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 7f3c06908..2da40803a 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -717,9 +717,7 @@ public: bool suggestBanReport() const; bool suggestDeleteAllReport() const; - bool hasDirectLink() const { - return id > 0 && _history->peer->isChannel() && _history->peer->asChannel()->isPublic() && !_history->peer->isMegagroup(); - } + bool hasDirectLink() const; QString directLink() const; int y() const {