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();
auto slice = StoryViews{
.nextOffset = data.vnext_offset().value_or_empty(),
.reactions = data.vreactions_count().v,
.total = data.vcount().v,
};
_owner->processUsers(data.vusers());

View File

@ -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<not_null<PeerData*>>();
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);

View File

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

View File

@ -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() {

View File

@ -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<Ui::WhoReactedEntryAction>(
_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),
});

View File

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