Added reactions count to recent posts in list from statistics info.

This commit is contained in:
23rd 2023-11-22 07:49:59 +03:00 committed by John Preston
parent 1fbcec1d24
commit 6a87fef851
4 changed files with 68 additions and 56 deletions

View file

@ -621,7 +621,7 @@ void InnerWidget::fill() {
if (const auto i = _peer->owner().message(_contextId)) {
Ui::AddSkip(inner);
const auto preview = inner->add(
object_ptr<MessagePreview>(this, i, -1, -1, QImage()));
object_ptr<MessagePreview>(this, i, QImage()));
AddContextMenu(preview, _controller, i);
Ui::AddSkip(inner);
Ui::AddDivider(inner);
@ -719,15 +719,15 @@ void InnerWidget::fillRecentPosts() {
? Ui::CreateChild<MessagePreview>(
button,
maybeItem,
info.viewsCount,
info.forwardsCount,
std::move(cachedPreview))
: Ui::CreateChild<MessagePreview>(
button,
maybeStory,
info.viewsCount,
info.forwardsCount,
std::move(cachedPreview));
raw->setInfo(
info.viewsCount,
info.forwardsCount,
info.reactionsCount);
if (maybeItem) {
AddContextMenu(button, _controller, maybeItem);

View file

@ -74,32 +74,12 @@ namespace {
MessagePreview::MessagePreview(
not_null<Ui::RpWidget*> parent,
not_null<HistoryItem*> item,
int views,
int shares,
QImage cachedPreview)
: Ui::RpWidget(parent)
, _messageId(item->fullId())
, _date(
st::statisticsHeaderTitleTextStyle,
Ui::FormatDateTime(ItemDateTime(item)))
, _views(
st::defaultPeerListItem.nameStyle,
(views >= 0)
? tr::lng_stats_recent_messages_views(
tr::now,
lt_count_decimal,
views)
: QString())
, _shares(
st::statisticsHeaderTitleTextStyle,
(shares >= 0)
? tr::lng_stats_recent_messages_shares(
tr::now,
lt_count_decimal,
shares)
: QString())
, _viewsWidth(_views.maxWidth())
, _sharesWidth(_shares.maxWidth())
, _preview(std::move(cachedPreview)) {
_text.setMarkedText(
st::defaultPeerListItem.nameStyle,
@ -109,7 +89,7 @@ MessagePreview::MessagePreview(
.session = &item->history()->session(),
.customEmojiRepaint = [=] { update(); },
});
if (item->media()->hasSpoiler()) {
if (item->media() && item->media()->hasSpoiler()) {
_spoiler = std::make_unique<Ui::SpoilerAnimation>([=] { update(); });
}
if (_preview.isNull()) {
@ -129,32 +109,12 @@ MessagePreview::MessagePreview(
MessagePreview::MessagePreview(
not_null<Ui::RpWidget*> parent,
not_null<Data::Story*> story,
int views,
int shares,
QImage cachedPreview)
: Ui::RpWidget(parent)
, _storyId(story->fullId())
, _date(
st::statisticsHeaderTitleTextStyle,
Ui::FormatDateTime(base::unixtime::parse(story->date())))
, _views(
st::defaultPeerListItem.nameStyle,
(views >= 0)
? tr::lng_stats_recent_messages_views(
tr::now,
lt_count_decimal,
views)
: QString())
, _shares(
st::statisticsHeaderTitleTextStyle,
(shares >= 0)
? tr::lng_stats_recent_messages_shares(
tr::now,
lt_count_decimal,
shares)
: QString())
, _viewsWidth(_views.maxWidth())
, _sharesWidth(_shares.maxWidth())
, _preview(std::move(cachedPreview)) {
_text.setMarkedText(
st::defaultPeerListItem.nameStyle,
@ -176,6 +136,26 @@ MessagePreview::MessagePreview(
}
}
void MessagePreview::setInfo(int views, int shares, int reactions) {
_views = Ui::Text::String(
st::defaultPeerListItem.nameStyle,
(views >= 0)
? tr::lng_stats_recent_messages_views(
tr::now,
lt_count_decimal,
views)
: QString());
_shares = Ui::Text::String(
st::statisticsHeaderTitleTextStyle,
(shares >= 0) ? Lang::FormatCountDecimal(shares) : QString());
_reactions = Ui::Text::String(
st::statisticsHeaderTitleTextStyle,
(reactions >= 0) ? Lang::FormatCountDecimal(reactions) : QString());
_viewsWidth = (_views.maxWidth());
_sharesWidth = (_shares.maxWidth());
_reactionsWidth = (_reactions.maxWidth());
}
void MessagePreview::processPreview() {
const auto session = _photoMedia
? &_photoMedia->owner()->session()
@ -234,7 +214,17 @@ void MessagePreview::paintEvent(QPaintEvent *e) {
auto p = QPainter(this);
const auto padding = st::boxRowPadding.left() / 2;
const auto rightWidth = std::max(_viewsWidth, _sharesWidth) + padding;
const auto rightSubTextWidth = 0
+ (_sharesWidth
? _sharesWidth + st::statisticsRecentPostShareIcon.width()
: 0)
+ (_reactionsWidth
? _reactionsWidth
+ st::statisticsRecentPostReactionIcon.width()
+ st::statisticsChartRulerCaptionSkip
: 0);
const auto rightWidth = std::max(_viewsWidth, rightSubTextWidth)
+ padding;
const auto left = _preview.isNull()
? st::peerListBoxItem.photoPosition.x()
: st::peerListBoxItem.namePosition.x();
@ -292,11 +282,32 @@ void MessagePreview::paintEvent(QPaintEvent *e) {
.outerWidth = width() - left,
.availableWidth = width() - rightWidth - left,
});
_shares.draw(p, {
.position = { width() - _sharesWidth, bottomTextTop },
.outerWidth = _sharesWidth,
.availableWidth = _sharesWidth,
});
{
auto right = width() - _sharesWidth;
_shares.draw(p, {
.position = { right, bottomTextTop },
.outerWidth = _sharesWidth,
.availableWidth = _sharesWidth,
});
const auto bottomTextBottom = bottomTextTop
+ st::statisticsHeaderTitleTextStyle.font->height;
if (_sharesWidth) {
const auto &icon = st::statisticsRecentPostShareIcon;
const auto iconTop = bottomTextBottom - icon.height();
icon.paint(p, { (right -= icon.width()), iconTop }, width());
}
right -= _reactionsWidth + st::statisticsChartRulerCaptionSkip;
_reactions.draw(p, {
.position = { right, bottomTextTop },
.outerWidth = _reactionsWidth,
.availableWidth = _reactionsWidth,
});
if (_reactionsWidth) {
const auto &icon = st::statisticsRecentPostReactionIcon;
const auto iconTop = bottomTextBottom - icon.height();
icon.paint(p, { (right -= icon.width()), iconTop }, width());
}
}
}
void MessagePreview::saveState(SavedState &state) const {

View file

@ -30,16 +30,13 @@ public:
MessagePreview(
not_null<Ui::RpWidget*> parent,
not_null<HistoryItem*> item,
int views,
int shares,
QImage cachedPreview);
MessagePreview(
not_null<Ui::RpWidget*> parent,
not_null<Data::Story*> story,
int views,
int shares,
QImage cachedPreview);
void setInfo(int views, int shares, int reactions);
void saveState(SavedState &state) const;
protected:
@ -56,9 +53,11 @@ private:
Ui::Text::String _date;
Ui::Text::String _views;
Ui::Text::String _shares;
Ui::Text::String _reactions;
int _viewsWidth = 0;
int _sharesWidth = 0;
int _reactionsWidth = 0;
QImage _cornerCache;
QImage _preview;

View file

@ -104,6 +104,8 @@ statisticsRecentPostButton: SettingsButton(defaultSettingsButton) {
height: 56px;
padding: margins(7px, 0px, 24px, 0px);
}
statisticsRecentPostShareIcon: icon {{ "menu/forward", windowSubTextFg }};
statisticsRecentPostReactionIcon: icon {{ "menu/group_reactions", windowSubTextFg }};
statisticsShowMoreButton: SettingsButton(defaultSettingsButton) {
textFg: lightButtonFg;