forked from mirrors/linphone-iphone
Added new APIs to manipulate Contents inside ChatMessage
This commit is contained in:
parent
1e2d9d9a0e
commit
af0db8a7ea
9 changed files with 108 additions and 6 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// =============================================================================
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
// =============================================================================
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -458,8 +458,7 @@ void ChatRoom::compose () {
|
|||
shared_ptr<ChatMessage> ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) {
|
||||
shared_ptr<ChatMessage> chatMessage = createMessage();
|
||||
|
||||
/* TODO
|
||||
Content content;
|
||||
/*Content content;
|
||||
content.setContentType(ContentType::FileTransfer);
|
||||
content.setBody(linphone_content_get_string_buffer(initialContent));
|
||||
chatMessage->addContent(content);*/
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ public:
|
|||
string contentDisposition;
|
||||
};
|
||||
|
||||
const Content Content::Empty;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Content::Content () : ClonableObject(*new ContentPrivate) {}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ public:
|
|||
|
||||
bool isEmpty () const;
|
||||
|
||||
static const Content Empty;
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(Content);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue