diff --git a/Telegram/SourceFiles/data/data_stories.cpp b/Telegram/SourceFiles/data/data_stories.cpp index 4107f7a79..586104855 100644 --- a/Telegram/SourceFiles/data/data_stories.cpp +++ b/Telegram/SourceFiles/data/data_stories.cpp @@ -1263,6 +1263,7 @@ void Stories::loadViewsSlice( const auto &data = result.data(); auto slice = StoryViews{ .nextOffset = data.vnext_offset().value_or_empty(), + .reactions = data.vreactions_count().v, .total = data.vcount().v, }; _owner->processUsers(data.vusers()); diff --git a/Telegram/SourceFiles/data/data_story.cpp b/Telegram/SourceFiles/data/data_story.cpp index 8f629bd34..30596269f 100644 --- a/Telegram/SourceFiles/data/data_story.cpp +++ b/Telegram/SourceFiles/data/data_story.cpp @@ -347,10 +347,16 @@ int Story::views() const { return _views.total; } +int Story::reactions() const { + return _views.reactions; +} + void Story::applyViewsSlice( const QString &offset, const StoryViews &slice) { - const auto changed = (_views.total != slice.total); + const auto changed = (_views.reactions != slice.reactions) + || (_views.total != slice.total); + _views.reactions = slice.reactions; _views.total = slice.total; if (offset.isEmpty()) { _views = slice; @@ -362,6 +368,11 @@ void Story::applyViewsSlice( _views.nextOffset = slice.nextOffset; if (_views.nextOffset.isEmpty()) { _views.total = int(_views.list.size()); + _views.reactions = _views.total + - ranges::count( + _views.list, + Data::ReactionId(), + &StoryView::reaction); } } const auto known = int(_views.list.size()); @@ -421,10 +432,12 @@ void Story::applyFields( data.ventities().value_or_empty()), }; auto views = _views.total; + auto reactions = _views.reactions; auto viewers = std::vector>(); if (!data.is_min()) { if (const auto info = data.vviews()) { views = info->data().vviews_count().v; + reactions = info->data().vreactions_count().v; if (const auto list = info->data().vrecent_viewers()) { viewers.reserve(list->v.size()); auto &owner = _peer->owner(); @@ -442,6 +455,7 @@ void Story::applyFields( const auto mediaChanged = (_media != media); const auto captionChanged = (_caption != caption); const auto viewsChanged = (_views.total != views) + || (_views.reactions != reactions) || (_recentViewers != viewers); _privacyPublic = (privacy == StoryPrivacy::Public); @@ -452,8 +466,8 @@ void Story::applyFields( _edited = edited; _pinned = pinned; _noForwards = noForwards; - if (_views.total != views) { - _views = StoryViews{ .total = views }; + if (_views.reactions != reactions || _views.total != views) { + _views = StoryViews{ .reactions = reactions, .total = views }; } if (viewsChanged) { _recentViewers = std::move(viewers); diff --git a/Telegram/SourceFiles/data/data_story.h b/Telegram/SourceFiles/data/data_story.h index 21ab368b6..50d1dbff8 100644 --- a/Telegram/SourceFiles/data/data_story.h +++ b/Telegram/SourceFiles/data/data_story.h @@ -68,6 +68,7 @@ struct StoryView { struct StoryViews { std::vector list; QString nextOffset; + int reactions = 0; int total = 0; }; @@ -125,6 +126,7 @@ public: -> const std::vector> &; [[nodiscard]] const StoryViews &viewsList() const; [[nodiscard]] int views() const; + [[nodiscard]] int reactions() const; void applyViewsSlice(const QString &offset, const StoryViews &slice); void applyChanges( diff --git a/Telegram/SourceFiles/media/stories/media_stories_controller.cpp b/Telegram/SourceFiles/media/stories/media_stories_controller.cpp index bc2233f3d..67fde0447 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_controller.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_controller.cpp @@ -880,6 +880,7 @@ void Controller::show( }); _recentViews->show({ .list = story->recentViewers(), + .reactions = story->reactions(), .total = story->views(), .valid = user->isSelf(), }); @@ -951,6 +952,7 @@ void Controller::subscribeToSession() { } else { _recentViews->show({ .list = update.story->recentViewers(), + .reactions = update.story->reactions(), .total = update.story->views(), .valid = update.story->peer()->isSelf(), }); @@ -1439,12 +1441,9 @@ void Controller::refreshViewsFromData() { const auto maybeStory = stories.lookup(_shown); if (!maybeStory || !user->isSelf()) { _viewsSlice = {}; - return; + } else { + _viewsSlice = (*maybeStory)->viewsList(); } - const auto story = *maybeStory; - const auto &views = story->viewsList(); - const auto total = story->views(); - _viewsSlice = story->viewsList(); } void Controller::unfocusReply() { diff --git a/Telegram/SourceFiles/media/stories/media_stories_recent_views.cpp b/Telegram/SourceFiles/media/stories/media_stories_recent_views.cpp index 5a5567466..6155b9f0f 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_recent_views.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_recent_views.cpp @@ -131,7 +131,9 @@ void RecentViews::show(RecentViewsData data) { if (_data == data) { return; } - const auto totalChanged = _text.isEmpty() || (_data.total != data.total); + const auto countersChanged = _text.isEmpty() + || (_data.total != data.total) + || (_data.reactions != data.reactions); const auto usersChanged = !_userpics || (_data.list != data.list); _data = data; if (!_data.valid) { @@ -148,7 +150,7 @@ void RecentViews::show(RecentViewsData data) { if (!_userpics) { setupUserpics(); } - if (totalChanged) { + if (countersChanged) { updateText(); } if (usersChanged) { @@ -253,9 +255,13 @@ void RecentViews::updatePartsGeometry() { } void RecentViews::updateText() { - _text.setText(st::defaultTextStyle, _data.total - ? tr::lng_stories_views(tr::now, lt_count, _data.total) - : tr::lng_stories_no_views(tr::now)); + const auto text = _data.total + ? (tr::lng_stories_views(tr::now, lt_count, _data.total) + + (_data.reactions + ? (u" "_q + QChar(10084) + QString::number(_data.reactions)) + : QString())) + : tr::lng_stories_no_views(tr::now); + _text.setText(st::defaultTextStyle, text); updatePartsGeometry(); } @@ -340,6 +346,7 @@ void RecentViews::addMenuRow(Data::StoryView entry, const QDateTime &now) { return Ui::WhoReactedEntryData{ .text = peer->name(), .date = date, + .customEntityData = Data::ReactionEntityData(entry.reaction), .userpic = std::move(userpic), .callback = [=] { show->show(PrepareShortInfoBox(peer)); }, }; @@ -349,12 +356,14 @@ void RecentViews::addMenuRow(Data::StoryView entry, const QDateTime &now) { auto data = prepare(i->view); i->peer = peer; i->date = date; + i->customEntityData = data.customEntityData; i->callback = data.callback; i->action->setData(std::move(data)); } else { auto view = Ui::PeerUserpicView(); auto data = prepare(view); auto callback = data.callback; + auto customEntityData = data.customEntityData; auto action = base::make_unique_q( _menu->menu(), nullptr, @@ -366,6 +375,7 @@ void RecentViews::addMenuRow(Data::StoryView entry, const QDateTime &now) { .action = raw, .peer = peer, .date = date, + .customEntityData = std::move(customEntityData), .callback = std::move(callback), .view = std::move(view), }); diff --git a/Telegram/SourceFiles/media/stories/media_stories_recent_views.h b/Telegram/SourceFiles/media/stories/media_stories_recent_views.h index 14bbdba68..294ea86f9 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_recent_views.h +++ b/Telegram/SourceFiles/media/stories/media_stories_recent_views.h @@ -32,6 +32,7 @@ class Controller; struct RecentViewsData { std::vector> list; + int reactions = 0; int total = 0; bool valid = false; @@ -55,6 +56,7 @@ private: not_null action; PeerData *peer = nullptr; QString date; + QString customEntityData; Fn callback; Ui::PeerUserpicView view; InMemoryKey key;