From 92ff07f723226d8ee15c6c5aa6ee761f6e5bb89e Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 6 Jan 2025 21:07:14 +0400 Subject: [PATCH] Fix possible crash in message translation. --- .../SourceFiles/history/history_inner_widget.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 79534bbb9..8a3c5e2d6 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2773,7 +2773,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } } if (!item->isService() && view && actionText.isEmpty()) { - if (!hasCopyRestriction(item) + const auto hasRestriction = hasCopyRestriction(item); + if (!hasRestriction && (view->hasVisibleText() || mediaHasTextForCopy)) { _menu->addAction( tr::lng_context_copy_text(tr::now), @@ -2782,6 +2783,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } if ((!item->translation() || !_history->translatedTo()) && (view->hasVisibleText() || mediaHasTextForCopy)) { + const auto peer = item->history()->peer; + const auto itemId = item->id; const auto translate = mediaHasTextForCopy ? (HistoryView::TransribedText(item) .append('\n') @@ -2792,12 +2795,10 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(tr::lng_context_translate(tr::now), [=] { _controller->show(Box( Ui::TranslateBox, - item->history()->peer, - mediaHasTextForCopy - ? MsgId() - : item->fullId().msg, + peer, + mediaHasTextForCopy ? MsgId() : itemId, translate, - hasCopyRestriction(item))); + hasRestriction)); }, &st::menuIconTranslate); } }