diff --git a/coreapi/chat_file_transfer.c b/coreapi/chat_file_transfer.c index d3ded3de2..210551f45 100644 --- a/coreapi/chat_file_transfer.c +++ b/coreapi/chat_file_transfer.c @@ -28,6 +28,3 @@ #include "c-wrapper/c-wrapper.h" #include "chat/chat-room/chat-room.h" -LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) { - return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createFileTransferMessage(initial_content)); -} diff --git a/include/linphone/api/c-chat-message.h b/include/linphone/api/c-chat-message.h index 4dabfcf8e..ce5da7eed 100644 --- a/include/linphone/api/c-chat-message.h +++ b/include/linphone/api/c-chat-message.h @@ -346,6 +346,34 @@ LINPHONE_PUBLIC LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessag */ LINPHONE_PUBLIC LinphoneChatMessageCbs * linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg); +/** + * Adds a content to the ChatMessage + * @param[in] msg LinphoneChatMessage object + * @param[in] c_content LinphoneContent object + */ +LINPHONE_PUBLIC void linphone_chat_message_add_text_content(LinphoneChatMessage *msg, const LinphoneContent *c_content); + +/** + * Returns true if the chat message has a text content + * @param[in] msg LinphoneChatMessage object + * @return true if it has one, false otherwise + */ +LINPHONE_PUBLIC bool_t linphone_chat_message_has_text_content(const LinphoneChatMessage *msg); + +/** + * Returns true if the chat message has a file transfer content + * @param[in] msg LinphoneChatMessage object + * @return true if it has one, false otherwise + */ +LINPHONE_PUBLIC bool_t linphone_chat_message_has_file_content(const LinphoneChatMessage *msg); + +/** + * Gets the text content if available as a string + * @param[in] msg LinphoneChatMessage object + * @return the LinphoneContent buffer if available, null otherwise + */ +LINPHONE_PUBLIC const char* linphone_chat_message_get_text_content(const LinphoneChatMessage *msg); + /** * @} */ diff --git a/src/c-wrapper/api/c-chat-message.cpp b/src/c-wrapper/api/c-chat-message.cpp index 1c0db2089..949ccde7f 100644 --- a/src/c-wrapper/api/c-chat-message.cpp +++ b/src/c-wrapper/api/c-chat-message.cpp @@ -297,6 +297,30 @@ LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t return ((LinphoneStatus)L_GET_CPP_PTR_FROM_C_OBJECT(msg)->putCharacter(character)); } +void linphone_chat_message_add_text_content(LinphoneChatMessage *msg, const char *c_content) { + LinphonePrivate::Content content; + LinphonePrivate::ContentType contentType = LinphonePrivate::ContentType::PlainText; + content.setContentType(contentType); + content.setBody(L_C_TO_STRING(c_content)); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->addContent(content); +} + +bool_t linphone_chat_message_has_text_content(const LinphoneChatMessage *msg) { + return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->hasTextContent(); +} + +bool_t linphone_chat_message_has_file_content(const LinphoneChatMessage *msg) { + return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->hasFileTransferContent(); +} + +const char * linphone_chat_message_get_text_content(const LinphoneChatMessage *msg) { + LinphonePrivate::Content content = L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getTextContent(); + if (content == LinphonePrivate::Content::Empty) { + return NULL; + } + return L_STRING_TO_C(content.getBodyAsString()); +} + // ============================================================================= // Old listener // ============================================================================= diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index d0f25a116..91fac588c 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -305,6 +305,10 @@ bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr) return result; } +LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) { + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createFileTransferMessage(initial_content)); +} + // ============================================================================= // Reference and user data handling functions. // ============================================================================= diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 1bc7f2d02..be50e0f27 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -1153,7 +1153,7 @@ void ChatMessagePrivate::send () { LinphoneCall *call = nullptr; int errorCode = 0; - if ((currentSendStep &ChatMessagePrivate::Step::FileUpload) == ChatMessagePrivate::Step::FileUpload) { + if ((currentSendStep & ChatMessagePrivate::Step::FileUpload) == ChatMessagePrivate::Step::FileUpload) { lInfo() << "File upload step already done, skipping"; } else { if (getFileTransferInformation()) { @@ -1516,6 +1516,46 @@ void ChatMessage::removeCustomHeader (const string &headerName) { d->customHeaders.erase(headerName); } +bool ChatMessage::hasTextContent() const { + L_D(); + for (const auto &c : d->contents) { + if (c.getContentType() == ContentType::PlainText) { + return true; + } + } + return false; +} + +const Content &ChatMessage::getTextContent() const { + L_D(); + for (const auto &c : d->contents) { + if (c.getContentType() == ContentType::PlainText) { + return c; + } + } + return Content::Empty; +} + +bool ChatMessage::hasFileTransferContent() const { + L_D(); + for (const auto &c : d->contents) { + if (c.getContentType() == ContentType::FileTransfer) { + return true; + } + } + return false; +} + +const Content &ChatMessage::getFileTransferContent() const { + L_D(); + for (const auto &c : d->contents) { + if (c.getContentType() == ContentType::FileTransfer) { + return c; + } + } + return Content::Empty; +} + // ----------------------------------------------------------------------------- void ChatMessage::store () { diff --git a/src/chat/chat-message/chat-message.h b/src/chat/chat-message/chat-message.h index 00c41df82..f4227665c 100644 --- a/src/chat/chat-message/chat-message.h +++ b/src/chat/chat-message/chat-message.h @@ -102,6 +102,12 @@ public: void addContent (const Content &content); void removeContent (const Content &content); + bool hasTextContent() const; + const Content &getTextContent() const; + + bool hasFileTransferContent() const; + const Content &getFileTransferContent() const; + const Content &getInternalContent () const; void setInternalContent (const Content &content); diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 03bd1950f..3d085d61d 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -458,8 +458,7 @@ void ChatRoom::compose () { shared_ptr ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) { shared_ptr chatMessage = createMessage(); - /* TODO - Content content; + /*Content content; content.setContentType(ContentType::FileTransfer); content.setBody(linphone_content_get_string_buffer(initialContent)); chatMessage->addContent(content);*/ diff --git a/src/content/content.cpp b/src/content/content.cpp index 7a28ad53e..978f5db3b 100644 --- a/src/content/content.cpp +++ b/src/content/content.cpp @@ -35,6 +35,8 @@ public: string contentDisposition; }; +const Content Content::Empty; + // ----------------------------------------------------------------------------- Content::Content () : ClonableObject(*new ContentPrivate) {} diff --git a/src/content/content.h b/src/content/content.h index 7f73b83f5..3e5f5fb8d 100644 --- a/src/content/content.h +++ b/src/content/content.h @@ -63,6 +63,8 @@ public: bool isEmpty () const; + static const Content Empty; + private: L_DECLARE_PRIVATE(Content); };