Support alternative edited-on date display.

This commit is contained in:
John Preston
2026-06-19 12:20:36 +04:00
parent 4fff6a1ff7
commit baa53cafd8
6 changed files with 60 additions and 6 deletions
+3
View File
@@ -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}";
@@ -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*> 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<HistoryMessageViews>()) {
if (views->views.count >= 0) {
@@ -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<Flag>;
QDateTime date;
QDateTime editedDate;
QString author;
EffectId effectId = 0;
int64 tonStake = 0;
@@ -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<Ui::Menu::MultilineAction>(
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()) {
@@ -278,6 +278,10 @@ void Session::appConfigRefreshed() {
u"premium_purchase_blocked"_q,
true);
#endif // OS_MAC_STORE
_messagePrimaryEditedDate = config.get<bool>(
u"message_primary_edited_date"_q,
false);
}
void Session::setTmpPassword(const QByteArray &password, TimeId validUntil) {
+4
View File
@@ -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<QImage> _selfUserpicView;
rpl::variable<bool> _premiumPossible = false;
bool _messagePrimaryEditedDate = false;
rpl::event_stream<bool> _termsLockChanges;
std::unique_ptr<Window::TermsLock> _termsLock;