diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp index 21b1213079..d4c73423ad 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp @@ -320,6 +320,22 @@ QString formatDateTime(const QDateTime &date) { return datePart + getLocalizedAt() + timePart; } +QString formatMessageTime(const QTime &time) { + const auto &settings = AyuSettings::getInstance(); + + const auto format = + settings.showMessageSeconds + ? (QLocale().timeFormat(QLocale::ShortFormat).contains("AP") + ? "h:mm:ss AP" + : "HH:mm:ss") + : QLocale().timeFormat(QLocale::ShortFormat); + + return QLocale().toString( + time, + format + ); +} + int getMediaSizeBytes(not_null message) { if (!message->media()) { return -1; diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h index 9c000466c0..7c48d181a2 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.h +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.h @@ -37,6 +37,7 @@ void readHistory(not_null message); QString formatTTL(int time); QString formatDateTime(const QDateTime &date); +QString formatMessageTime(const QTime &time); QString getDCName(int dc); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 4bc8eb5b6a..8267fc32be 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -1330,14 +1330,8 @@ void HistoryItem::setCommentsItemId(FullMsgId id) { void HistoryItem::setServiceText(PreparedServiceText &&prepared) { auto text = std::move(prepared.text); - const auto &settings = AyuSettings::getInstance(); if (date() > 0) { - const auto timeString = QString(" (%1)").arg(QLocale().toString( - base::unixtime::parse(_date), - settings.showMessageSeconds - ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") - : QLocale::system().timeFormat(QLocale::ShortFormat) - )); + const auto timeString = QString(" (%1)").arg(formatMessageTime(base::unixtime::parse(_date).time())); if (!text.text.isEmpty() && !text.text.contains(timeString)) { text = text.append(timeString); } diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index 186c99e3d0..8c489d4c6d 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ayu_settings.h" #include "ayu/features/messageshot/message_shot.h" +#include "ayu/utils/telegram_helpers.h" #include "core/ui_integration.h" #include "styles/style_ayu_icons.h" @@ -428,12 +429,7 @@ void BottomInfo::layoutDateText() { : QString(); const auto author = _data.author; const auto prefix = !author.isEmpty() ? u", "_q : QString(); - const auto date = edited + QLocale().toString( - _data.date.time(), - settings.showMessageSeconds - ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") - : QLocale::system().timeFormat(QLocale::ShortFormat) - ); + const auto date = edited + formatMessageTime(_data.date.time()); const auto afterAuthor = prefix + date; const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor); const auto authorWidth = st::msgDateFont->width(author); @@ -494,12 +490,9 @@ void BottomInfo::layoutDateText() { const auto author = _data.author; const auto prefix = !author.isEmpty() ? (_data.flags & Data::Flag::Edited ? u" "_q : u", "_q) : QString(); - const auto date = TextWithEntities{}.append(edited).append(QLocale().toString( - _data.date.time(), - settings.showMessageSeconds - ? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t") - : QLocale::system().timeFormat(QLocale::ShortFormat) - )); + const auto date = TextWithEntities{} + .append(edited) + .append(formatMessageTime(_data.date.time())); const auto afterAuthor = TextWithEntities{}.append(prefix).append(date); const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor.text);