diff --git a/src/app/conversationlistmodelbase.cpp b/src/app/conversationlistmodelbase.cpp index 645c741d1ad84d23f9e9bbe14a914917809b5693..36f6f442f65fe157b513b1886aa607c13e2fed14 100644 --- a/src/app/conversationlistmodelbase.cpp +++ b/src/app/conversationlistmodelbase.cpp @@ -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; diff --git a/src/app/conversationlistmodelbase.h b/src/app/conversationlistmodelbase.h index a47b3dc05c190d7dd7f74b4958b32cb84a6f9675..4fa382e4699e0440db1137568a74060cf4f54721 100644 --- a/src/app/conversationlistmodelbase.h +++ b/src/app/conversationlistmodelbase.h @@ -31,7 +31,6 @@ X(URI) \ X(UnreadMessagesCount) \ X(LastInteractionTimeStamp) \ - X(LastInteractionDate) \ X(LastInteraction) \ X(ContactType) \ X(IsSwarm) \ diff --git a/src/app/mainview/components/SmartListItemDelegate.qml b/src/app/mainview/components/SmartListItemDelegate.qml index 4888a82914ce7a39e70fdfdcbfb88db38b5139bb..8ca7b63937be9dfe50c9aca91d2365fb918411f9 100644 --- a/src/app/mainview/components/SmartListItemDelegate.qml +++ b/src/app/mainview/components/SmartListItemDelegate.qml @@ -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 diff --git a/src/app/messagesadapter.cpp b/src/app/messagesadapter.cpp index 85bdd0094fa89ee91fe1cb9ce75354a062d6d120..2bc816d37023cbcbdb72ff6aeff6f5efb734f7d5 100644 --- a/src/app/messagesadapter.cpp +++ b/src/app/messagesadapter.cpp @@ -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); diff --git a/src/app/messagesadapter.h b/src/app/messagesadapter.h index 6cb8029b222c3968a96502cdee22756242e7b955..881eec37651b8379ae06db8ad04342ea9a9a2145 100644 --- a/src/app/messagesadapter.h +++ b/src/app/messagesadapter.h @@ -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, diff --git a/src/app/utils.cpp b/src/app/utils.cpp index b97887b4ba382ced92703ad0471653291c8b7189..d9841fd5364386f79593ee372c17b50ee8aa54bf 100644 --- a/src/app/utils.cpp +++ b/src/app/utils.cpp @@ -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) { diff --git a/src/app/utils.h b/src/app/utils.h index 35820c0b1e916171db4de8ecbe1a657a86d1ce7c..35118660c82195d06540f0498c95f73e40f6d3d3 100644 --- a/src/app/utils.h +++ b/src/app/utils.h @@ -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);