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;
}
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) {
if (!message->media()) {
return -1;

View file

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

View file

@ -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);
}

View file

@ -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);