diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 024d0cb6f..27c42b3e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,6 +30,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES call/call.h chat/basic-chat-room-p.h chat/basic-chat-room.h + chat/chat-message-p.h chat/chat-message.h chat/chat-room-p.h chat/chat-room.h diff --git a/src/chat/chat-message-p.h b/src/chat/chat-message-p.h new file mode 100644 index 000000000..ffd699d17 --- /dev/null +++ b/src/chat/chat-message-p.h @@ -0,0 +1,59 @@ +/* + * chat-message-p.h + * Copyright (C) 2017 Belledonne Communications SARL + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _CHAT_MESSAGE_P_H_ +#define _CHAT_MESSAGE_P_H_ + +#include + +#include "chat-message.h" +#include "db/events-db.h" +#include "object/object-p.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class ChatMessagePrivate : public ObjectPrivate { +private: + std::weak_ptr chatRoom; + ChatMessage::Direction direction = ChatMessage::Incoming; + // LinphoneAddress *from; + // LinphoneAddress *to; + std::shared_ptr errorInfo; + std::string contentType; + std::string text; + bool isSecured = false; + bool isReadOnly = false; + time_t time = 0; + std::string id; + std::string appData; + std::list > contents; + std::shared_ptr internalContent; + std::unordered_map customHeaders; + ChatMessage::State state = ChatMessage::Idle; + std::shared_ptr eventsDb; + + L_DECLARE_PUBLIC(ChatMessage); + friend class CpimChatMessageModifier; + friend class MultipartChatMessageModifier; +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _CHAT_MESSAGE_P_H_ diff --git a/src/chat/chat-message.cpp b/src/chat/chat-message.cpp index f4cae49b0..a5e816342 100644 --- a/src/chat/chat-message.cpp +++ b/src/chat/chat-message.cpp @@ -21,37 +21,23 @@ #include "db/events-db.h" #include "object/object-p.h" +#include "linphone/types.h" +#include "linphone/core.h" +#include "linphone/lpconfig.h" + +#include "chat-message-p.h" #include "chat-message.h" +#include "modifier/multipart-chat-message-modifier.h" +#include "modifier/cpim-chat-message-modifier.h" +#include "chat-room.h" + // ============================================================================= LINPHONE_BEGIN_NAMESPACE using namespace std; -class ChatMessagePrivate : public ObjectPrivate { -private: - weak_ptr chatRoom; - ChatMessage::Direction direction = ChatMessage::Incoming; - // LinphoneAddress *from; - // LinphoneAddress *to; - shared_ptr errorInfo; - string contentType; - string text; - bool isSecured = false; - bool isReadOnly = false; - time_t time = 0; - string id; - string appData; - list > contents; - shared_ptr private_content; - unordered_map customHeaders; - ChatMessage::State state = ChatMessage::Idle; - shared_ptr eventsDb; - - L_DECLARE_PUBLIC(ChatMessage); -}; - // ----------------------------------------------------------------------------- ChatMessage::ChatMessage (ChatMessagePrivate &p) : Object(p) {} @@ -105,17 +91,21 @@ string ChatMessage::getContentType () const { return d->contentType; } -string ChatMessage::getText () const { - L_D(const ChatMessage); - return d->text; -} - -void ChatMessage::setText (const string &text) { - L_D(ChatMessage); - d->text = text; -} - void ChatMessage::send () const { + L_D(const ChatMessage); + + if (d->contents.size() > 1) { + MultipartChatMessageModifier mcmm; + mcmm.encode(d); + } + + LinphoneCore *lc = getChatRoom()->getCore(); + LpConfig *lpc = linphone_core_get_config(lc); + if (lp_config_get_int(lpc, "sip", "use_cpim", 0) == 1) { + CpimChatMessageModifier ccmm; + ccmm.encode(d); + } + // TODO. } @@ -164,11 +154,15 @@ list > ChatMessage::getContents () const { void ChatMessage::addContent (const shared_ptr &content) { L_D(ChatMessage); + if (d->isReadOnly) return; + d->contents.push_back(content); } void ChatMessage::removeContent (const shared_ptr &content) { L_D(ChatMessage); + if (d->isReadOnly) return; + d->contents.remove(const_pointer_cast(content)); } @@ -184,11 +178,15 @@ string ChatMessage::getCustomHeaderValue (const string &headerName) const { void ChatMessage::addCustomHeader (const string &headerName, const string &headerValue) { L_D(ChatMessage); + if (d->isReadOnly) return; + d->customHeaders[headerName] = headerValue; } void ChatMessage::removeCustomHeader (const string &headerName) { L_D(ChatMessage); + if (d->isReadOnly) return; + d->customHeaders.erase(headerName); } diff --git a/src/chat/chat-message.h b/src/chat/chat-message.h index e69883d40..727a6fb93 100644 --- a/src/chat/chat-message.h +++ b/src/chat/chat-message.h @@ -69,9 +69,6 @@ public: std::string getContentType () const; - std::string getText () const; - void setText (const std::string &text); - void send () const; bool containsReadableText () const; diff --git a/src/chat/modifier/chat-message-modifier.h b/src/chat/modifier/chat-message-modifier.h index 7fa2de4cb..64434abe5 100644 --- a/src/chat/modifier/chat-message-modifier.h +++ b/src/chat/modifier/chat-message-modifier.h @@ -27,8 +27,8 @@ class ChatMessageModifier { public: - virtual void encode(std::shared_ptr msg) = 0; - virtual void decode(std::shared_ptr msg) = 0; + virtual void encode(const LinphonePrivate::ChatMessagePrivate* msg) = 0; + virtual void decode(const LinphonePrivate::ChatMessagePrivate* msg) = 0; virtual ~ChatMessageModifier () = default; }; diff --git a/src/chat/modifier/cpim-chat-message-modifier.cpp b/src/chat/modifier/cpim-chat-message-modifier.cpp index c6843a242..b29d4cd27 100644 --- a/src/chat/modifier/cpim-chat-message-modifier.cpp +++ b/src/chat/modifier/cpim-chat-message-modifier.cpp @@ -16,17 +16,23 @@ * along with this program. If not, see . */ + #include "chat/chat-message-p.h" #include "cpim-chat-message-modifier.h" LINPHONE_BEGIN_NAMESPACE using namespace std; - void CpimChatMessageModifier::encode(shared_ptr msg) { + void CpimChatMessageModifier::encode(const LinphonePrivate::ChatMessagePrivate* msg) { //TODO + if (msg->internalContent) { + // Another ChatMessageModifier was called before this one, we apply our changes on the private content + } else { + // We're the first ChatMessageModifier to be called, we'll create the private content from the public one + } } - void CpimChatMessageModifier::decode(shared_ptr msg) { + void CpimChatMessageModifier::decode(const LinphonePrivate::ChatMessagePrivate* msg) { //TODO } diff --git a/src/chat/modifier/cpim-chat-message-modifier.h b/src/chat/modifier/cpim-chat-message-modifier.h index ccdaddbdc..d5ee530c6 100644 --- a/src/chat/modifier/cpim-chat-message-modifier.h +++ b/src/chat/modifier/cpim-chat-message-modifier.h @@ -27,8 +27,9 @@ class CpimChatMessageModifier : ChatMessageModifier { public: - virtual void encode(std::shared_ptr msg) = 0; - virtual void decode(std::shared_ptr msg) = 0; + CpimChatMessageModifier() {}; + virtual void encode(const LinphonePrivate::ChatMessagePrivate* msg); + virtual void decode(const LinphonePrivate::ChatMessagePrivate* msg); virtual ~CpimChatMessageModifier () = default; }; diff --git a/src/chat/modifier/multipart-chat-message-modifier.cpp b/src/chat/modifier/multipart-chat-message-modifier.cpp index c805cfeb9..f980a9bfd 100644 --- a/src/chat/modifier/multipart-chat-message-modifier.cpp +++ b/src/chat/modifier/multipart-chat-message-modifier.cpp @@ -16,17 +16,20 @@ * along with this program. If not, see . */ + #include "chat/chat-message-p.h" #include "multipart-chat-message-modifier.h" LINPHONE_BEGIN_NAMESPACE using namespace std; - void MultipartChatMessageModifier::encode(shared_ptr msg) { - //TODO + void MultipartChatMessageModifier::encode(const LinphonePrivate::ChatMessagePrivate* msg) { + if (msg->contents.size() > 1) { + //TODO + } } - void MultipartChatMessageModifier::decode(shared_ptr msg) { + void MultipartChatMessageModifier::decode(const LinphonePrivate::ChatMessagePrivate* msg) { //TODO } diff --git a/src/chat/modifier/multipart-chat-message-modifier.h b/src/chat/modifier/multipart-chat-message-modifier.h index 4577825b4..9f9b23069 100644 --- a/src/chat/modifier/multipart-chat-message-modifier.h +++ b/src/chat/modifier/multipart-chat-message-modifier.h @@ -27,8 +27,9 @@ class MultipartChatMessageModifier : ChatMessageModifier { public: - virtual void encode(std::shared_ptr msg) = 0; - virtual void decode(std::shared_ptr msg) = 0; + MultipartChatMessageModifier() {}; + virtual void encode(const LinphonePrivate::ChatMessagePrivate* msg); + virtual void decode(const LinphonePrivate::ChatMessagePrivate* msg); virtual ~MultipartChatMessageModifier () = default; };