Create private channel post links.

This commit is contained in:
John Preston 2019-04-04 14:02:22 +04:00
parent 73470c3a95
commit 0744f43a0e
8 changed files with 33 additions and 35 deletions

View File

@ -1032,6 +1032,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_group_invite_no_room" = "Unable to join this group because there are too many members in it already.";
"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_forwarded" = "Forwarded from {user}";
"lng_forwarded_date" = "Original: {date}";

View File

@ -1167,7 +1167,7 @@ std::unique_ptr<QMimeData> HistoryInner::prepareDrag() {
//}
}
if (auto mimeData = MimeDataFromTextWithEntities(sel)) {
updateDragSelection(0, 0, false);
updateDragSelection(nullptr, nullptr, false);
_widget->noSelectingScroll();
if (!urls.isEmpty()) mimeData->setUrls(urls);
@ -1580,7 +1580,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}
if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(lang(item->history()->peer->isMegagroup() ? lng_context_copy_link : lng_context_copy_post_link), [=] {
_widget->copyPostLink(itemId);
HistoryView::CopyPostLink(itemId);
});
}
if (isUponSelected > 1) {
@ -1716,7 +1716,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
});
} else if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(lang(item->history()->peer->isMegagroup() ? lng_context_copy_link : lng_context_copy_post_link), [=] {
_widget->copyPostLink(itemId);
HistoryView::CopyPostLink(itemId);
});
}
if (isUponSelected > 1) {
@ -2256,7 +2256,7 @@ bool HistoryInner::focusNextPrevChild(bool next) {
void HistoryInner::adjustCurrent(int32 y) const {
int32 htop = historyTop(), hdrawtop = historyDrawTop(), mtop = migratedTop();
_curHistory = 0;
_curHistory = nullptr;
if (mtop >= 0) {
adjustCurrent(y - mtop, _migrated);
}
@ -2682,7 +2682,7 @@ void HistoryInner::mouseActionUpdate() {
if (_mouseAction == MouseAction::Selecting) {
_widget->checkSelectingScroll(mousePos);
} else {
updateDragSelection(0, 0, false);
updateDragSelection(nullptr, nullptr, false);
_widget->noSelectingScroll();
}

View File

@ -549,21 +549,19 @@ bool HistoryItem::suggestDeleteAllReport() const {
}
bool HistoryItem::hasDirectLink() const {
if (!IsServerMsgId(id)) {
return false;
}
if (auto channel = _history->peer->asChannel()) {
return channel->isPublic();
}
return false;
return IsServerMsgId(id) && _history->peer->isChannel();
}
QString HistoryItem::directLink() const {
if (hasDirectLink()) {
auto channel = _history->peer->asChannel();
const auto channel = _history->peer->asChannel();
Assert(channel != nullptr);
auto query = channel->username + '/' + QString::number(id);
if (!channel->isMegagroup()) {
const auto base = channel->isPublic()
? channel->username
: "c/" + QString::number(channel->bareId());
const auto query = base + '/' + QString::number(id);
if (channel->isPublic() && !channel->isMegagroup()) {
if (const auto media = this->media()) {
if (const auto document = media->document()) {
if (document->isVideoMessage()) {

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_location_manager.h"
#include "history/history_service.h"
#include "history/view/history_view_service_message.h"
#include "history/view/history_view_context_menu.h" // For CopyPostLink().
#include "auth_session.h"
#include "boxes/share_box.h"
#include "boxes/confirm_box.h"
@ -104,9 +105,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
auto copyCallback = [data]() {
if (auto item = App::histItemById(data->msgIds[0])) {
if (item->hasDirectLink()) {
QApplication::clipboard()->setText(item->directLink());
Ui::Toast::Show(lang(lng_channel_public_link_copied));
HistoryView::CopyPostLink(item->fullId());
} else if (const auto bot = item->getMessageBot()) {
if (const auto media = item->media()) {
if (const auto game = media->game()) {

View File

@ -5781,14 +5781,6 @@ void HistoryWidget::onPinnedHide() {
}
}
void HistoryWidget::copyPostLink(FullMsgId itemId) {
if (const auto item = App::histItemById(itemId)) {
if (item->hasDirectLink()) {
QApplication::clipboard()->setText(item->directLink());
}
}
}
bool HistoryWidget::lastForceReplyReplied(const FullMsgId &replyTo) const {
if (replyTo.channel != _channel) {
return false;

View File

@ -201,7 +201,6 @@ public:
void editMessage(not_null<HistoryItem*> item);
void pinMessage(FullMsgId itemId);
void unpinMessage(FullMsgId itemId);
void copyPostLink(FullMsgId itemId);
MsgId replyToId() const;
void messageDataReceived(ChannelData *channel, MsgId msgId);

View File

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/media/history_media_web_page.h"
#include "ui/widgets/popup_menu.h"
#include "ui/image/image.h"
#include "ui/toast/toast.h"
#include "chat_helpers/message_field.h"
#include "boxes/confirm_box.h"
#include "boxes/sticker_set_box.h"
@ -185,14 +186,6 @@ void AddDocumentActions(
AddSaveDocumentAction(menu, contextId, document);
}
void CopyPostLink(FullMsgId itemId) {
if (const auto item = App::histItemById(itemId)) {
if (item->hasDirectLink()) {
QApplication::clipboard()->setText(item->directLink());
}
}
}
void AddPostLinkAction(
not_null<Ui::PopupMenu*> menu,
const ContextMenuRequest &request) {
@ -512,6 +505,21 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
return result;
}
void CopyPostLink(FullMsgId itemId) {
if (const auto item = App::histItemById(itemId)) {
if (item->hasDirectLink()) {
QApplication::clipboard()->setText(item->directLink());
const auto channel = item->history()->peer->asChannel();
Assert(channel != nullptr);
Ui::Toast::Show(lang(channel->isPublic()
? lng_channel_public_link_copied
: lng_context_about_private_link));
}
}
}
void StopPoll(FullMsgId itemId) {
Ui::show(Box<ConfirmBox>(
lang(lng_polls_stop_warning),

View File

@ -35,6 +35,7 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
not_null<ListWidget*> list,
const ContextMenuRequest &request);
void CopyPostLink(FullMsgId itemId);
void StopPoll(FullMsgId itemId);
} // namespace