1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-04-22 06:02:03 +02:00

Smartlist: Date should show in correct locale format

- Standard time/date is now used
- If today, show local time, otherwise show local date

GitLab: #545
Change-Id: I07f1e706868c725d1c917c473dc0fdbad8d6810f
This commit is contained in:
Nicolas Vengeon 2023-02-02 14:52:58 -05:00 committed by Sébastien Blin
parent 530c027068
commit 6348d3ee0b
7 changed files with 33 additions and 31 deletions

View file

@ -110,13 +110,6 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
} }
break; break;
} }
case Role::LastInteractionDate: {
if (!item.interactions->empty()) {
return QVariant(
Utils::formatTimeString(item.interactions->at(item.lastMessageUid).timestamp));
}
break;
}
case Role::LastInteraction: { case Role::LastInteraction: {
if (!item.interactions->empty()) { if (!item.interactions->empty()) {
auto interaction = item.interactions->at(item.lastMessageUid); auto interaction = item.interactions->at(item.lastMessageUid);
@ -190,7 +183,8 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
case Role::IsBanned: case Role::IsBanned:
return QVariant(false); return QVariant(false);
case Role::ContactType: case Role::ContactType:
return QVariant(static_cast<int>(lrcInstance_->getCurrentAccountInfo().profileInfo.type)); return QVariant(
static_cast<int>(lrcInstance_->getCurrentAccountInfo().profileInfo.type));
} }
} }
ContactModel* contactModel; ContactModel* contactModel;

View file

@ -31,7 +31,6 @@
X(URI) \ X(URI) \
X(UnreadMessagesCount) \ X(UnreadMessagesCount) \
X(LastInteractionTimeStamp) \ X(LastInteractionTimeStamp) \
X(LastInteractionDate) \
X(LastInteraction) \ X(LastInteraction) \
X(ContactType) \ X(ContactType) \
X(IsSwarm) \ X(IsSwarm) \

View file

