fix: message seconds on linux

This commit is contained in:
AlexeyZavar 2025-07-15 21:06:09 +03:00
parent 72618f98d1
commit 7a37ab1b25
4 changed files with 23 additions and 19 deletions

View file

@ -320,6 +320,22 @@ QString formatDateTime(const QDateTime &date) {
return datePart + getLocalizedAt() + timePart; 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<HistoryItem*> message) { int getMediaSizeBytes(not_null<HistoryItem*> message) {
if (!message->media()) { if (!message->media()) {
return -1; return -1;

View file

@ -37,6 +37,7 @@ void readHistory(not_null<HistoryItem*> message);
QString formatTTL(int time); QString formatTTL(int time);
QString formatDateTime(const QDateTime &date); QString formatDateTime(const QDateTime &date);
QString formatMessageTime(const QTime &time);
QString getDCName(int dc); QString getDCName(int dc);

View file

@ -1330,14 +1330,8 @@ void HistoryItem::setCommentsItemId(FullMsgId id) {
void HistoryItem::setServiceText(PreparedServiceText &&prepared) { void HistoryItem::setServiceText(PreparedServiceText &&prepared) {
auto text = std::move(prepared.text); auto text = std::move(prepared.text);
const auto &settings = AyuSettings::getInstance();
if (date() > 0) { if (date() > 0) {
const auto timeString = QString(" (%1)").arg(QLocale().toString( const auto timeString = QString(" (%1)").arg(formatMessageTime(base::unixtime::parse(_date).time()));
base::unixtime::parse(_date),
settings.showMessageSeconds
? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t")
: QLocale::system().timeFormat(QLocale::ShortFormat)
));
if (!text.text.isEmpty() && !text.text.contains(timeString)) { if (!text.text.isEmpty() && !text.text.contains(timeString)) {
text = text.append(timeString); text = text.append(timeString);
} }

View file

@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// AyuGram includes // AyuGram includes
#include "ayu/ayu_settings.h" #include "ayu/ayu_settings.h"
#include "ayu/features/messageshot/message_shot.h" #include "ayu/features/messageshot/message_shot.h"
#include "ayu/utils/telegram_helpers.h"
#include "core/ui_integration.h" #include "core/ui_integration.h"
#include "styles/style_ayu_icons.h" #include "styles/style_ayu_icons.h"
@ -428,12 +429,7 @@ void BottomInfo::layoutDateText() {
: QString(); : QString();
const auto author = _data.author; const auto author = _data.author;
const auto prefix = !author.isEmpty() ? u", "_q : QString(); const auto prefix = !author.isEmpty() ? u", "_q : QString();
const auto date = edited + QLocale().toString( const auto date = edited + formatMessageTime(_data.date.time());
_data.date.time(),
settings.showMessageSeconds
? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t")
: QLocale::system().timeFormat(QLocale::ShortFormat)
);
const auto afterAuthor = prefix + date; const auto afterAuthor = prefix + date;
const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor); const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor);
const auto authorWidth = st::msgDateFont->width(author); const auto authorWidth = st::msgDateFont->width(author);
@ -494,12 +490,9 @@ void BottomInfo::layoutDateText() {
const auto author = _data.author; const auto author = _data.author;
const auto prefix = !author.isEmpty() ? (_data.flags & Data::Flag::Edited ? u" "_q : u", "_q) : QString(); const auto prefix = !author.isEmpty() ? (_data.flags & Data::Flag::Edited ? u" "_q : u", "_q) : QString();
const auto date = TextWithEntities{}.append(edited).append(QLocale().toString( const auto date = TextWithEntities{}
_data.date.time(), .append(edited)
settings.showMessageSeconds .append(formatMessageTime(_data.date.time()));
? QLocale::system().timeFormat(QLocale::LongFormat).remove(" t")
: QLocale::system().timeFormat(QLocale::ShortFormat)
));
const auto afterAuthor = TextWithEntities{}.append(prefix).append(date); const auto afterAuthor = TextWithEntities{}.append(prefix).append(date);
const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor.text); const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor.text);