From 7b55777eb0c00ea3a9649054df593aad7dc45a84 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sun, 11 Sep 2022 05:08:19 +0300 Subject: [PATCH] [Improvement] Show time of service messages --- .../SourceFiles/data/data_replies_list.cpp | 6 ++++- .../admin_log/history_admin_log_item.cpp | 22 +++++++++------- Telegram/SourceFiles/history/history_item.cpp | 2 +- .../SourceFiles/history/history_service.cpp | 26 ++++++++++++++++--- .../SourceFiles/history/history_service.h | 12 ++++++++- 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index b0391e0e6..25b8b4229 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -32,7 +32,10 @@ constexpr auto kMessagesPerPage = 50; history->nextNonHistoryEntryId(), MessageFlag::FakeHistoryItem, date, - HistoryService::PreparedText{ { .text = text } }); + HistoryService::PreparedText{ { .text = text } }, + PeerId(0), + nullptr, + false); } } // namespace @@ -287,6 +290,7 @@ void RepliesList::injectRootDivider( text()); } else if (_dividerWithComments != withComments) { _dividerWithComments = withComments; + _divider->setNeedTime(false); _divider->setServiceText(HistoryService::PreparedText{ { text() } }); } slice->ids.push_back(_divider->fullId()); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index 5ee9df794..3aa1cf0f8 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -700,10 +700,11 @@ void GenerateItems( const auto fromLink = from->createOpenLink(); const auto fromLinkText = Ui::Text::Link(fromName, QString()); - const auto addSimpleServiceMessage = [&]( + auto addSimpleServiceMessage = [&]( const TextWithEntities &text, - PhotoData *photo = nullptr) { - auto message = HistoryService::PreparedText{ text }; + PhotoData *photo = nullptr, + bool showTime = true) { + auto message = HistoryService::PreparedText { text }; message.links.push_back(fromLink); addPart(history->makeServiceMessage( history->nextNonHistoryEntryId(), @@ -711,7 +712,8 @@ void GenerateItems( date, message, peerToUser(from->id), - photo)); + photo, + showTime)); }; const auto createChangeTitle = [&](const LogTitle &action) { @@ -762,7 +764,7 @@ void GenerateItems( ? tr::lng_admin_log_removed_description_channel : tr::lng_admin_log_changed_description_channel) )(tr::now, lt_from, fromLinkText, Ui::Text::WithEntities); - addSimpleServiceMessage(text); + addSimpleServiceMessage(text, nullptr, false); const auto body = makeSimpleTextMessage( PrepareText(newValue, QString())); @@ -787,7 +789,7 @@ void GenerateItems( ? tr::lng_admin_log_removed_link_channel : tr::lng_admin_log_changed_link_channel) )(tr::now, lt_from, fromLinkText, Ui::Text::WithEntities); - addSimpleServiceMessage(text); + addSimpleServiceMessage(text, nullptr, false); const auto body = makeSimpleTextMessage(newValue.isEmpty() ? TextWithEntities() @@ -863,7 +865,7 @@ void GenerateItems( lt_from, fromLinkText, Ui::Text::WithEntities); - addSimpleServiceMessage(text); + addSimpleServiceMessage(text, nullptr, false); const auto detachExistingItem = false; addPart( @@ -898,7 +900,7 @@ void GenerateItems( lt_from, fromLinkText, Ui::Text::WithEntities); - addSimpleServiceMessage(text); + addSimpleServiceMessage(text, nullptr, false); auto oldValue = ExtractEditedText( session, @@ -930,7 +932,7 @@ void GenerateItems( lt_from, fromLinkText, Ui::Text::WithEntities); - addSimpleServiceMessage(text); + addSimpleServiceMessage(text, nullptr, false); const auto detachExistingItem = false; addPart( @@ -1063,7 +1065,7 @@ void GenerateItems( lt_from, fromLinkText, Ui::Text::WithEntities); - addSimpleServiceMessage(text); + addSimpleServiceMessage(text, nullptr, false); const auto detachExistingItem = false; addPart( diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 844414f4b..9bf9ea42b 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -1226,7 +1226,7 @@ bool HistoryItem::isEmpty() const { TextWithEntities HistoryItem::notificationText() const { const auto result = [&] { - if (_media && !isService()) { + if (_media/* && !isService()*/) { return _media->notificationText(); } else if (!emptyText()) { return _text.toTextWithEntities(); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index e01370657..401100b92 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -41,13 +41,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "ui/text/text_options.h" #include "ui/text/text_utilities.h" +#include "ui/text/text_entity.h" +#include "base/unixtime.h" namespace { +constexpr auto kNotificationTextLimit = 255; constexpr auto kPinnedMessageTextLimit = 16; using ItemPreview = HistoryView::ItemPreview; +QString GenerateServiceTime(TimeId date) { + if (date > 0) { + return qs(" ยท ") + base::unixtime::parse(date).toString(cTimeFormat()); + } + return QString(); +} + [[nodiscard]] bool PeerCallKnown(not_null peer) { if (peer->groupCall() != nullptr) { return true; @@ -105,6 +115,7 @@ using ItemPreview = HistoryView::ItemPreview; } // namespace void HistoryService::setMessageByAction(const MTPmessageAction &action) { + setNeedTime(true); auto prepareChatAddUserText = [this](const MTPDmessageActionChatAddUser &action) { auto result = PreparedText{}; auto &users = action.vusers().v; @@ -1160,8 +1171,10 @@ HistoryService::HistoryService( TimeId date, const PreparedText &message, PeerId from, - PhotoData *photo) + PhotoData *photo, + bool showTime) : HistoryItem(history, id, flags, date, from) { + setNeedTime(showTime); setServiceText(message); if (photo) { _media = std::make_unique( @@ -1194,7 +1207,7 @@ ItemPreview HistoryService::toPreview(ToPreviewOptions options) const { } TextWithEntities HistoryService::inReplyText() const { - auto result = HistoryService::notificationText(); + auto result = TextWithEntities{ notificationText() }; const auto &name = author()->name; TextUtilities::Trim(result); if (result.text.startsWith(name)) { @@ -1219,9 +1232,16 @@ ClickHandlerPtr HistoryService::fromLink() const { } void HistoryService::setServiceText(const PreparedText &prepared) { + auto preparedText = prepared.text; _text.setMarkedText( st::serviceTextStyle, - prepared.text, + (needTime() && !prepared.text.empty() + ? preparedText.append(GenerateServiceTime(date())) + : preparedText), + Ui::ItemTextServiceOptions()); + _cleanText.setText( + st::serviceTextStyle, + prepared.text.text, Ui::ItemTextServiceOptions()); HistoryView::FillTextWithAnimatedSpoilers(_text); auto linkIndex = 0; diff --git a/Telegram/SourceFiles/history/history_service.h b/Telegram/SourceFiles/history/history_service.h index 09278b230..c0f6191ec 100644 --- a/Telegram/SourceFiles/history/history_service.h +++ b/Telegram/SourceFiles/history/history_service.h @@ -84,7 +84,8 @@ public: TimeId date, const PreparedText &message, PeerId from = 0, - PhotoData *photo = nullptr); + PhotoData *photo = nullptr, + bool showTime = true); bool updateDependencyItem() override; MsgId dependencyMsgId() const override { @@ -119,6 +120,13 @@ public: HistoryView::Element *replacing = nullptr) override; void setServiceText(const PreparedText &prepared); + void setNeedTime(bool need) { + _needTime = need; + }; + + bool needTime() { + return _needTime; + }; void hideSpoilers() override; @@ -172,6 +180,8 @@ private: friend class HistoryView::Service; + Ui::Text::String _cleanText; + bool _needTime = true; }; [[nodiscard]] not_null GenerateJoinedMessage(