2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-02 07:25:46 +00:00

Moved formatting of dialog last date to td_ui.

This commit is contained in:
23rd
2024-05-02 01:44:52 +03:00
parent 47800ee02d
commit 26e8c29f40
3 changed files with 24 additions and 27 deletions

View File

@@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_window.h"
#include "storage/localstorage.h"
#include "ui/empty_userpic.h"
#include "ui/text/format_values.h"
#include "ui/text/text_options.h"
#include "ui/text/text_utilities.h"
#include "ui/unread_badge.h"
@@ -44,8 +45,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Dialogs::Ui {
namespace {
// Show all dates that are in the last 20 hours in time format.
constexpr int kRecentlyInSeconds = 20 * 3600;
const auto kPsaBadgePrefix = "cloud_lng_badge_psa_";
[[nodiscard]] bool ShowUserBotIcon(not_null<UserData*> user) {
@@ -81,29 +80,6 @@ void PaintRowTopRight(
text);
}
void PaintRowDate(
QPainter &p,
QDateTime date,
QRect &rectForName,
const PaintContext &context) {
const auto now = QDateTime::currentDateTime();
const auto &lastTime = date;
const auto nowDate = now.date();
const auto lastDate = lastTime.date();
const auto dt = [&] {
if ((lastDate == nowDate)
|| (qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds)) {
return QLocale().toString(lastTime.time(), QLocale::ShortFormat);
} else if (qAbs(lastDate.daysTo(nowDate)) < 7) {
return langDayOfWeek(lastDate);
} else {
return QLocale().toString(lastDate, QLocale::ShortFormat);
}
}();
PaintRowTopRight(p, dt, rectForName, context);
}
int PaintBadges(
QPainter &p,
const PaintContext &context,
@@ -444,7 +420,8 @@ void PaintRow(
|| (supportMode
&& entry->session().supportHelper().isOccupiedBySomeone(history))) {
if (!promoted) {
PaintRowDate(p, date, rectForName, context);
const auto dateString = Ui::FormatDialogsDate(date);
PaintRowTopRight(p, dateString, rectForName, context);
}
auto availableWidth = namewidth;
@@ -566,7 +543,8 @@ void PaintRow(
}
} else if (!item->isEmpty()) {
if ((thread || sublist) && !promoted) {
PaintRowDate(p, date, rectForName, context);
const auto dateString = Ui::FormatDialogsDate(date);
PaintRowTopRight(p, dateString, rectForName, context);
}
paintItemCallback(nameleft, namewidth);