Allow reactions for changelog stories.

This commit is contained in:
John Preston 2023-09-25 21:36:51 +04:00
parent 846e96579d
commit 013c8ebeb4
5 changed files with 51 additions and 19 deletions

View file

@ -866,8 +866,7 @@ void Controller::show(
.list = story->recentViewers(), .list = story->recentViewers(),
.reactions = story->reactions(), .reactions = story->reactions(),
.total = story->views(), .total = story->views(),
.self = peer->isSelf(), .type = RecentViewsTypeFor(peer),
.channel = peer->isChannel(),
}, _reactions->likedValue()); }, _reactions->likedValue());
if (const auto nowLikeButton = _recentViews->likeButton()) { if (const auto nowLikeButton = _recentViews->likeButton()) {
if (wasLikeButton != nowLikeButton) { if (wasLikeButton != nowLikeButton) {
@ -875,7 +874,7 @@ void Controller::show(
} }
} }
if (peer->isSelf() || peer->isChannel()) { if (peer->isSelf() || peer->isChannel() || peer->isServiceUser()) {
_reactions->setReactionIconWidget(_recentViews->likeIconWidget()); _reactions->setReactionIconWidget(_recentViews->likeIconWidget());
} else if (const auto like = _replyArea->likeAnimationTarget()) { } else if (const auto like = _replyArea->likeAnimationTarget()) {
_reactions->setReactionIconWidget(like); _reactions->setReactionIconWidget(like);
@ -963,8 +962,7 @@ void Controller::subscribeToSession() {
.list = update.story->recentViewers(), .list = update.story->recentViewers(),
.reactions = update.story->reactions(), .reactions = update.story->reactions(),
.total = update.story->views(), .total = update.story->views(),
.self = update.story->peer()->isSelf(), .type = RecentViewsTypeFor(update.story->peer()),
.channel = update.story->peer()->isChannel(),
}); });
updateAreas(update.story); updateAreas(update.story);
} }

View file

