From baa53cafd80667be889e889fa2e9c960dd60b35b Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 19 Jun 2026 12:20:36 +0400 Subject: [PATCH] Support alternative edited-on date display. --- Telegram/Resources/langs/lang.strings | 3 ++ .../history/view/history_view_bottom_info.cpp | 30 +++++++++++++++++-- .../history/view/history_view_bottom_info.h | 2 ++ .../view/history_view_context_menu.cpp | 23 ++++++++++++-- Telegram/SourceFiles/main/main_session.cpp | 4 +++ Telegram/SourceFiles/main/main_session.h | 4 +++ 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f1d4e37ba4..cc406729e4 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2897,6 +2897,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_repeated_yearly" = "yearly"; "lng_edited_date" = "Edited: {date}"; "lng_sent_date" = "Sent: {date}"; +"lng_edited_at" = "edited at {time}"; +"lng_edited_on" = "edited on {date} at {time}"; +"lng_sent_on" = "sent on {date} at {time}"; "lng_approximate_about" = "Estimated date of video publishing."; "lng_views_tooltip#one" = "Views: {count}"; "lng_views_tooltip#other" = "Views: {count}"; diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index fe1996d6bb..12101bf4c8 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -69,6 +69,20 @@ namespace { return map.back().text; } +[[nodiscard]] QString FormatEditedDate(QDateTime sent, QDateTime edited) { + const auto today = QDateTime::currentDateTime().date(); + const auto time = QLocale().toString(edited.time(), QLocale::ShortFormat); + if (sent.date() == today && edited.date() == today) { + return tr::lng_edited_at(tr::now, lt_time, time); + } + return tr::lng_edited_on( + tr::now, + lt_date, + langDayOfMonthShort(edited.date()), + lt_time, + time); +} + } // namespace struct BottomInfo::Effect { @@ -458,7 +472,11 @@ void BottomInfo::layout() { } void BottomInfo::layoutDateText() { - const auto edited = (_data.flags & Data::Flag::Edited) + const auto editedPrimary = (_data.flags & Data::Flag::EditedPrimary) + && !(_data.flags & Data::Flag::ForwardedDate); + const auto edited = editedPrimary + ? QString() + : (_data.flags & Data::Flag::Edited) ? (tr::lng_edited(tr::now) + ' ') : (_data.flags & Data::Flag::EstimateDate) ? (tr::lng_approximate(tr::now) + ' ') @@ -467,7 +485,9 @@ void BottomInfo::layoutDateText() { : QString(); const auto author = _data.author; const auto prefix = !author.isEmpty() ? u", "_q : QString(); - const auto date = edited + ((_data.flags & Data::Flag::ForwardedDate) + const auto date = editedPrimary + ? FormatEditedDate(_data.date, _data.editedDate) + : edited + ((_data.flags & Data::Flag::ForwardedDate) ? Ui::FormatDateTimeSavedFrom(_data.date) : QLocale().toString(_data.date.time(), QLocale::ShortFormat)); const auto afterAuthor = prefix + date; @@ -650,8 +670,12 @@ BottomInfo::Data BottomInfoDataFromMessage(not_null message) { } } } - if (message->displayedEditDate()) { + if (const auto editedDate = message->displayedEditDate()) { result.flags |= Flag::Edited; + if (item->history()->session().messagePrimaryEditedDate()) { + result.flags |= Flag::EditedPrimary; + result.editedDate = base::unixtime::parse(editedDate); + } } if (const auto views = item->Get()) { if (views->views.count >= 0) { diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.h b/Telegram/SourceFiles/history/view/history_view_bottom_info.h index 91a1d434b2..ff7f68ed19 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.h +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.h @@ -44,12 +44,14 @@ public: EstimateDate = 0x100, ForwardedDate = 0x200, Silent = 0x400, + EditedPrimary = 0x800, //Unread, // We don't want to pass and update it in Date for now. }; friend inline constexpr bool is_flag_type(Flag) { return true; }; using Flags = base::flags; QDateTime date; + QDateTime editedDate; QString author; EffectId effectId = 0; int64 tonStake = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 7fb4cb8290..092fd789cd 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -2048,9 +2048,26 @@ void AddWhenEditedForwardedAuthorActionHelper( if (insertSeparator && !menu->empty()) { menu->addSeparator(&st::expandedMenuSeparator); } - menu->addAction(Ui::WhenReadContextAction( - menu.get(), - Api::WhenEdited(item->from(), edited->date))); + if (item->history()->session().messagePrimaryEditedDate()) { + const auto sent = base::unixtime::parse(item->date()); + auto label = base::make_unique_q( + menu->menu(), + menu->st().menu, + st::historyHasCustomEmoji, + st::historyHasCustomEmojiPosition, + tr::marked(tr::lng_sent_on( + tr::now, + lt_date, + langDayOfMonthShort(sent.date()), + lt_time, + QLocale().toString(sent.time(), QLocale::ShortFormat)))); + label->setAttribute(Qt::WA_TransparentForMouseEvents); + menu->addAction(std::move(label)); + } else { + menu->addAction(Ui::WhenReadContextAction( + menu.get(), + Api::WhenEdited(item->from(), edited->date))); + } } } if (item->canLookupMessageAuthor()) { diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index cedcddfd13..c73f3c7dc0 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -278,6 +278,10 @@ void Session::appConfigRefreshed() { u"premium_purchase_blocked"_q, true); #endif // OS_MAC_STORE + + _messagePrimaryEditedDate = config.get( + u"message_primary_edited_date"_q, + false); } void Session::setTmpPassword(const QByteArray &password, TimeId validUntil) { diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index f1f3a0eee1..eadc0f6f22 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -120,6 +120,9 @@ public: [[nodiscard]] Storage::Domain &domainLocal() const; [[nodiscard]] AppConfig &appConfig() const; + [[nodiscard]] bool messagePrimaryEditedDate() const { + return _messagePrimaryEditedDate; + } [[nodiscard]] bool premium() const; [[nodiscard]] bool premiumPossible() const; @@ -341,6 +344,7 @@ private: std::shared_ptr _selfUserpicView; rpl::variable _premiumPossible = false; + bool _messagePrimaryEditedDate = false; rpl::event_stream _termsLockChanges; std::unique_ptr _termsLock;