Fixed display of toast about copying post link in corresponding window.

This commit is contained in:
23rd 2022-06-14 13:38:06 +03:00
parent 4de71408a2
commit 236b7bbf28
4 changed files with 13 additions and 10 deletions

View File

@ -1270,7 +1270,7 @@ void FastShareMessage(
}
if (item->hasDirectLink()) {
using namespace HistoryView;
CopyPostLink(session, item->fullId(), Context::History);
CopyPostLink(controller, item->fullId(), Context::History);
} else if (const auto bot = item->getMessageBot()) {
if (const auto media = item->media()) {
if (const auto game = media->game()) {

View File

@ -2208,7 +2208,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}
if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_message_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] {
HistoryView::CopyPostLink(session, itemId, HistoryView::Context::History);
HistoryView::CopyPostLink(controller, itemId, HistoryView::Context::History);
}, &st::menuIconLink);
}
if (isUponSelected > 1) {
@ -2354,7 +2354,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
&st::menuIconCopy);
} else if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_message_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] {
HistoryView::CopyPostLink(session, itemId, HistoryView::Context::History);
HistoryView::CopyPostLink(controller, itemId, HistoryView::Context::History);
}, &st::menuIconLink);
}
if (isUponSelected > 1) {

View File

@ -325,11 +325,12 @@ void AddPostLinkAction(
const auto context = request.view
? request.view->context()
: Context::History;
const auto controller = request.navigation->parentController();
menu->addAction(
(item->history()->peer->isMegagroup()
? tr::lng_context_copy_message_link
: tr::lng_context_copy_post_link)(tr::now),
[=] { CopyPostLink(session, itemId, context); },
[=] { CopyPostLink(controller, itemId, context); },
&st::menuIconLink);
}
@ -1007,10 +1008,10 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
}
void CopyPostLink(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
FullMsgId itemId,
Context context) {
const auto item = session->data().message(itemId);
const auto item = controller->session().data().message(itemId);
if (!item || !item->hasDirectLink()) {
return;
}
@ -1037,9 +1038,11 @@ void CopyPostLink(
return channel->hasUsername();
}();
Ui::Toast::Show(isPublicLink
? tr::lng_channel_public_link_copied(tr::now)
: tr::lng_context_about_private_link(tr::now));
Ui::Toast::Show(
Window::Show(controller).toastParent(),
isPublicLink
? tr::lng_channel_public_link_copied(tr::now)
: tr::lng_context_about_private_link(tr::now));
}
void AddPollActions(

View File

@ -51,7 +51,7 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
const ContextMenuRequest &request);
void CopyPostLink(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
FullMsgId itemId,
Context context);
void AddPollActions(