From 4824b26afd423f693d6205389a2e92008f6fd3d7 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 5 Oct 2022 19:06:01 +0300 Subject: [PATCH] Added tooltip with forwards count to views info for channel messages. --- Telegram/Resources/langs/lang.strings | 4 +++ .../history/history_item_components.h | 1 + .../SourceFiles/history/history_message.cpp | 9 ++++++ .../history/view/history_view_bottom_info.cpp | 32 +++++++++++++++++++ .../history/view/history_view_bottom_info.h | 1 + .../history/view/history_view_message.cpp | 3 +- .../media/history_view_extended_preview.cpp | 3 +- .../history/view/media/history_view_gif.cpp | 3 +- .../view/media/history_view_location.cpp | 3 +- .../view/media/history_view_media_grouped.cpp | 3 +- .../media/history_view_media_unwrapped.cpp | 3 +- .../history/view/media/history_view_photo.cpp | 3 +- 12 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f4399e84fa..cab0d6a7e3 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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"; diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 0a3a8272a4..2d9b714390 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -62,6 +62,7 @@ struct HistoryMessageViews : public RuntimeComponent { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index cf6d6457b8..63c5150616 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1585,6 +1585,15 @@ bool HistoryMessage::changeViewsCount(int count) { } void HistoryMessage::setForwardsCount(int count) { + const auto views = Get(); + if (!views + || views->forwardsCount == count + || (count >= 0 && views->forwardsCount > count)) { + return; + } + + views->forwardsCount = count; + history()->owner().notifyItemDataChange(this); } void HistoryMessage::setPostAuthor(const QString &author) { diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index 1211d83d76..ff00b2c45e 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -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) { 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; diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.h b/Telegram/SourceFiles/history/view/history_view_bottom_info.h index 6e8d2117f7..b0d28c2a13 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.h +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.h @@ -55,6 +55,7 @@ public: std::vector reactions; std::optional views; std::optional replies; + std::optional forwardsCount; Flags flags; }; BottomInfo(not_null<::Data::Reactions*> reactionsOwner, Data &&data); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 1c3ff4faa0..8e9d9c749e 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -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; } }; diff --git a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp index 73463ed96a..5710ecafc1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp @@ -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()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 219e4ac84f..18c7d9df9d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -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; } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index cd49e09ebd..e710b09a4e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -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()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index aaa16181f8..6bac66bcf4 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -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()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index ccd07c1d8c..e6a7fda77a 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -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) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 4c52695fd4..fe0aaf432d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -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()) {