1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-04-21 21:52: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;
}
case Role::LastInteractionDate: {
if (!item.interactions->empty()) {
return QVariant(
Utils::formatTimeString(item.interactions->at(item.lastMessageUid).timestamp));
}
break;
}
case Role::LastInteraction: {
if (!item.interactions->empty()) {
auto interaction = item.interactions->at(item.lastMessageUid);
@ -190,7 +183,8 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
case Role::IsBanned:
return QVariant(false);
case Role::ContactType:
return QVariant(static_cast<int>(lrcInstance_->getCurrentAccountInfo().profileInfo.type));
return QVariant(
static_cast<int>(lrcInstance_->getCurrentAccountInfo().profileInfo.type));
}
}
ContactModel* contactModel;

View file

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

View file

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

View file

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

View file

@ -123,6 +123,7 @@ protected:
Q_INVOKABLE bool isRemoteImage(const QString& msg);
Q_INVOKABLE QString getFormattedDay(const quint64 timestamp);
Q_INVOKABLE QString getFormattedTime(const quint64 timestamp);
Q_INVOKABLE QString getBestFormattedDate(const quint64 timestamp);
Q_INVOKABLE void parseMessageUrls(const QString& messageId,
const QString& msg,
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
Utils::isInteractionGenerated(const lrc::api::interaction::Type& type)
{

View file

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