Fix a crash in forwarded sender avatars.

This commit is contained in:
John Preston 2024-06-03 22:59:14 +04:00
parent 9043c18725
commit 06d0e78b00
1 changed files with 9 additions and 4 deletions

View File

@ -196,14 +196,19 @@ void HistoryMessageForwarded::create(
? originalSender->name()
: originalHiddenSenderInfo->name)
};
if (originalSender) {
context.session = &originalSender->owner().session();
if (const auto copy = originalSender) {
context.session = &copy->owner().session();
context.customEmojiRepaint = [=] {
originalSender->owner().requestItemRepaint(item);
// It is important to capture here originalSender by value,
// not capture the HistoryMessageForwarded* and read the
// originalSender field, because the components themselves
// get moved from place to place and the captured `this`
// pointer may become invalid, resulting in a crash.
copy->owner().requestItemRepaint(item);
};
phrase = Ui::Text::SingleCustomEmoji(
context.session->data().customEmojiManager().peerUserpicEmojiData(
originalSender,
copy,
st::fwdTextUserpicPadding));
}
if (!originalPostAuthor.isEmpty()) {