diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 94bea15a8..d163223e8 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -989,7 +989,6 @@ LinphoneReason ChatMessagePrivate::receive() { L_Q(); int errorCode = 0; LinphoneReason reason = LinphoneReasonNone; - bool store = false; // --------------------------------------- // Start of message modification @@ -1024,13 +1023,12 @@ LinphoneReason ChatMessagePrivate::receive() { if (errorCode <= 0) { bool foundSupportContentType = false; - for (auto it = contents.begin(); it != contents.end(); it++) { - if (linphone_core_is_content_type_supported(chatRoom->getCore(), it->getContentType().asString().c_str())) { + for (const auto &c : contents) { + if (linphone_core_is_content_type_supported(chatRoom->getCore(), c.getContentType().asString().c_str())) { foundSupportContentType = true; break; - } else { - lError() << "Unsupported content-type: " << it->getContentType().asString(); - } + } else + lError() << "Unsupported content-type: " << c.getContentType().asString(); } if (!foundSupportContentType) { @@ -1039,24 +1037,31 @@ LinphoneReason ChatMessagePrivate::receive() { } } + // Check if this is in fact an outgoing message (case where this is a message sent by us from an other device) + Address me(linphone_core_get_identity(chatRoom->getCore())); + if (me.weakEqual(from)) + setDirection(ChatMessage::Direction::Outgoing); + + /* Check if this is a duplicate message */ + if (chatRoom->findMessageWithDirection(q->getImdnMessageId(), q->getDirection())) + return chatRoom->getCore()->chat_deny_code; + if (errorCode > 0) { reason = linphone_error_code_to_reason(errorCode); q->sendDeliveryNotification(reason); return reason; } - for (auto it = contents.begin(); it != contents.end(); it++) { - if (it->getContentType() == ContentType::FileTransfer) { - store = true; - createFileTransferInformationsFromVndGsmaRcsFtHttpXml(it->getBodyAsString()); - } else if (it->getContentType() == ContentType::PlainText) { - store = true; - } + bool messageToBeStored = false; + for (const auto &c : contents) { + if (c.getContentType() == ContentType::FileTransfer) { + messageToBeStored = true; + createFileTransferInformationsFromVndGsmaRcsFtHttpXml(c.getBodyAsString()); + } else if (c.getContentType() == ContentType::PlainText) + messageToBeStored = true; } - - if (store) { + if (messageToBeStored) q->store(); - } return reason; } diff --git a/src/chat/chat-room/chat-room-p.h b/src/chat/chat-room/chat-room-p.h index c1f3823ee..0074c3767 100644 --- a/src/chat/chat-room/chat-room-p.h +++ b/src/chat/chat-room/chat-room-p.h @@ -98,7 +98,6 @@ public: std::list> messages; std::list> transientMessages; std::list> weakMessages; - std::list receivedRttCharacters; std::shared_ptr pendingMessage = nullptr; IsComposing isComposingHandler; diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 315682bdc..96eb6b1c8 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -371,12 +371,6 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa LinphoneReason reason = LinphoneReasonNone; shared_ptr msg; - /* Check if this is a duplicate message */ - if ((msg = q->findMessageWithDirection(op->get_call_id(), ChatMessage::Direction::Incoming))) { - reason = core->chat_deny_code; - return reason; - } - msg = q->createMessage(); Content content;