From 7f3dc8e9284101702a1e81ef0cb3fe3779799fff Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 4 May 2023 17:28:08 +0200 Subject: [PATCH] Fix ordering messages --- .../src/components/chat-events/ChatCallModel.cpp | 2 +- .../components/chat-events/ChatMessageModel.cpp | 6 +++--- .../components/chat-events/ChatNoticeModel.cpp | 2 +- .../components/chat-room/ChatRoomProxyModel.cpp | 4 +++- .../src/components/core/CoreHandlers.cpp | 2 +- .../src/components/history/HistoryModel.cpp | 4 ++-- linphone-app/ui/modules/Linphone/Chat/Chat.js | 2 +- linphone-app/ui/modules/Linphone/Chat/Chat.qml | 16 ++++++++-------- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/linphone-app/src/components/chat-events/ChatCallModel.cpp b/linphone-app/src/components/chat-events/ChatCallModel.cpp index 42bf6e1cc..19949135a 100644 --- a/linphone-app/src/components/chat-events/ChatCallModel.cpp +++ b/linphone-app/src/components/chat-events/ChatCallModel.cpp @@ -41,7 +41,7 @@ ChatCallModel::ChatCallModel ( std::shared_ptr callLog, const }else{ mTimestamp = QDateTime::fromMSecsSinceEpoch((callLog->getStartDate() + callLog->getDuration()) * 1000); if(hasReceived) - mReceivedTimestamp = QDateTime::fromMSecsSinceEpoch((mCallLog->getData("receivedTime") + callLog->getDuration()) * 1000); + mReceivedTimestamp = QDateTime::fromMSecsSinceEpoch(mCallLog->getData("receivedTime") + (callLog->getDuration() * 1000)); else mReceivedTimestamp = mTimestamp; } diff --git a/linphone-app/src/components/chat-events/ChatMessageModel.cpp b/linphone-app/src/components/chat-events/ChatMessageModel.cpp index c70f10504..19a064f2a 100644 --- a/linphone-app/src/components/chat-events/ChatMessageModel.cpp +++ b/linphone-app/src/components/chat-events/ChatMessageModel.cpp @@ -111,11 +111,11 @@ ChatMessageModel::ChatMessageModel ( std::shared_ptr chat mTimestamp = QDateTime::fromMSecsSinceEpoch(chatMessage->getTime() * 1000); auto appdata = ChatMessageModel::AppDataManager(QString::fromStdString(chatMessage->getAppdata())); if(!appdata.mData.contains("receivedTime")){ - appdata.mData["receivedTime"] = QString::number(mTimestamp.toSecsSinceEpoch()); + mReceivedTimestamp = QDateTime::currentDateTime(); + appdata.mData["receivedTime"] = QString::number(mReceivedTimestamp.toMSecsSinceEpoch()); chatMessage->setAppdata(Utils::appStringToCoreString(appdata.toString())); - mReceivedTimestamp = mTimestamp; }else - mReceivedTimestamp = QDateTime::fromMSecsSinceEpoch(appdata.mData["receivedTime"].toULongLong() * 1000); + mReceivedTimestamp = QDateTime::fromMSecsSinceEpoch(appdata.mData["receivedTime"].toULongLong()); } mWasDownloaded = false; diff --git a/linphone-app/src/components/chat-events/ChatNoticeModel.cpp b/linphone-app/src/components/chat-events/ChatNoticeModel.cpp index bcdc73d1e..88e717339 100644 --- a/linphone-app/src/components/chat-events/ChatNoticeModel.cpp +++ b/linphone-app/src/components/chat-events/ChatNoticeModel.cpp @@ -35,7 +35,7 @@ ChatNoticeModel::ChatNoticeModel ( std::shared_ptr eventLog, setEventLogType(LinphoneEnums::fromLinphone(mEventLog->getType())); mTimestamp = QDateTime::fromMSecsSinceEpoch(eventLog->getCreationTime() * 1000); if(mEventLog->dataExists("receivedTime")) - mReceivedTimestamp = QDateTime::fromMSecsSinceEpoch(mEventLog->getData("receivedTime") * 1000); + mReceivedTimestamp = QDateTime::fromMSecsSinceEpoch(mEventLog->getData("receivedTime")); else mReceivedTimestamp = mTimestamp; } diff --git a/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp b/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp index c170c7f87..0cb35419f 100644 --- a/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp @@ -188,7 +188,8 @@ bool ChatRoomProxyModel::lessThan (const QModelIndex &left, const QModelIndex &r return true; if(!a) return false; - return a->getReceivedTimestamp() < b->getReceivedTimestamp(); + return a->getReceivedTimestamp() < b->getReceivedTimestamp() || + (a->getReceivedTimestamp() == b->getReceivedTimestamp() && a->getTimestamp() < b->getTimestamp()); } // ----------------------------------------------------------------------------- @@ -288,6 +289,7 @@ void ChatRoomProxyModel::reload (ChatRoomModel *chatRoomModel) { mChatRoomModel = CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(chatRoomModel); setSourceModel(mChatRoomModel.get()); + sort(0); if (mChatRoomModel) { ChatRoomModel *ChatRoomModel = mChatRoomModel.get(); diff --git a/linphone-app/src/components/core/CoreHandlers.cpp b/linphone-app/src/components/core/CoreHandlers.cpp index 780d6a88a..61fbad8b4 100644 --- a/linphone-app/src/components/core/CoreHandlers.cpp +++ b/linphone-app/src/components/core/CoreHandlers.cpp @@ -233,7 +233,7 @@ void CoreHandlers::onMessagesReceived ( auto chatRoom = message->getChatRoom(); auto dbMessage = chatRoom->findMessage(message->getMessageId()); auto appdata = ChatMessageModel::AppDataManager(QString::fromStdString(dbMessage->getAppdata())); - appdata.mData["receivedTime"] = QString::number(QDateTime::currentMSecsSinceEpoch()/1000); + appdata.mData["receivedTime"] = QString::number(QDateTime::currentMSecsSinceEpoch()); dbMessage->setAppdata(Utils::appStringToCoreString(appdata.toString())); } if( !message || message->isOutgoing() ) diff --git a/linphone-app/src/components/history/HistoryModel.cpp b/linphone-app/src/components/history/HistoryModel.cpp index e4be1e0c7..1d46fe991 100644 --- a/linphone-app/src/components/history/HistoryModel.cpp +++ b/linphone-app/src/components/history/HistoryModel.cpp @@ -45,7 +45,7 @@ static inline void fillCallStartEntry (QVariantMap &dest, const shared_ptrgetStartDate() * 1000); if(callLog->dataExists("receivedTime")) - dest["receivedTimestamp"] = QDateTime::fromMSecsSinceEpoch(callLog->getData("receivedTime") * 1000); + dest["receivedTimestamp"] = QDateTime::fromMSecsSinceEpoch(callLog->getData("receivedTime")); else dest["receivedTimestamp"] = dest["timestamp"]; dest["isOutgoing"] = callLog->getDir() == linphone::Call::Dir::Outgoing; @@ -64,7 +64,7 @@ static inline void fillCallEndEntry (QVariantMap &dest, const shared_ptrgetStartDate() + callLog->getDuration()) * 1000); if(callLog->dataExists("receivedTime")) - dest["receivedTimestamp"] = QDateTime::fromMSecsSinceEpoch((callLog->getData("receivedTime") + callLog->getDuration()) * 1000); + dest["receivedTimestamp"] = QDateTime::fromMSecsSinceEpoch(callLog->getData("receivedTime") + (callLog->getDuration() * 1000)); else dest["receivedTimestamp"] = dest["timestamp"]; dest["isOutgoing"] = callLog->getDir() == linphone::Call::Dir::Outgoing; diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.js b/linphone-app/ui/modules/Linphone/Chat/Chat.js index d151c1289..56c87bc29 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.js +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.js @@ -38,7 +38,7 @@ function initView () { } function getComponentFromEntry (chatEntry) { - + if(!chatEntry) return '' if (chatEntry.type === Linphone.ChatRoomModel.CallEntry) { return 'Event.qml' } diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.qml b/linphone-app/ui/modules/Linphone/Chat/Chat.qml index e371c10ba..dfa51a2f4 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.qml +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.qml @@ -123,12 +123,12 @@ Rectangle { delegate: Rectangle { id: entry - property bool isNotice : $chatEntry.type === ChatRoomModel.NoticeEntry - property bool isCall : $chatEntry.type === ChatRoomModel.CallEntry - property bool isMessage : $chatEntry.type === ChatRoomModel.MessageEntry + property bool isNotice : $chatEntry && ($chatEntry.type === ChatRoomModel.NoticeEntry) + property bool isCall : $chatEntry && ($chatEntry.type === ChatRoomModel.CallEntry) + property bool isMessage : $chatEntry && ($chatEntry.type === ChatRoomModel.MessageEntry) property var previousItem : proxyModel.count > 0 && index >0 ? proxyModel.getAt(index-1) : null property var nextItem : proxyModel.count > 0 ? proxyModel.getAt(index+1) : null // bind to count - property bool displayDate: !Utils.equalDate(new Date($chatEntry.timestamp), new Date()) + property bool displayDate: $chatEntry && !Utils.equalDate(new Date($chatEntry.timestamp), new Date()) property bool isTopGrouped: isGrouped(entry.previousItem, $chatEntry) || false property bool isBottomGrouped: isGrouped($chatEntry, entry.nextItem) || false @@ -177,7 +177,7 @@ Rectangle { RowLayout{ id: headerLayout Layout.fillWidth: true - Layout.alignment: Qt.AlignTop | ($chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) + Layout.alignment: Qt.AlignTop | ($chatEntry && $chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) Layout.leftMargin: ChatStyle.entry.metaWidth// + ChatStyle.entry.message.extraContent.spacing Layout.rightMargin: ChatStyle.entry.message.outgoing.areaSize spacing:0 @@ -185,7 +185,7 @@ Rectangle { visible: !entry.isTopGrouped Text { id:timeDisplay - Layout.alignment: Qt.AlignTop | ($chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) + Layout.alignment: Qt.AlignTop | ($chatEntry && $chatEntry.isOutgoing ? Qt.AlignRight : Qt.AlignLeft) Layout.preferredHeight: implicitHeight// ChatStyle.entry.lineHeight //Layout.preferredWidth: ChatStyle.entry.time.width @@ -200,14 +200,14 @@ Rectangle { verticalAlignment: Text.AlignVCenter TooltipArea { - text: UtilsCpp.toDateTimeString($chatEntry.timestamp) + text: $chatEntry ? UtilsCpp.toDateTimeString($chatEntry.timestamp) : '' } visible:!isNotice } Text{ id:authorName //Layout.leftMargin: timeDisplay.width + ChatStyle.entry.metaWidth + ChatStyle.entry.message.extraContent.spacing - property var displayName: $chatEntry.fromDisplayName ? $chatEntry.fromDisplayName : $chatEntry.name + property var displayName: $chatEntry ? $chatEntry.fromDisplayName ? $chatEntry.fromDisplayName : $chatEntry.name : '' text : displayName != undefined ? displayName : '' color: ChatStyle.entry.event.text.colorModel.color