From 7f32ae8582e3e3f4b8a175128b538a5c1e34afed Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 11 Oct 2017 11:56:17 +0200 Subject: [PATCH] fix(ChatMessage): use L_DECLARE_ENUM to declare direction --- include/linphone/api/c-types.h | 6 ++ include/linphone/enums/chat-message-enums.h | 4 + src/chat/chat-message.cpp | 8 +- src/chat/chat-message.h | 99 ++++++++++----------- src/chat/chat-room.cpp | 4 +- 5 files changed, 63 insertions(+), 58 deletions(-) diff --git a/include/linphone/api/c-types.h b/include/linphone/api/c-types.h index 92ce261f3..16d86f3fb 100644 --- a/include/linphone/api/c-types.h +++ b/include/linphone/api/c-types.h @@ -137,6 +137,12 @@ typedef struct _LinphoneChatMessageEvent LinphoneChatMessageEvent; */ L_DECLARE_C_ENUM(ChatMessageState, L_ENUM_VALUES_CHAT_MESSAGE_STATE); +/** + * LinphoneChatMessageDirection is used to indicate if a message is outgoing or incoming. + * @ingroup chatroom + */ +L_DECLARE_C_ENUM(ChatMessageDirection, L_ENUM_VALUES_CHAT_MESSAGE_DIRECTION); + L_DECLARE_C_ENUM(ChatRoomState, L_ENUM_VALUES_CHAT_ROOM_STATE); L_DECLARE_C_ENUM(EventLogType, L_ENUM_VALUES_EVENT_LOG_TYPE); diff --git a/include/linphone/enums/chat-message-enums.h b/include/linphone/enums/chat-message-enums.h index f98f9fe7f..048a70213 100644 --- a/include/linphone/enums/chat-message-enums.h +++ b/include/linphone/enums/chat-message-enums.h @@ -32,4 +32,8 @@ F(DeliveredToUser) \ F(Displayed) +#define L_ENUM_VALUES_CHAT_MESSAGE_DIRECTION(F) \ + F(Incoming) \ + F(Outgoing) + #endif // ifndef _CHAT_MESSAGE_ENUMS_H_ diff --git a/src/chat/chat-message.cpp b/src/chat/chat-message.cpp index 39a6cd747..3542edee6 100644 --- a/src/chat/chat-message.cpp +++ b/src/chat/chat-message.cpp @@ -1124,7 +1124,7 @@ void ChatMessagePrivate::send() { //TODO Remove : This won't be necessary once we store the contentsList string clearTextMessage; ContentType clearTextContentType; - + if (!getText().empty()) { clearTextMessage = getText().c_str(); } @@ -1271,12 +1271,12 @@ ChatMessage::Direction ChatMessage::getDirection () const { bool ChatMessage::isOutgoing () const { L_D(); - return d->direction == Outgoing; + return d->direction == Direction::Outgoing; } bool ChatMessage::isIncoming () const { L_D(); - return d->direction == Incoming; + return d->direction == Direction::Incoming; } ChatMessage::State ChatMessage::getState() const { @@ -1556,7 +1556,7 @@ int ChatMessage::putCharacter(uint32_t character) { lDebug() << "New line sent, forge a message with content " << d->rttMessage.c_str(); d->setTime(ms_time(0)); d->state = State::Displayed; - d->direction = Outgoing; + d->direction = Direction::Outgoing; setFromAddress(LinphonePrivate::Address(linphone_address_as_string(linphone_address_new(linphone_core_get_identity(lc))))); linphone_chat_message_store(L_GET_C_BACK_PTR(this)); d->rttMessage = ""; diff --git a/src/chat/chat-message.h b/src/chat/chat-message.h index d684f931a..90a6c6400 100644 --- a/src/chat/chat-message.h +++ b/src/chat/chat-message.h @@ -33,7 +33,6 @@ LINPHONE_BEGIN_NAMESPACE class Address; class ChatRoom; -class ChatRoomPrivate; class Content; class ErrorInfo; class ChatMessagePrivate; @@ -46,96 +45,92 @@ class LINPHONE_PUBLIC ChatMessage : public Object { public: L_OVERRIDE_SHARED_FROM_THIS(ChatMessage); - enum Direction { - Incoming, - Outgoing - }; - L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_MESSAGE_STATE); + L_DECLARE_ENUM(Direction, L_ENUM_VALUES_CHAT_MESSAGE_DIRECTION); - ChatMessage(const std::shared_ptr &room); - virtual ~ChatMessage() = default; + ChatMessage (const std::shared_ptr &chatRoom); + virtual ~ChatMessage () = default; - LinphoneChatMessage * getBackPtr(); + LinphoneChatMessage *getBackPtr (); - std::shared_ptr getChatRoom() const; + std::shared_ptr getChatRoom () const; // ----------------------------------------------------------------------------- // Methods // ----------------------------------------------------------------------------- - void store(); + void store (); - void updateState(State state); + void updateState (State state); - void reSend(); + void reSend (); - void sendDeliveryNotification(LinphoneReason reason); + void sendDeliveryNotification (LinphoneReason reason); - void sendDisplayNotification(); + void sendDisplayNotification (); - int uploadFile(); + int uploadFile (); - int downloadFile(); + int downloadFile (); - void cancelFileTransfer(); + void cancelFileTransfer (); - int putCharacter(uint32_t character); + int putCharacter (uint32_t character); // ----------------------------------------------------------------------------- // Getters & setters // ----------------------------------------------------------------------------- - Direction getDirection() const; - bool isOutgoing() const; - bool isIncoming() const; + Direction getDirection () const; + bool isOutgoing () const; + bool isIncoming () const; - const std::string& getExternalBodyUrl() const; - void setExternalBodyUrl(const std::string &url); + const std::string &getExternalBodyUrl () const; + void setExternalBodyUrl (const std::string &url); - time_t getTime() const; + time_t getTime () const; - bool isSecured() const; - void setIsSecured(bool isSecured); + bool isSecured () const; + void setIsSecured (bool isSecured); - State getState() const; + State getState () const; - const std::string& getId() const; - void setId(const std::string&); + const std::string &getId () const; + void setId (const std::string &); - bool isRead() const; + bool isRead () const; - const std::string& getAppdata() const; - void setAppdata(const std::string &appData); + const std::string &getAppdata () const; + void setAppdata (const std::string &appData); - const Address& getFromAddress() const; - void setFromAddress(Address from); - void setFromAddress(const std::string& from); + const Address &getFromAddress () const; + void setFromAddress (Address from); + void setFromAddress (const std::string &from); - const Address& getToAddress() const; - void setToAddress(Address to); - void setToAddress(const std::string& to); + const Address &getToAddress () const; + void setToAddress (Address to); + void setToAddress (const std::string &to); - const std::string& getFileTransferFilepath() const; - void setFileTransferFilepath(const std::string &path); + const std::string &getFileTransferFilepath () const; + void setFileTransferFilepath (const std::string &path); - const LinphoneErrorInfo * getErrorInfo() const; + const LinphoneErrorInfo *getErrorInfo () const; - bool isReadOnly() const; + bool isReadOnly () const; - const std::list& getContents() const; - void addContent(const Content& content); - void removeContent(const Content& content); + const std::list &getContents () const; + void addContent (const Content &content); + void removeContent (const Content &content); - const Content& getInternalContent() const; - void setInternalContent(const Content& content); + const Content &getInternalContent () const; + void setInternalContent (const Content &content); - std::string getCustomHeaderValue(const std::string &headerName) const; - void addCustomHeader(const std::string &headerName, const std::string &headerValue); - void removeCustomHeader(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: - explicit ChatMessage(ChatMessagePrivate &p); + explicit ChatMessage (ChatMessagePrivate &p); private: L_DECLARE_PRIVATE(ChatMessage); diff --git a/src/chat/chat-room.cpp b/src/chat/chat-room.cpp index eea1feab0..678a82d3c 100644 --- a/src/chat/chat-room.cpp +++ b/src/chat/chat-room.cpp @@ -280,7 +280,7 @@ int ChatRoomPrivate::createChatMessageFromDb (int argc, char **argv, char **colN message->addContent(content); Address peer(peerAddress.asString()); - if (atoi(argv[3]) == ChatMessage::Direction::Incoming) { + if (atoi(argv[3]) == static_cast(ChatMessage::Direction::Incoming)) { message->getPrivate()->setDirection(ChatMessage::Direction::Incoming); message->setFromAddress(peer); } else { @@ -552,7 +552,7 @@ void ChatRoom::compose () { shared_ptr ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) { L_D(); shared_ptr chatMessage = createMessage(); - + /* TODO Content content; content.setContentType(ContentType::FileTransfer);