Commit af0db8a7 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Added new APIs to manipulate Contents inside ChatMessage

parent 1e2d9d9a
...@@ -28,6 +28,3 @@ ...@@ -28,6 +28,3 @@
#include "c-wrapper/c-wrapper.h" #include "c-wrapper/c-wrapper.h"
#include "chat/chat-room/chat-room.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));
}
...@@ -346,6 +346,34 @@ LINPHONE_PUBLIC LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessag ...@@ -346,6 +346,34 @@ LINPHONE_PUBLIC LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessag
*/ */
LINPHONE_PUBLIC LinphoneChatMessageCbs * linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg); 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);
/** /**
* @} * @}
*/ */
......
...@@ -297,6 +297,30 @@ LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t ...@@ -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)); 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 // Old listener
// ============================================================================= // =============================================================================
......
...@@ -305,6 +305,10 @@ bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr) ...@@ -305,6 +305,10 @@ bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr)
return result; 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. // Reference and user data handling functions.
// ============================================================================= // =============================================================================
......
...@@ -1153,7 +1153,7 @@ void ChatMessagePrivate::send () { ...@@ -1153,7 +1153,7 @@ void ChatMessagePrivate::send () {
LinphoneCall *call = nullptr; LinphoneCall *call = nullptr;
int errorCode = 0; 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"; lInfo() << "File upload step already done, skipping";
} else { } else {
if (getFileTransferInformation()) { if (getFileTransferInformation()) {
...@@ -1516,6 +1516,46 @@ void ChatMessage::removeCustomHeader (const string &headerName) { ...@@ -1516,6 +1516,46 @@ void ChatMessage::removeCustomHeader (const string &headerName) {
d->customHeaders.erase(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 () { void ChatMessage::store () {
......
...@@ -102,6 +102,12 @@ public: ...@@ -102,6 +102,12 @@ public:
void addContent (const Content &content); void addContent (const Content &content);
void removeContent (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; const Content &getInternalContent () const;
void setInternalContent (const Content &content); void setInternalContent (const Content &content);
......
...@@ -458,8 +458,7 @@ void ChatRoom::compose () { ...@@ -458,8 +458,7 @@ void ChatRoom::compose () {
shared_ptr<ChatMessage> ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) { shared_ptr<ChatMessage> ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) {
shared_ptr<ChatMessage> chatMessage = createMessage(); shared_ptr<ChatMessage> chatMessage = createMessage();
/* TODO /*Content content;
Content content;
content.setContentType(ContentType::FileTransfer); content.setContentType(ContentType::FileTransfer);
content.setBody(linphone_content_get_string_buffer(initialContent)); content.setBody(linphone_content_get_string_buffer(initialContent));
chatMessage->addContent(content);*/ chatMessage->addContent(content);*/
......
...@@ -35,6 +35,8 @@ public: ...@@ -35,6 +35,8 @@ public:
string contentDisposition; string contentDisposition;
}; };
const Content Content::Empty;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Content::Content () : ClonableObject(*new ContentPrivate) {} Content::Content () : ClonableObject(*new ContentPrivate) {}
......
...@@ -63,6 +63,8 @@ public: ...@@ -63,6 +63,8 @@ public:
bool isEmpty () const; bool isEmpty () const;
static const Content Empty;
private: private:
L_DECLARE_PRIVATE(Content); L_DECLARE_PRIVATE(Content);
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment