Added tooltip with forwards count to views info for channel messages.

This commit is contained in:
23rd 2022-10-05 19:06:01 +03:00 committed by John Preston
parent 5751d29c47
commit 4824b26afd
12 changed files with 61 additions and 7 deletions

View File

@ -1647,6 +1647,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_edited" = "edited";
"lng_edited_date" = "Edited: {date}";
"lng_sent_date" = "Sent: {date}";
"lng_views_tooltip#one" = "Views: {count}";
"lng_views_tooltip#other" = "Views: {count}";
"lng_forwards_tooltip#one" = "Forwards: {count}";
"lng_forwards_tooltip#other" = "Forwards: {count}";
"lng_imported" = "imported";
"lng_admin_badge" = "admin";
"lng_owner_badge" = "owner";

View File

@ -62,6 +62,7 @@ struct HistoryMessageViews : public RuntimeComponent<HistoryMessageViews, Histor
MsgId commentsRootId = 0;
MsgId commentsInboxReadTillId = 0;
MsgId commentsMaxId = 0;
int forwardsCount = 0;
};
struct HistoryMessageSigned : public RuntimeComponent<HistoryMessageSigned, HistoryItem> {

View File

@ -1585,6 +1585,15 @@ bool HistoryMessage::changeViewsCount(int count) {
}
void HistoryMessage::setForwardsCount(int count) {
const auto views = Get<HistoryMessageViews>();
if (!views
|| views->forwardsCount == count
|| (count >= 0 && views->forwardsCount > count)) {
return;
}
views->forwardsCount = count;
history()->owner().notifyItemDataChange(this);
}
void HistoryMessage::setPostAuthor(const QString &author) {

View File

@ -131,6 +131,35 @@ TextState BottomInfo::textState(
if (_data.flags & (Data::Flag::OutLayout | Data::Flag::Sending)) {
withTicksWidth += st::historySendStateSpace;
}
if (!_views.isEmpty()) {
const auto viewsWidth = _views.maxWidth();
const auto right = width()
- withTicksWidth
- ((_data.flags & Data::Flag::Pinned) ? st::historyPinWidth : 0)
- st::historyViewsSpace
- st::historyViewsWidth
- viewsWidth;
const auto inViews = QRect(
right,
0,
withTicksWidth + st::historyViewsWidth,
st::msgDateFont->height
).contains(position);
if (inViews) {
result.customTooltip = true;
const auto fullViews = tr::lng_views_tooltip(
tr::now,
lt_count_decimal,
*_data.views);
const auto fullForwards = _data.forwardsCount
? ('\n' + tr::lng_forwards_tooltip(
tr::now,
lt_count_decimal,
*_data.forwardsCount))
: QString();
result.customTooltipText = fullViews + fullForwards;
}
}
const auto inTime = QRect(
width() - withTicksWidth,
0,
@ -637,6 +666,9 @@ BottomInfo::Data BottomInfoDataFromMessage(not_null<Message*> message) {
if (views->replies.count >= 0 && !views->commentsMegagroupId) {
result.replies = views->replies.count;
}
if (views->forwardsCount > 0) {
result.forwardsCount = views->forwardsCount;
}
}
if (item->isSending() || item->hasFailed()) {
result.flags |= Flag::Sending;

View File

@ -55,6 +55,7 @@ public:
std::vector<MessageReaction> reactions;
std::optional<int> views;
std::optional<int> replies;
std::optional<int> forwardsCount;
Flags flags;
};
BottomInfo(not_null<::Data::Reactions*> reactionsOwner, Data &&data);

View File

@ -1723,7 +1723,8 @@ TextState Message::textState(
point,
InfoDisplayType::Default);
if (bottomInfoResult.link
|| bottomInfoResult.cursor != CursorState::None) {
|| bottomInfoResult.cursor != CursorState::None
|| bottomInfoResult.customTooltip) {
result = bottomInfoResult;
}
};

View File

@ -387,7 +387,8 @@ TextState ExtendedPreview::textState(QPoint point, StateRequest request) const {
point,
InfoDisplayType::Image);
if (bottomInfoResult.link
|| bottomInfoResult.cursor != CursorState::None) {
|| bottomInfoResult.cursor != CursorState::None
|| bottomInfoResult.customTooltip) {
return bottomInfoResult;
}
if (const auto size = bubble ? std::nullopt : _parent->rightActionSize()) {

View File

@ -961,7 +961,8 @@ TextState Gif::textState(QPoint point, StateRequest request) const {
? InfoDisplayType::Background
: InfoDisplayType::Image));
if (bottomInfoResult.link
|| bottomInfoResult.cursor != CursorState::None) {
|| bottomInfoResult.cursor != CursorState::None
|| bottomInfoResult.customTooltip) {
return bottomInfoResult;
}
}

View File

@ -328,7 +328,8 @@ TextState Location::textState(QPoint point, StateRequest request) const {
point,
InfoDisplayType::Image);
if (bottomInfoResult.link
|| bottomInfoResult.cursor != CursorState::None) {
|| bottomInfoResult.cursor != CursorState::None
|| bottomInfoResult.customTooltip) {
return bottomInfoResult;
}
if (const auto size = bubble ? std::nullopt : _parent->rightActionSize()) {

View File

@ -453,7 +453,8 @@ TextState GroupedMedia::textState(QPoint point, StateRequest request) const {
point,
InfoDisplayType::Image);
if (bottomInfoResult.link
|| bottomInfoResult.cursor != CursorState::None) {
|| bottomInfoResult.cursor != CursorState::None
|| bottomInfoResult.customTooltip) {
return bottomInfoResult;
}
if (const auto size = _parent->hasBubble() ? std::nullopt : _parent->rightActionSize()) {

View File

@ -389,7 +389,8 @@ TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const {
point,
InfoDisplayType::Background);
if (bottomInfoResult.link
|| bottomInfoResult.cursor != CursorState::None) {
|| bottomInfoResult.cursor != CursorState::None
|| bottomInfoResult.customTooltip) {
return bottomInfoResult;
}
if (rightActionSize) {

View File

@ -523,7 +523,8 @@ TextState Photo::textState(QPoint point, StateRequest request) const {
point,
InfoDisplayType::Image);
if (bottomInfoResult.link
|| bottomInfoResult.cursor != CursorState::None) {
|| bottomInfoResult.cursor != CursorState::None
|| bottomInfoResult.customTooltip) {
return bottomInfoResult;
}
if (const auto size = bubble ? std::nullopt : _parent->rightActionSize()) {