mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Moved formatting of dialog last date to td_ui.
This commit is contained in:
parent
47800ee02d
commit
26e8c29f40
3 changed files with 24 additions and 27 deletions
|
@ -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);
|
||||
|
|
|
@ -484,4 +484,22 @@ QString FormatResetCloudPasswordIn(float64 sec) {
|
|||
return (sec >= 3600) ? FormatTTL(sec) : FormatDurationText(sec);
|
||||
}
|
||||
|
||||
QString FormatDialogsDate(const QDateTime &lastTime) {
|
||||
// Show all dates that are in the last 20 hours in time format.
|
||||
constexpr int kRecentlyInSeconds = 20 * 3600;
|
||||
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
const auto nowDate = now.date();
|
||||
const auto lastDate = lastTime.date();
|
||||
|
||||
if ((lastDate == nowDate)
|
||||
|| (std::abs(lastTime.secsTo(now)) < kRecentlyInSeconds)) {
|
||||
return QLocale().toString(lastTime.time(), QLocale::ShortFormat);
|
||||
} else if (std::abs(lastDate.daysTo(nowDate)) < 7) {
|
||||
return langDayOfWeek(lastDate);
|
||||
} else {
|
||||
return QLocale().toString(lastDate, QLocale::ShortFormat);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -31,6 +31,7 @@ inline constexpr auto FileStatusSizeFailed = 0xFFFFFFF2LL;
|
|||
[[nodiscard]] QString FormatMuteFor(float64 sec);
|
||||
[[nodiscard]] QString FormatMuteForTiny(float64 sec);
|
||||
[[nodiscard]] QString FormatResetCloudPasswordIn(float64 sec);
|
||||
[[nodiscard]] QString FormatDialogsDate(const QDateTime &lastTime);
|
||||
|
||||
struct CurrencyRule {
|
||||
const char *international = "";
|
||||
|
|
Loading…
Add table
Reference in a new issue