mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 07:07:08 +02:00
Correctly show views count without viewers.
This commit is contained in:
parent
cdb5f4dc1e
commit
41eac3692c
5 changed files with 56 additions and 29 deletions
Telegram/SourceFiles
|
@ -313,15 +313,17 @@ bool Story::applyChanges(StoryMedia media, const MTPDstoryItem &data) {
|
|||
&owner().session(),
|
||||
data.ventities().value_or_empty()),
|
||||
};
|
||||
auto views = 0;
|
||||
auto views = -1;
|
||||
auto recent = std::vector<not_null<PeerData*>>();
|
||||
if (const auto info = data.vviews()) {
|
||||
views = info->data().vviews_count().v;
|
||||
if (const auto list = info->data().vrecent_viewers()) {
|
||||
recent.reserve(list->v.size());
|
||||
auto &owner = _peer->owner();
|
||||
for (const auto &id : list->v) {
|
||||
recent.push_back(owner.peer(peerFromUser(id)));
|
||||
if (!data.is_min()) {
|
||||
if (const auto info = data.vviews()) {
|
||||
views = info->data().vviews_count().v;
|
||||
if (const auto list = info->data().vrecent_viewers()) {
|
||||
recent.reserve(list->v.size());
|
||||
auto &owner = _peer->owner();
|
||||
for (const auto &id : list->v) {
|
||||
recent.push_back(owner.peer(peerFromUser(id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +333,7 @@ bool Story::applyChanges(StoryMedia media, const MTPDstoryItem &data) {
|
|||
|| (_isPublic != isPublic)
|
||||
|| (_closeFriends != closeFriends)
|
||||
|| (_caption != caption)
|
||||
|| (_views != views)
|
||||
|| (views >= 0 && _views != views)
|
||||
|| (_recentViewers != recent);
|
||||
if (!changed) {
|
||||
return false;
|
||||
|
@ -341,7 +343,9 @@ bool Story::applyChanges(StoryMedia media, const MTPDstoryItem &data) {
|
|||
_isPublic = isPublic;
|
||||
_closeFriends = closeFriends;
|
||||
_caption = std::move(caption);
|
||||
_views = views;
|
||||
if (views >= 0) {
|
||||
_views = views;
|
||||
}
|
||||
_recentViewers = std::move(recent);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -150,15 +150,41 @@ void RecentViews::show(RecentViewsData data) {
|
|||
if (usersChanged) {
|
||||
updateUserpics();
|
||||
}
|
||||
refreshClickHandler();
|
||||
}
|
||||
|
||||
void RecentViews::refreshClickHandler() {
|
||||
const auto nowEmpty = _data.list.empty();
|
||||
const auto wasEmpty = !_clickHandlerLifetime;
|
||||
const auto raw = _widget.get();
|
||||
if (wasEmpty == nowEmpty) {
|
||||
return;
|
||||
} else if (nowEmpty) {
|
||||
_clickHandlerLifetime.destroy();
|
||||
} else {
|
||||
_clickHandlerLifetime = raw->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||
return (_data.total > 0)
|
||||
&& (e->type() == QEvent::MouseButtonPress)
|
||||
&& (static_cast<QMouseEvent*>(e.get())->button()
|
||||
== Qt::LeftButton);
|
||||
}) | rpl::start_with_next([=] {
|
||||
showMenu();
|
||||
});
|
||||
}
|
||||
raw->setCursor(_clickHandlerLifetime
|
||||
? style::cur_pointer
|
||||
: style::cur_default);
|
||||
}
|
||||
|
||||
void RecentViews::updateUserpics() {
|
||||
_userpicsLifetime = ContentByUsers(
|
||||
_data.list
|
||||
) | rpl::start_with_next([=](
|
||||
const std::vector<Ui::GroupCallUser> &list) {
|
||||
const std::vector<Ui::GroupCallUser> &list) {
|
||||
_userpics->update(list, true);
|
||||
});
|
||||
_userpics->finishAnimating();
|
||||
}
|
||||
|
||||
void RecentViews::setupUserpics() {
|
||||
|
@ -201,18 +227,6 @@ void RecentViews::setupWidget() {
|
|||
_textPosition.y(),
|
||||
raw->width() - _userpicsWidth - st::storiesRecentViewsSkip);
|
||||
}, raw->lifetime());
|
||||
|
||||
raw->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||
return (_data.total > 0)
|
||||
&& (e->type() == QEvent::MouseButtonPress)
|
||||
&& (static_cast<QMouseEvent*>(e.get())->button()
|
||||
== Qt::LeftButton);
|
||||
}) | rpl::start_with_next([=] {
|
||||
showMenu();
|
||||
}, raw->lifetime());
|
||||
|
||||
raw->setCursor(style::cur_pointer);
|
||||
}
|
||||
|
||||
void RecentViews::updatePartsGeometry() {
|
||||
|
@ -242,7 +256,7 @@ void RecentViews::updateText() {
|
|||
}
|
||||
|
||||
void RecentViews::showMenu() {
|
||||
if (_menu) {
|
||||
if (_menu || _data.list.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ private:
|
|||
void addMenuRowPlaceholder();
|
||||
void rebuildMenuTail();
|
||||
void subscribeToMenuUserpicsLoading(not_null<Main::Session*> session);
|
||||
void refreshClickHandler();
|
||||
|
||||
const not_null<Controller*> _controller;
|
||||
|
||||
|
@ -88,6 +89,7 @@ private:
|
|||
rpl::variable<bool> _shortAnimationPlaying;
|
||||
bool _waitingUserpicsCheck = false;
|
||||
rpl::lifetime _waitingForUserpicsLifetime;
|
||||
rpl::lifetime _clickHandlerLifetime;
|
||||
|
||||
QRect _outer;
|
||||
QPoint _userpicsPosition;
|
||||
|
|
|
@ -348,11 +348,17 @@ void GroupCallUserpics::update(
|
|||
_speakingAnimation.start();
|
||||
}
|
||||
|
||||
if (!visible) {
|
||||
for (auto &userpic : _list) {
|
||||
userpic.shownAnimation.stop();
|
||||
userpic.leftAnimation.stop();
|
||||
}
|
||||
if (visible) {
|
||||
recountAndRepaint();
|
||||
} else {
|
||||
finishAnimating();
|
||||
}
|
||||
}
|
||||
|
||||
void GroupCallUserpics::finishAnimating() {
|
||||
for (auto &userpic : _list) {
|
||||
userpic.shownAnimation.stop();
|
||||
userpic.leftAnimation.stop();
|
||||
}
|
||||
recountAndRepaint();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
const std::vector<GroupCallUser> &users,
|
||||
bool visible);
|
||||
void paint(QPainter &p, int x, int y, int size);
|
||||
void finishAnimating();
|
||||
|
||||
[[nodiscard]] int maxWidth() const;
|
||||
[[nodiscard]] rpl::producer<int> widthValue() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue