From 1610aa411e6a6d01aaa81d078906b00611893b4d Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 21 Aug 2017 13:59:09 +0200 Subject: [PATCH] feat(Message): add a basic impl --- src/message/message.cpp | 171 ++++++++++++++++++++++++++++++++++++++++ src/message/message.h | 19 ++--- 2 files changed, 181 insertions(+), 9 deletions(-) diff --git a/src/message/message.cpp b/src/message/message.cpp index b74ec5376..c3eaff907 100644 --- a/src/message/message.cpp +++ b/src/message/message.cpp @@ -15,3 +15,174 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include + +#include "db/events-db.h" +#include "object/object-p.h" + +#include "message.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +using namespace std; + +class MessagePrivate : public ObjectPrivate { +private: + weak_ptr chatRoom; + MessageDirection direction = MessageDirection::Incoming; + // LinphoneAddress *from; + // LinphoneAddress *to; + shared_ptr errorInfo; + string contentType; + string text; + bool isSecured = false; + time_t time = 0; + string id; + string appData; + list > contents; + unordered_map customHeaders; + MessageState state = MessageState::Idle; + shared_ptr eventsDb; + + L_DECLARE_PUBLIC(Message); +}; + +// ----------------------------------------------------------------------------- + +Message::Message (MessagePrivate &p) : Object(p) {} + +shared_ptr Message::getChatRoom () const { + L_D(const Message); + shared_ptr chatRoom = d->chatRoom.lock(); + if (!chatRoom) { + // TODO. + } + return chatRoom; +} + +MessageDirection Message::getDirection () const { + L_D(const Message); + return d->direction; +} + +shared_ptr Message::getFromAddress () const { + // TODO. + return nullptr; +} + +shared_ptr Message::getToAddress () const { + // TODO. + return nullptr; +} + +shared_ptr Message::getLocalAddress () const { + // TODO. + return nullptr; +} + +shared_ptr Message::getRemoteAddress () const { + // TODO. + return nullptr; +} + +MessageState Message::getState () const { + L_D(const Message); + return d->state; +} + +shared_ptr Message::getErrorInfo () const { + L_D(const Message); + return d->errorInfo; +} + +string Message::getContentType () const { + L_D(const Message); + return d->contentType; +} + +string Message::getText () const { + L_D(const Message); + return d->text; +} + +void Message::setText (const string &text) { + L_D(Message); + d->text = text; +} + +void Message::send () const { + // TODO. +} + +bool Message::containsReadableText () const { + // TODO: Check content type. + return true; +} + +bool Message::isSecured () const { + L_D(const Message); + return d->isSecured; +} + +time_t Message::getTime () const { + L_D(const Message); + return d->time; +} + +string Message::getId () const { + L_D(const Message); + return d->id; +} + +string Message::getAppdata () const { + L_D(const Message); + return d->appData; +} + +void Message::setAppdata (const string &appData) { + L_D(Message); + d->appData = appData; +} + +list > Message::getContents () const { + L_D(const Message); + list > contents; + for (const auto &content : d->contents) + contents.push_back(content); + return contents; +} + +void Message::addContent (const shared_ptr &content) { + L_D(Message); + d->contents.push_back(content); +} + +void Message::removeContent (const shared_ptr &content) { + L_D(Message); + d->contents.remove(const_pointer_cast(content)); +} + +string Message::getCustomHeaderValue (const string &headerName) const { + L_D(const Message); + try { + return d->customHeaders.at(headerName); + } catch (const exception &) { + // Key doesn't exist. + } + return ""; +} + +void Message::addCustomHeader (const string &headerName, const string &headerValue) { + L_D(Message); + d->customHeaders[headerName] = headerValue; +} + +void Message::removeCustomHeader (const string &headerName) { + L_D(Message); + d->customHeaders.erase(headerName); +} + +LINPHONE_END_NAMESPACE diff --git a/src/message/message.h b/src/message/message.h index 2ed93b803..e317269c4 100644 --- a/src/message/message.h +++ b/src/message/message.h @@ -40,6 +40,8 @@ class LINPHONE_PUBLIC Message : public Object { friend class ChatRoom; public: + std::shared_ptr getChatRoom () const; + MessageDirection getDirection () const; std::shared_ptr getFromAddress () const; @@ -47,7 +49,7 @@ public: std::shared_ptr getLocalAddress () const; std::shared_ptr getRemoteAddress () const; - std::shared_ptr getChatRoom () const; + MessageState getState () const; std::shared_ptr getErrorInfo () const; @@ -67,20 +69,19 @@ public: std::string getId () const; std::string getAppdata () const; - void setAppdata (const std::string &data); + void setAppdata (const std::string &appData); - std::list > getContents () const; - void addContent (std::shared_ptr &content); - void removeContent (std::shared_ptr &content); + std::list > getContents () const; + void addContent (const std::shared_ptr &content); + void removeContent (const std::shared_ptr &content); - std::string getCustomHeaderValue (const std::string &headerName); + std::string getCustomHeaderValue (const std::string &headerName) const; void addCustomHeader (const std::string &headerName, const std::string &headerValue); void removeCustomHeader (const std::string &headerName); -protected: - Message (); - private: + Message (MessagePrivate &p); + L_DECLARE_PRIVATE(Message); L_DISABLE_COPY(Message); };