Fixed blinking of message preview from user's personal channel.

This commit is contained in:
23rd 2025-01-17 20:17:22 +03:00
parent 97afb4e01a
commit 75e454f3fd
3 changed files with 20 additions and 8 deletions

View file

@ -150,7 +150,8 @@ void MessageView::prepare(
not_null<const HistoryItem*> item, not_null<const HistoryItem*> item,
Data::Forum *forum, Data::Forum *forum,
Fn<void()> customEmojiRepaint, Fn<void()> customEmojiRepaint,
ToPreviewOptions options) { ToPreviewOptions options,
Fn<void()> customLoadingFinishCallback) {
if (!forum) { if (!forum) {
_topics = nullptr; _topics = nullptr;
} else if (!_topics || _topics->forum() != forum) { } else if (!_topics || _topics->forum() != forum) {
@ -212,9 +213,11 @@ void MessageView::prepare(
if (!_loadingContext) { if (!_loadingContext) {
_loadingContext = std::make_unique<LoadingContext>(); _loadingContext = std::make_unique<LoadingContext>();
item->history()->session().downloaderTaskFinished( item->history()->session().downloaderTaskFinished(
) | rpl::start_with_next([=] { ) | rpl::start_with_next(
_textCachedFor = nullptr; customLoadingFinishCallback
}, _loadingContext->lifetime); ? customLoadingFinishCallback
: Fn<void()>([=] { _textCachedFor = nullptr; }),
_loadingContext->lifetime);
} }
_loadingContext->context = std::move(preview.loadingContext); _loadingContext->context = std::move(preview.loadingContext);
} else { } else {

View file

@ -61,7 +61,8 @@ public:
not_null<const HistoryItem*> item, not_null<const HistoryItem*> item,
Data::Forum *forum, Data::Forum *forum,
Fn<void()> customEmojiRepaint, Fn<void()> customEmojiRepaint,
ToPreviewOptions options); ToPreviewOptions options,
Fn<void()> customLoadingFinishCallback = nullptr);
void paint( void paint(
Painter &p, Painter &p,

View file

@ -1657,10 +1657,18 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupPersonalChannel(
auto &lifetime = preview->lifetime(); auto &lifetime = preview->lifetime();
using namespace Dialogs::Ui; using namespace Dialogs::Ui;
const auto previewView = lifetime.make_state<MessageView>(); const auto previewView = lifetime.make_state<MessageView>();
const auto previewUpdate = [=] { preview->update(); };
preview->resize(0, st::infoLabeled.style.font->height); preview->resize(0, st::infoLabeled.style.font->height);
const auto prepare = [previewView, preview](
not_null<HistoryItem*> item) {
previewView->prepare(
item,
nullptr,
[=] { preview->update(); },
{},
[]{});
};
if (!previewView->dependsOn(item)) { if (!previewView->dependsOn(item)) {
previewView->prepare(item, nullptr, previewUpdate, {}); prepare(item);
} }
preview->paintRequest( preview->paintRequest(
) | rpl::start_with_next([=, fullId = item->fullId()]( ) | rpl::start_with_next([=, fullId = item->fullId()](
@ -1690,7 +1698,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupPersonalChannel(
preview->rect(), preview->rect(),
tr::lng_contacts_loading(tr::now), tr::lng_contacts_loading(tr::now),
style::al_left); style::al_left);
previewView->prepare(item, nullptr, previewUpdate, {}); prepare(item);
preview->update(); preview->update();
} }
}, preview->lifetime()); }, preview->lifetime());