Fix possible crash in message translation.

This commit is contained in:
John Preston 2025-01-06 21:07:14 +04:00
parent a23dca080a
commit 92ff07f723

View file

@ -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);
}
}