Show reactions count below my stories.

This commit is contained in:
John Preston 2023-08-04 17:30:49 +02:00
parent 318d75cc63
commit 4e78c24abf
6 changed files with 41 additions and 13 deletions

View File

@ -1263,6 +1263,7 @@ void Stories::loadViewsSlice(
const auto &data = result.data(); const auto &data = result.data();
auto slice = StoryViews{ auto slice = StoryViews{
.nextOffset = data.vnext_offset().value_or_empty(), .nextOffset = data.vnext_offset().value_or_empty(),
.reactions = data.vreactions_count().v,
.total = data.vcount().v, .total = data.vcount().v,
}; };
_owner->processUsers(data.vusers()); _owner->processUsers(data.vusers());

View File

@ -347,10 +347,16 @@ int Story::views() const {
return _views.total; return _views.total;
} }
int Story::reactions() const {
return _views.reactions;
}
void Story::applyViewsSlice( void Story::applyViewsSlice(
const QString &offset, const QString &offset,
const StoryViews &slice) { 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; _views.total = slice.total;
if (offset.isEmpty()) { if (offset.isEmpty()) {
_views = slice; _views = slice;
@ -362,6 +368,11 @@ void Story::applyViewsSlice(
_views.nextOffset = slice.nextOffset; _views.nextOffset = slice.nextOffset;
if (_views.nextOffset.isEmpty()) { if (_views.nextOffset.isEmpty()) {
_views.total = int(_views.list.size()); _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()); const auto known = int(_views.list.size());
@ -421,10 +432,12 @@ void Story::applyFields(
data.ventities().value_or_empty()), data.ventities().value_or_empty()),
}; };
auto views = _views.total; auto views = _views.total;
auto reactions = _views.reactions;
auto viewers = std::vector<not_null<PeerData*>>(); auto viewers = std::vector<not_null<PeerData*>>();
if (!data.is_min()) { if (!data.is_min()) {
if (const auto info = data.vviews()) { if (const auto info = data.vviews()) {
views = info->data().vviews_count().v; views = info->data().vviews_count().v;
reactions = info->data().vreactions_count().v;
if (const auto list = info->data().vrecent_viewers()) { if (const auto list = info->data().vrecent_viewers()) {
viewers.reserve(list->v.size()); viewers.reserve(list->v.size());
auto &owner = _peer->owner(); auto &owner = _peer->owner();
@ -442,6 +455,7 @@ void Story::applyFields(
const auto mediaChanged = (_media != media); const auto mediaChanged = (_media != media);
const auto captionChanged = (_caption != caption); const auto captionChanged = (_caption != caption);
const auto viewsChanged = (_views.total != views) const auto viewsChanged = (_views.total != views)
|| (_views.reactions != reactions)
|| (_recentViewers != viewers); || (_recentViewers != viewers);
_privacyPublic = (privacy == StoryPrivacy::Public); _privacyPublic = (privacy == StoryPrivacy::Public);
@ -452,8 +466,8 @@ void Story::applyFields(
_edited = edited; _edited = edited;
_pinned = pinned; _pinned = pinned;
_noForwards = noForwards; _noForwards = noForwards;
if (_views.total != views) { if (_views.reactions != reactions || _views.total != views) {
_views = StoryViews{ .total = views }; _views = StoryViews{ .reactions = reactions, .total = views };
} }
if (viewsChanged) { if (viewsChanged) {
_recentViewers = std::move(viewers); _recentViewers = std::move(viewers);

View File

@ -68,6 +68,7 @@ struct StoryView {
struct StoryViews { struct StoryViews {
std::vector<StoryView> list; std::vector<StoryView> list;
QString nextOffset; QString nextOffset;
int reactions = 0;
int total = 0; int total = 0;
}; };
@ -125,6 +126,7 @@ public:
-> const std::vector<not_null<PeerData*>> &; -> const std::vector<not_null<PeerData*>> &;
[[nodiscard]] const StoryViews &viewsList() const; [[nodiscard]] const StoryViews &viewsList() const;
[[nodiscard]] int views() const; [[nodiscard]] int views() const;
[[nodiscard]] int reactions() const;
void applyViewsSlice(const QString &offset, const StoryViews &slice); void applyViewsSlice(const QString &offset, const StoryViews &slice);
void applyChanges( void applyChanges(

View File

@ -880,6 +880,7 @@ void Controller::show(
}); });
_recentViews->show({ _recentViews->show({
.list = story->recentViewers(), .list = story->recentViewers(),
.reactions = story->reactions(),
.total = story->views(), .total = story->views(),
.valid = user->isSelf(), .valid = user->isSelf(),
}); });
@ -951,6 +952,7 @@ void Controller::subscribeToSession() {
} else { } else {
_recentViews->show({ _recentViews->show({
.list = update.story->recentViewers(), .list = update.story->recentViewers(),
.reactions = update.story->reactions(),
.total = update.story->views(), .total = update.story->views(),
.valid = update.story->peer()->isSelf(), .valid = update.story->peer()->isSelf(),
}); });
@ -1439,12 +1441,9 @@ void Controller::refreshViewsFromData() {
const auto maybeStory = stories.lookup(_shown); const auto maybeStory = stories.lookup(_shown);
if (!maybeStory || !user->isSelf()) { if (!maybeStory || !user->isSelf()) {
_viewsSlice = {}; _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() { void Controller::unfocusReply() {

View File

@ -131,7 +131,9 @@ void RecentViews::show(RecentViewsData data) {
if (_data == data) { if (_data == data) {
return; 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); const auto usersChanged = !_userpics || (_data.list != data.list);
_data = data; _data = data;
if (!_data.valid) { if (!_data.valid) {
@ -148,7 +150,7 @@ void RecentViews::show(RecentViewsData data) {
if (!_userpics) { if (!_userpics) {
setupUserpics(); setupUserpics();
} }
if (totalChanged) { if (countersChanged) {
updateText(); updateText();
} }
if (usersChanged) { if (usersChanged) {
@ -253,9 +255,13 @@ void RecentViews::updatePartsGeometry() {
} }
void RecentViews::updateText() { void RecentViews::updateText() {
_text.setText(st::defaultTextStyle, _data.total const auto text = _data.total
? tr::lng_stories_views(tr::now, lt_count, _data.total) ? (tr::lng_stories_views(tr::now, lt_count, _data.total)
: tr::lng_stories_no_views(tr::now)); + (_data.reactions
? (u" "_q + QChar(10084) + QString::number(_data.reactions))
: QString()))
: tr::lng_stories_no_views(tr::now);
_text.setText(st::defaultTextStyle, text);
updatePartsGeometry(); updatePartsGeometry();
} }
@ -340,6 +346,7 @@ void RecentViews::addMenuRow(Data::StoryView entry, const QDateTime &now) {
return Ui::WhoReactedEntryData{ return Ui::WhoReactedEntryData{
.text = peer->name(), .text = peer->name(),
.date = date, .date = date,
.customEntityData = Data::ReactionEntityData(entry.reaction),
.userpic = std::move(userpic), .userpic = std::move(userpic),
.callback = [=] { show->show(PrepareShortInfoBox(peer)); }, .callback = [=] { show->show(PrepareShortInfoBox(peer)); },
}; };
@ -349,12 +356,14 @@ void RecentViews::addMenuRow(Data::StoryView entry, const QDateTime &now) {
auto data = prepare(i->view); auto data = prepare(i->view);
i->peer = peer; i->peer = peer;
i->date = date; i->date = date;
i->customEntityData = data.customEntityData;
i->callback = data.callback; i->callback = data.callback;
i->action->setData(std::move(data)); i->action->setData(std::move(data));
} else { } else {
auto view = Ui::PeerUserpicView(); auto view = Ui::PeerUserpicView();
auto data = prepare(view); auto data = prepare(view);
auto callback = data.callback; auto callback = data.callback;
auto customEntityData = data.customEntityData;
auto action = base::make_unique_q<Ui::WhoReactedEntryAction>( auto action = base::make_unique_q<Ui::WhoReactedEntryAction>(
_menu->menu(), _menu->menu(),
nullptr, nullptr,
@ -366,6 +375,7 @@ void RecentViews::addMenuRow(Data::StoryView entry, const QDateTime &now) {
.action = raw, .action = raw,
.peer = peer, .peer = peer,
.date = date, .date = date,
.customEntityData = std::move(customEntityData),
.callback = std::move(callback), .callback = std::move(callback),
.view = std::move(view), .view = std::move(view),
}); });

View File

@ -32,6 +32,7 @@ class Controller;
struct RecentViewsData { struct RecentViewsData {
std::vector<not_null<PeerData*>> list; std::vector<not_null<PeerData*>> list;
int reactions = 0;
int total = 0; int total = 0;
bool valid = false; bool valid = false;
@ -55,6 +56,7 @@ private:
not_null<Ui::WhoReactedEntryAction*> action; not_null<Ui::WhoReactedEntryAction*> action;
PeerData *peer = nullptr; PeerData *peer = nullptr;
QString date; QString date;
QString customEntityData;
Fn<void()> callback; Fn<void()> callback;
Ui::PeerUserpicView view; Ui::PeerUserpicView view;
InMemoryKey key; InMemoryKey key;