diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index 9a7b07740..51456cd8f 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -885,6 +885,15 @@ bool ChatRoomModel::isTerminated(const std::shared_ptr& chat return chatRoom->getState() == linphone::ChatRoom::State::Terminated || chatRoom->getState() == linphone::ChatRoom::State::Deleted; } +bool ChatRoomModel::exists(const std::shared_ptr message) const{ + auto entry = std::find_if(mList.begin(), mList.end(), [message](const QSharedPointer& entry ){ + auto chatEventEntry = entry.objectCast(); + return chatEventEntry->mType == ChatRoomModel::EntryType::MessageEntry && chatEventEntry.objectCast()->getChatMessage() == message; + }); + // if not find, load more entries and find it in new entries. + return entry != mList.end(); +} + void ChatRoomModel::addBindingCall(){ // If a call is binding to this chat room, we avoid cleaning data (Add=+1, remove=-1) ++mBindingCalls; } @@ -1088,7 +1097,7 @@ void ChatRoomModel::insertCalls (const QList QSharedPointer ChatRoomModel::insertMessageAtEnd (const std::shared_ptr &message) { QSharedPointer model; - if(mIsInitialized){ + if(mIsInitialized && !exists(message)){ model = ChatMessageModel::create(message); if(model){ connect(model.get(), &ChatMessageModel::remove, this, &ChatRoomModel::removeEntry); @@ -1213,7 +1222,6 @@ void ChatRoomModel::onIsComposingReceived(const std::shared_ptr & chatRoom, const std::shared_ptr & message){ diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.hpp b/linphone-app/src/components/chat-room/ChatRoomModel.hpp index bd4208382..ec8e82e26 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.hpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.hpp @@ -176,6 +176,7 @@ public: void updateNewMessageNotice(const int& count); Q_INVOKABLE int loadTillMessage(ChatMessageModel * message);// Load all entries till message and return its index. -1 if not found. static bool isTerminated(const std::shared_ptr& chatRoom); + bool exists(const std::shared_ptr message) const; void addBindingCall(); // If a call is binding to this chat room, we avoid cleaning data (Add=+1, remove=-1) void removeBindingCall();