@ -40,6 +40,11 @@ ItemDelegate {
highlighted: ListView.isCurrentItem highlighted: ListView.isCurrentItem
property bool interactive: true property bool interactive: true
property string lastInteractionDate: LastInteractionTimeStamp === undefined
? ""
: LastInteractionTimeStamp
property string lastInteractionFormattedDate: MessagesAdapter.getBestFormattedDate(lastInteractionDate)
onVisibleChanged: { onVisibleChanged: {
if (visible) if (visible)
@ -47,6 +52,13 @@ ItemDelegate {
UtilsAdapter.clearInteractionsCache(root.accountId, root.convId) UtilsAdapter.clearInteractionsCache(root.accountId, root.convId)
} }
Connections {
target: MessagesAdapter
function onTimestampUpdated() {
lastInteractionFormattedDate = MessagesAdapter.getBestFormattedDate(lastInteractionDate)
}
}
Component.onCompleted: { Component.onCompleted: {
// Store to avoid undefined at the end // Store to avoid undefined at the end
root.accountId = CurrentAccount.id root.accountId = CurrentAccount.id
@ -131,7 +143,7 @@ ItemDelegate {
RowLayout { RowLayout {
visible: ContactType !== Profile.Type.TEMPORARY visible: ContactType !== Profile.Type.TEMPORARY
&& !IsBanned && !IsBanned
&& LastInteractionDate !== undefined && lastInteractionFormattedDate !== undefined
&& interactive && interactive
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: 20 Layout.minimumHeight: 20
@ -140,7 +152,7 @@ ItemDelegate {
// last Interaction date // last Interaction date
Text { Text {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
text: LastInteractionDate === undefined ? "" : LastInteractionDate text: lastInteractionFormattedDate === undefined ? "" : lastInteractionFormattedDate
textFormat: TextEdit.PlainText textFormat: TextEdit.PlainText
font.pointSize: JamiTheme.smartlistItemInfoFontSize font.pointSize: JamiTheme.smartlistItemInfoFontSize
font.weight: UnreadMessagesCount ? Font.DemiBold : Font.Normal font.weight: UnreadMessagesCount ? Font.DemiBold : Font.Normal

View file

@ -695,8 +695,8 @@ MessagesAdapter::isRemoteImage(const QString& msg)
QString QString
MessagesAdapter::getFormattedTime(const quint64 timestamp) MessagesAdapter::getFormattedTime(const quint64 timestamp)
{ {
const auto now = QDateTime::currentDateTime(); const auto currentTime = QDateTime::currentDateTime();
const auto seconds = now.toSecsSinceEpoch() - timestamp; const auto seconds = currentTime.toSecsSinceEpoch() - timestamp;
auto interval = qFloor(seconds / 60); auto interval = qFloor(seconds / 60);
if (interval > 1) { if (interval > 1) {
@ -714,14 +714,24 @@ MessagesAdapter::getFormattedTime(const quint64 timestamp)
return QObject::tr("just now"); return QObject::tr("just now");
} }
QString
MessagesAdapter::getBestFormattedDate(const quint64 timestamp)
{
auto currentDate = QDate::currentDate();
auto timestampDate = QDateTime::fromSecsSinceEpoch(timestamp).date();
if (timestampDate == currentDate)
return getFormattedTime(timestamp);
return getFormattedDay(timestamp);
}
QString QString
MessagesAdapter::getFormattedDay(const quint64 timestamp) MessagesAdapter::getFormattedDay(const quint64 timestamp)
{ {
auto now = QDate::currentDate(); auto currentDate = QDate::currentDate();
auto before = QDateTime::fromSecsSinceEpoch(timestamp).date(); auto timestampDate = QDateTime::fromSecsSinceEpoch(timestamp).date();
if (before == now) if (timestampDate == currentDate)
return QObject::tr("Today"); return QObject::tr("Today");
if (before.daysTo(now) == 1) if (timestampDate.daysTo(currentDate) == 1)
return QObject::tr("Yesterday"); return QObject::tr("Yesterday");
auto curLang = settingsManager_->getValue(Settings::Key::LANG); auto curLang = settingsManager_->getValue(Settings::Key::LANG);

View file

@ -123,6 +123,7 @@ protected:
Q_INVOKABLE bool isRemoteImage(const QString& msg); Q_INVOKABLE bool isRemoteImage(const QString& msg);
Q_INVOKABLE QString getFormattedDay(const quint64 timestamp); Q_INVOKABLE QString getFormattedDay(const quint64 timestamp);
Q_INVOKABLE QString getFormattedTime(const quint64 timestamp); Q_INVOKABLE QString getFormattedTime(const quint64 timestamp);
Q_INVOKABLE QString getBestFormattedDate(const quint64 timestamp);
Q_INVOKABLE void parseMessageUrls(const QString& messageId, Q_INVOKABLE void parseMessageUrls(const QString& messageId,
const QString& msg, const QString& msg,
bool showPreview, bool showPreview,

View file

@ -596,19 +596,6 @@ Utils::profileType(const lrc::api::conversation::Info& conv,
} }
} }
QString
Utils::formatTimeString(const std::time_t& timeStamp)
{
auto currentTimeStamp = QDateTime::fromSecsSinceEpoch(timeStamp);
auto now = QDateTime::currentDateTime();
auto timeStampDMY = currentTimeStamp.toString("dd/MM/yy");
if (timeStampDMY == now.toString("dd/MM/yy")) {
return currentTimeStamp.toString("hh:mm");
} else {
return timeStampDMY;
}
}
bool bool
Utils::isInteractionGenerated(const lrc::api::interaction::Type& type) Utils::isInteractionGenerated(const lrc::api::interaction::Type& type)
{ {

View file

@ -75,7 +75,6 @@ void removeOldVersions();
// LRC helpers // LRC helpers
lrc::api::profile::Type profileType(const lrc::api::conversation::Info& conv, lrc::api::profile::Type profileType(const lrc::api::conversation::Info& conv,
const lrc::api::ConversationModel& model); const lrc::api::ConversationModel& model);
QString formatTimeString(const std::time_t& timeStamp);
bool isInteractionGenerated(const lrc::api::interaction::Type& interaction); bool isInteractionGenerated(const lrc::api::interaction::Type& interaction);
bool isContactValid(const QString& contactUid, const lrc::api::ConversationModel& model); bool isContactValid(const QString& contactUid, const lrc::api::ConversationModel& model);
bool getReplyMessageBox(QWidget* widget, const QString& title, const QString& text); bool getReplyMessageBox(QWidget* widget, const QString& title, const QString& text);