@ -123,6 +123,16 @@ constexpr auto kLoadViewsPages = 2;
} // namespace } // namespace
RecentViewsType RecentViewsTypeFor(not_null<PeerData*> peer) {
return peer->isSelf()
? RecentViewsType::Self
: peer->isChannel()
? RecentViewsType::Channel
: peer->isServiceUser()
? RecentViewsType::Changelog
: RecentViewsType::Other;
}
RecentViews::RecentViews(not_null<Controller*> controller) RecentViews::RecentViews(not_null<Controller*> controller)
: _controller(controller) { : _controller(controller) {
} }
@ -155,7 +165,7 @@ void RecentViews::show(
|| (_data.reactions != data.reactions); || (_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.self) { if (_data.type != RecentViewsType::Self) {
_text = {}; _text = {};
_clickHandlerLifetime.destroy(); _clickHandlerLifetime.destroy();
_userpicsLifetime.destroy(); _userpicsLifetime.destroy();
@ -177,13 +187,17 @@ void RecentViews::show(
refreshClickHandler(); refreshClickHandler();
} }
if (!_data.channel) { if (_data.type != RecentViewsType::Channel
&& _data.type != RecentViewsType::Changelog) {
_likeIcon = nullptr; _likeIcon = nullptr;
_likeWrap = nullptr; _likeWrap = nullptr;
_viewsWrap = nullptr; _viewsWrap = nullptr;
} else { } else {
_viewsCounter = Lang::FormatCountDecimal(std::max(_data.total, 1)); _viewsCounter = (_data.type == RecentViewsType::Channel)
_likesCounter = _data.reactions ? Lang::FormatCountDecimal(std::max(_data.total, 1))
: tr::lng_stories_cant_reply(tr::now);
_likesCounter = ((_data.type == RecentViewsType::Channel)
&& _data.reactions)
? Lang::FormatCountDecimal(_data.reactions) ? Lang::FormatCountDecimal(_data.reactions)
: QString(); : QString();
if (!_likeWrap || !_likeIcon || !_viewsWrap) { if (!_likeWrap || !_likeIcon || !_viewsWrap) {
@ -300,14 +314,19 @@ void RecentViews::setupViewsReactions() {
st::storiesViewsText); st::storiesViewsText);
views->show(); views->show();
views->setAttribute(Qt::WA_TransparentForMouseEvents); views->setAttribute(Qt::WA_TransparentForMouseEvents);
views->move(st::storiesViewsTextPosition);
views->widthValue( views->widthValue(
) | rpl::start_with_next([=](int width) { ) | rpl::start_with_next([=](int width) {
_viewsWrap->resize(views->x() + width, _likeIcon->height()); const auto left = (_data.type == RecentViewsType::Changelog)
? st::mediaviewCaptionPadding.left()
: st::storiesViewsTextPosition.x();
views->move(left, st::storiesViewsTextPosition.y());
_viewsWrap->resize(left + width, _likeIcon->height());
updateViewsReactionsGeometry(); updateViewsReactionsGeometry();
}, _viewsWrap->lifetime()); }, _viewsWrap->lifetime());
_viewsWrap->paintRequest() | rpl::start_with_next([=] { _viewsWrap->paintRequest() | rpl::filter([=] {
return (_data.type != RecentViewsType::Changelog);
}) | rpl::start_with_next([=] {
auto p = QPainter(_viewsWrap.get()); auto p = QPainter(_viewsWrap.get());
const auto &icon = st::storiesViewsIcon; const auto &icon = st::storiesViewsIcon;
const auto top = (_viewsWrap->height() - icon.height()) / 2; const auto top = (_viewsWrap->height() - icon.height()) / 2;
@ -342,9 +361,14 @@ void RecentViews::setupViewsReactions() {
} }
void RecentViews::updateViewsReactionsGeometry() { void RecentViews::updateViewsReactionsGeometry() {
_viewsWrap->move(_outer.topLeft() + st::storiesViewsPosition); const auto outerWidth = (_data.type == RecentViewsType::Changelog)
_likeWrap->move(_outer.topLeft() ? std::max(_outer.width(), st::storiesChangelogFooterWidthMin)
+ QPoint(_outer.width() - _likeWrap->width(), 0) : _outer.width();
const auto outerOrigin = _outer.topLeft()
+ QPoint((_outer.width() - outerWidth) / 2, 0);
_viewsWrap->move(outerOrigin + st::storiesViewsPosition);
_likeWrap->move(outerOrigin
+ QPoint(outerWidth - _likeWrap->width(), 0)
+ st::storiesLikesPosition); + st::storiesLikesPosition);
} }

View file

@ -33,12 +33,18 @@ namespace Media::Stories {
class Controller; class Controller;
enum class RecentViewsType {
Other,
Self,
Channel,
Changelog,
};
struct RecentViewsData { struct RecentViewsData {
std::vector<not_null<PeerData*>> list; std::vector<not_null<PeerData*>> list;
int reactions = 0; int reactions = 0;
int total = 0; int total = 0;
bool self = false; RecentViewsType type = RecentViewsType::Other;
bool channel = false;
friend inline auto operator<=>( friend inline auto operator<=>(
const RecentViewsData &, const RecentViewsData &,
@ -48,6 +54,8 @@ struct RecentViewsData {
const RecentViewsData &) = default; const RecentViewsData &) = default;
}; };
[[nodiscard]] RecentViewsType RecentViewsTypeFor(not_null<PeerData*> peer);
class RecentViews final { class RecentViews final {
public: public:
explicit RecentViews(not_null<Controller*> controller); explicit RecentViews(not_null<Controller*> controller);

View file

@ -675,8 +675,9 @@ void ReplyArea::show(
}), }),
}); });
_controls->clear(); _controls->clear();
const auto hidden = peer && (!peer->isUser() || peer->isSelf()); const auto hidden = peer
const auto cant = !peer || peer->isServiceUser(); && (!peer->isUser() || peer->isSelf() || peer->isServiceUser());
const auto cant = !peer;
if (!hidden && !cant) { if (!hidden && !cant) {
_controls->show(); _controls->show();
} else { } else {

View file

@ -1014,3 +1014,4 @@ storiesLikeCountStyle: TextStyle(defaultTextStyle) {
linkFont: font(32px semibold); linkFont: font(32px semibold);
linkFontOver: font(32px semibold underline); linkFontOver: font(32px semibold underline);
} }
storiesChangelogFooterWidthMin: 240px;