mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 06:37:24 +02:00
Allow reactions for changelog stories.
This commit is contained in:
parent
846e96579d
commit
013c8ebeb4
5 changed files with 51 additions and 19 deletions
|
@ -866,8 +866,7 @@ void Controller::show(
|
|||
.list = story->recentViewers(),
|
||||
.reactions = story->reactions(),
|
||||
.total = story->views(),
|
||||
.self = peer->isSelf(),
|
||||
.channel = peer->isChannel(),
|
||||
.type = RecentViewsTypeFor(peer),
|
||||
}, _reactions->likedValue());
|
||||
if (const auto nowLikeButton = _recentViews->likeButton()) {
|
||||
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());
|
||||
} else if (const auto like = _replyArea->likeAnimationTarget()) {
|
||||
_reactions->setReactionIconWidget(like);
|
||||
|
@ -963,8 +962,7 @@ void Controller::subscribeToSession() {
|
|||
.list = update.story->recentViewers(),
|
||||
.reactions = update.story->reactions(),
|
||||
.total = update.story->views(),
|
||||
.self = update.story->peer()->isSelf(),
|
||||
.channel = update.story->peer()->isChannel(),
|
||||
.type = RecentViewsTypeFor(update.story->peer()),
|
||||
});
|
||||
updateAreas(update.story);
|
||||
}
|
||||
|
|
|
@ -123,6 +123,16 @@ constexpr auto kLoadViewsPages = 2;
|
|||
|
||||
} // 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)
|
||||
: _controller(controller) {
|
||||
}
|
||||
|
@ -155,7 +165,7 @@ void RecentViews::show(
|
|||
|| (_data.reactions != data.reactions);
|
||||
const auto usersChanged = !_userpics || (_data.list != data.list);
|
||||
_data = data;
|
||||
if (!_data.self) {
|
||||
if (_data.type != RecentViewsType::Self) {
|
||||
_text = {};
|
||||
_clickHandlerLifetime.destroy();
|
||||
_userpicsLifetime.destroy();
|
||||
|
@ -177,13 +187,17 @@ void RecentViews::show(
|
|||
refreshClickHandler();
|
||||
}
|
||||
|
||||
if (!_data.channel) {
|
||||
if (_data.type != RecentViewsType::Channel
|
||||
&& _data.type != RecentViewsType::Changelog) {
|
||||
_likeIcon = nullptr;
|
||||
_likeWrap = nullptr;
|
||||
_viewsWrap = nullptr;
|
||||
} else {
|
||||
_viewsCounter = Lang::FormatCountDecimal(std::max(_data.total, 1));
|
||||
_likesCounter = _data.reactions
|
||||
_viewsCounter = (_data.type == RecentViewsType::Channel)
|
||||
? 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)
|
||||
: QString();
|
||||
if (!_likeWrap || !_likeIcon || !_viewsWrap) {
|
||||
|
@ -300,14 +314,19 @@ void RecentViews::setupViewsReactions() {
|
|||
st::storiesViewsText);
|
||||
views->show();
|
||||
views->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
views->move(st::storiesViewsTextPosition);
|
||||
|
||||
views->widthValue(
|
||||
) | 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();
|
||||
}, _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());
|
||||
const auto &icon = st::storiesViewsIcon;
|
||||
const auto top = (_viewsWrap->height() - icon.height()) / 2;
|
||||
|
@ -342,9 +361,14 @@ void RecentViews::setupViewsReactions() {
|
|||
}
|
||||
|
||||
void RecentViews::updateViewsReactionsGeometry() {
|
||||
_viewsWrap->move(_outer.topLeft() + st::storiesViewsPosition);
|
||||
_likeWrap->move(_outer.topLeft()
|
||||
+ QPoint(_outer.width() - _likeWrap->width(), 0)
|
||||
const auto outerWidth = (_data.type == RecentViewsType::Changelog)
|
||||
? std::max(_outer.width(), st::storiesChangelogFooterWidthMin)
|
||||
: _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);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,12 +33,18 @@ namespace Media::Stories {
|
|||
|
||||
class Controller;
|
||||
|
||||
enum class RecentViewsType {
|
||||
Other,
|
||||
Self,
|
||||
Channel,
|
||||
Changelog,
|
||||
};
|
||||
|
||||
struct RecentViewsData {
|
||||
std::vector<not_null<PeerData*>> list;
|
||||
int reactions = 0;
|
||||
int total = 0;
|
||||
bool self = false;
|
||||
bool channel = false;
|
||||
RecentViewsType type = RecentViewsType::Other;
|
||||
|
||||
friend inline auto operator<=>(
|
||||
const RecentViewsData &,
|
||||
|
@ -48,6 +54,8 @@ struct RecentViewsData {
|
|||
const RecentViewsData &) = default;
|
||||
};
|
||||
|
||||
[[nodiscard]] RecentViewsType RecentViewsTypeFor(not_null<PeerData*> peer);
|
||||
|
||||
class RecentViews final {
|
||||
public:
|
||||
explicit RecentViews(not_null<Controller*> controller);
|
||||
|
|
|
@ -675,8 +675,9 @@ void ReplyArea::show(
|
|||
}),
|
||||
});
|
||||
_controls->clear();
|
||||
const auto hidden = peer && (!peer->isUser() || peer->isSelf());
|
||||
const auto cant = !peer || peer->isServiceUser();
|
||||
const auto hidden = peer
|
||||
&& (!peer->isUser() || peer->isSelf() || peer->isServiceUser());
|
||||
const auto cant = !peer;
|
||||
if (!hidden && !cant) {
|
||||
_controls->show();
|
||||
} else {
|
||||
|
|
|
@ -1014,3 +1014,4 @@ storiesLikeCountStyle: TextStyle(defaultTextStyle) {
|
|||
linkFont: font(32px semibold);
|
||||
linkFontOver: font(32px semibold underline);
|
||||
}
|
||||
storiesChangelogFooterWidthMin: 240px;
|
||||
|
|
Loading…
Add table
Reference in a new issue