[poll-view] Added preview for media from poll option.

This commit is contained in:
23rd
2026-03-26 12:43:39 +03:00
parent fd634164ed
commit 589e486cb8
@@ -11,7 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/ui_integration.h" #include "core/ui_integration.h"
#include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_custom_emoji.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_document.h"
#include "data/data_peer.h" #include "data/data_peer.h"
#include "data/data_photo.h"
#include "data/data_poll.h" #include "data/data_poll.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_story.h" #include "data/data_story.h"
@@ -349,8 +351,10 @@ void Reply::update(
: nullptr; : nullptr;
const auto messagePoll = messageMedia const auto messagePoll = messageMedia
? messageMedia->poll() ? messageMedia->poll()
: message
? (message->media() ? message->media()->poll() : nullptr)
: nullptr; : nullptr;
const auto pollAnswer = messagePoll const auto pollAnswer = (messagePoll && !fields.pollOption.isEmpty())
? messagePoll->answerByOption(fields.pollOption) ? messagePoll->answerByOption(fields.pollOption)
: nullptr; : nullptr;
const auto story = data->resolvedStory.get(); const auto story = data->resolvedStory.get();
@@ -370,11 +374,18 @@ void Reply::update(
_hiddenSenderColorIndexPlusOne = (!_colorPeer && message) _hiddenSenderColorIndexPlusOne = (!_colorPeer && message)
? (message->originalHiddenSenderInfo()->colorIndex + 1) ? (message->originalHiddenSenderInfo()->colorIndex + 1)
: 0; : 0;
const auto pollMediaPtr = pollAnswer
? &pollAnswer->media
: (messagePoll && fields.pollOption.isEmpty())
? &messagePoll->attachedMedia
: nullptr;
const auto hasPreview = (story && story->hasReplyPreview()) const auto hasPreview = (story && story->hasReplyPreview())
|| (message || (message
&& message->media() && message->media()
&& message->media()->hasReplyPreview()) && message->media()->hasReplyPreview())
|| (externalMedia && externalMedia->hasReplyPreview()); || (externalMedia && externalMedia->hasReplyPreview())
|| (pollMediaPtr
&& (pollMediaPtr->photo || pollMediaPtr->document));
_hasPreview = hasPreview ? 1 : 0; _hasPreview = hasPreview ? 1 : 0;
_displaying = data->displaying() ? 1 : 0; _displaying = data->displaying() ? 1 : 0;
_multiline = data->multiline() ? 1 : 0; _multiline = data->multiline() ? 1 : 0;
@@ -890,15 +901,42 @@ void Reply::paint(
? data->resolvedMessage.get() ? data->resolvedMessage.get()
: nullptr; : nullptr;
const auto media = message ? message->media() : nullptr; const auto media = message ? message->media() : nullptr;
const auto image = media const auto messagePoll = media ? media->poll() : nullptr;
? media->replyPreview() const auto pollAnswer = messagePoll
: !data ? messagePoll->answerByOption(
? nullptr data->fields().pollOption)
: data->resolvedStory
? data->resolvedStory->replyPreview()
: data->fields().externalMedia
? data->fields().externalMedia->replyPreview()
: nullptr; : nullptr;
const auto pollMediaPtr = pollAnswer
? &pollAnswer->media
: (messagePoll
&& data->fields().pollOption.isEmpty())
? &messagePoll->attachedMedia
: nullptr;
const auto image = [&]() -> Image* {
if (pollMediaPtr) {
if (pollMediaPtr->photo) {
return pollMediaPtr->photo->getReplyPreview(
message);
} else if (pollMediaPtr->document) {
return pollMediaPtr->document->getReplyPreview(
message);
}
}
if (media) {
return media->replyPreview();
}
if (!data) {
return nullptr;
}
if (data->resolvedStory) {
return data->resolvedStory->replyPreview();
}
if (data->fields().externalMedia) {
return data->fields().externalMedia
->replyPreview();
}
return nullptr;
}();
if (image) { if (image) {
auto to = style::rtlrect( auto to = style::rtlrect(
x + st::historyReplyPreviewMargin.left(), x + st::historyReplyPreviewMargin.left(),