Commit 4957187d authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

More cleanup in ChatMessage

parent deb7f90a
......@@ -98,11 +98,11 @@ LinphoneChatRoom *linphone_chat_message_get_chat_room(const LinphoneChatMessage
}
const char *linphone_chat_message_get_external_body_url(const LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getExternalBodyUrl());
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getExternalBodyUrl());
}
void linphone_chat_message_set_external_body_url(LinphoneChatMessage *msg, const char *url) {
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setExternalBodyUrl(L_C_TO_STRING(url));
}
time_t linphone_chat_message_get_time(const LinphoneChatMessage *msg) {
......@@ -166,11 +166,11 @@ bool_t linphone_chat_message_is_read(LinphoneChatMessage *msg) {
}
const char *linphone_chat_message_get_appdata(const LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getAppdata());
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getAppdata());
}
void linphone_chat_message_set_appdata(LinphoneChatMessage *msg, const char *data) {
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setAppdata(L_C_TO_STRING(data));
L_GET_PRIVATE_FROM_C_OBJECT(msg)->setAppdata(L_C_TO_STRING(data));
}
const LinphoneAddress *linphone_chat_message_get_from_address(LinphoneChatMessage *msg) {
......@@ -200,11 +200,11 @@ void linphone_chat_message_set_to_address(LinphoneChatMessage *msg, const Linpho
}
const char *linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFileTransferFilepath());
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getFileTransferFilepath());
}
void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath) {
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setFileTransferFilepath(L_C_TO_STRING(filepath));
L_GET_PRIVATE_FROM_C_OBJECT(msg)->setFileTransferFilepath(L_C_TO_STRING(filepath));
}
belle_http_request_t * linphone_chat_message_get_http_request(LinphoneChatMessage *msg) {
......@@ -302,11 +302,11 @@ void linphone_chat_message_add_text_content(LinphoneChatMessage *msg, const char
}
bool_t linphone_chat_message_has_text_content(const LinphoneChatMessage *msg) {
return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->hasTextContent();
return L_GET_PRIVATE_FROM_C_OBJECT(msg)->hasTextContent();
}
const char * linphone_chat_message_get_text_content(const LinphoneChatMessage *msg) {
const LinphonePrivate::Content *content = L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getTextContent();
const LinphonePrivate::Content *content = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getTextContent();
if (*content == LinphonePrivate::Content::Empty) {
return NULL;
}
......
......@@ -93,6 +93,20 @@ public:
const std::string &getText();
void setText(const std::string &text);
const std::string &getFileTransferFilepath () const;
void setFileTransferFilepath (const std::string &path);
const std::string &getAppdata () const;
void setAppdata (const std::string &appData);
const std::string &getExternalBodyUrl () const;
bool hasTextContent() const;
const Content* getTextContent() const;
bool hasFileTransferContent() const;
const Content* getFileTransferContent() const;
LinphoneContent *getFileTransferInformation() const;
void setFileTransferInformation(const LinphoneContent *content);
......@@ -115,9 +129,6 @@ private:
Address to;
time_t time = 0;
std::string id;
std::string appData;
std::string fileTransferFilePath;
std::string externalBodyUrl;
std::string rttMessage;
bool isSecured = false;
bool isReadOnly = false;
......@@ -132,6 +143,8 @@ private:
FileTransferChatMessageModifier fileTransferChatMessageModifier;
// Cache for returned values, used for compatibility with previous C API
std::string appData;
std::string fileTransferFilePath;
ContentType cContentType;
std::string cText;
......
......@@ -157,6 +157,69 @@ string ChatMessagePrivate::getSalCustomHeaderValue (const string &name) {
// Below methods are only for C API backward compatibility...
// -----------------------------------------------------------------------------
bool ChatMessagePrivate::hasTextContent() const {
for (const Content *c : contents) {
if (c->getContentType() == ContentType::PlainText) {
return true;
}
}
return false;
}
const Content* ChatMessagePrivate::getTextContent() const {
for (const Content *c : contents) {
if (c->getContentType() == ContentType::PlainText) {
return c;
}
}
return &Content::Empty;
}
bool ChatMessagePrivate::hasFileTransferContent() const {
for (const Content *c : contents) {
if (c->getContentType() == ContentType::FileTransfer) {
return true;
}
}
return false;
}
const Content* ChatMessagePrivate::getFileTransferContent() const {
for (const Content *c : contents) {
if (c->getContentType() == ContentType::FileTransfer) {
return c;
}
}
return &Content::Empty;
}
const string &ChatMessagePrivate::getFileTransferFilepath () const {
return fileTransferFilePath;
}
void ChatMessagePrivate::setFileTransferFilepath (const string &path) {
fileTransferFilePath = path;
}
const string &ChatMessagePrivate::getAppdata () const {
return appData;
}
void ChatMessagePrivate::setAppdata (const string &data) {
appData = data;
// TODO: history.
// linphone_chat_message_store_appdata(L_GET_C_BACK_PTR(this));
}
const string &ChatMessagePrivate::getExternalBodyUrl () const {
if (hasFileTransferContent()) {
FileTransferContent *content = (FileTransferContent*) getFileTransferContent();
return content->getFileUrl();
}
return Utils::getEmptyConstRefObject<string>();
}
const ContentType &ChatMessagePrivate::getContentType () {
if (direction == ChatMessage::Direction::Incoming) {
if (contents.size() > 0) {
......@@ -183,10 +246,9 @@ void ChatMessagePrivate::setContentType (const ContentType &contentType) {
}
const string &ChatMessagePrivate::getText () {
L_Q();
if (direction == ChatMessage::Direction::Incoming) {
if (q->hasTextContent()) {
cText = q->getTextContent()->getBodyAsString();
if (hasTextContent()) {
cText = getTextContent()->getBodyAsString();
} else if (contents.size() > 0) {
Content *content = contents.front();
cText = content->getBodyAsString();
......@@ -194,8 +256,8 @@ const string &ChatMessagePrivate::getText () {
cText = internalContent.getBodyAsString();
}
} else {
if (q->hasTextContent()) {
cText = q->getTextContent()->getBodyAsString();
if (hasTextContent()) {
cText = getTextContent()->getBodyAsString();
} else if (!internalContent.isEmpty()) {
cText = internalContent.getBodyAsString();
} else {
......@@ -213,9 +275,8 @@ void ChatMessagePrivate::setText (const string &text) {
}
LinphoneContent *ChatMessagePrivate::getFileTransferInformation () const {
L_Q();
if (q->hasFileTransferContent()) {
return q->getFileTransferContent()->toLinphoneContent();
if (hasFileTransferContent()) {
return getFileTransferContent()->toLinphoneContent();
}
return NULL;
}
......@@ -556,18 +617,11 @@ void ChatMessagePrivate::send () {
internalContent = *(contents.front());
}
if (!externalBodyUrl.empty()) { // Deprecated way of sending files
char *content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"", externalBodyUrl.c_str());
auto msgOp = dynamic_cast<SalMessageOpInterface *>(op);
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), content_type, nullptr, nullptr);
ms_free(content_type);
auto msgOp = dynamic_cast<SalMessageOpInterface *>(op);
if (internalContent.getContentType().isValid()) {
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), internalContent.getContentType().asString().c_str(), internalContent.getBodyAsString().c_str(), to.asStringUriOnly().c_str());
} else {
auto msgOp = dynamic_cast<SalMessageOpInterface *>(op);
if (internalContent.getContentType().isValid()) {
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), internalContent.getContentType().asString().c_str(), internalContent.getBodyAsString().c_str(), to.asStringUriOnly().c_str());
} else {
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), internalContent.getBodyAsString().c_str());
}
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), internalContent.getBodyAsString().c_str());
}
for (Content *content : contents) {
......@@ -890,83 +944,4 @@ int ChatMessage::putCharacter (uint32_t character) {
return -1;
}
// -----------------------------------------------------------------------------
// Below methods are only for C API backward compatibility...
// -----------------------------------------------------------------------------
bool ChatMessage::hasTextContent() const {
L_D();
for (const Content *c : d->contents) {
if (c->getContentType() == ContentType::PlainText) {
return true;
}
}
return false;
}
const Content* ChatMessage::getTextContent() const {
L_D();
for (const Content *c : d->contents) {
if (c->getContentType() == ContentType::PlainText) {
return c;
}
}
return &Content::Empty;
}
bool ChatMessage::hasFileTransferContent() const {
L_D();
for (const Content *c : d->contents) {
if (c->getContentType() == ContentType::FileTransfer) {
return true;
}
}
return false;
}
const Content* ChatMessage::getFileTransferContent() const {
L_D();
for (const Content *c : d->contents) {
if (c->getContentType() == ContentType::FileTransfer) {
return c;
}
}
return &Content::Empty;
}
const string &ChatMessage::getFileTransferFilepath () const {
L_D();
return d->fileTransferFilePath;
}
void ChatMessage::setFileTransferFilepath (const string &path) {
L_D();
d->fileTransferFilePath = path;
}
const string &ChatMessage::getAppdata () const {
L_D();
return d->appData;
}
void ChatMessage::setAppdata (const string &appData) {
L_D();
d->appData = appData;
// TODO: history.
// linphone_chat_message_store_appdata(L_GET_C_BACK_PTR(this));
}
const string &ChatMessage::getExternalBodyUrl () const {
L_D();
return d->externalBodyUrl;
}
void ChatMessage::setExternalBodyUrl (const string &url) {
L_D();
d->externalBodyUrl = url;
}
// -----------------------------------------------------------------------------
LINPHONE_END_NAMESPACE
......@@ -57,12 +57,6 @@ public:
ChatMessage (const std::shared_ptr<ChatRoom> &chatRoom);
// ----- TODO: Remove me.
const std::string &getFileTransferFilepath () const;
void setFileTransferFilepath (const std::string &path);
const std::string &getAppdata () const;
void setAppdata (const std::string &appData);
const std::string &getExternalBodyUrl () const;
void setExternalBodyUrl (const std::string &url);
void cancelFileTransfer ();
int putCharacter (uint32_t character);
void updateState (State state);
......@@ -101,12 +95,6 @@ public:
void addContent (Content *content);
void removeContent (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);
......
......@@ -284,8 +284,8 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa
const SalCustomHeader *ch = op->get_recv_custom_header();
if (ch)
msg->getPrivate()->setSalCustomHeaders(sal_custom_header_clone(ch));
if (salMsg->url)
msg->setExternalBodyUrl(salMsg->url);
/*if (salMsg->url)
msg->getPrivate()->setExternalBodyUrl(salMsg->url);*/
reason = msg->getPrivate()->receive();
......
......@@ -432,8 +432,8 @@ int FileTransferChatMessageModifier::uploadFile () {
}
// THIS IS ONLY FOR BACKWARD C API COMPAT
if (currentFileContentToTransfer->getFilePath().empty() && !chatMessage->getFileTransferFilepath().empty()) {
currentFileContentToTransfer->setFilePath(chatMessage->getFileTransferFilepath());
if (currentFileContentToTransfer->getFilePath().empty() && !chatMessage->getPrivate()->getFileTransferFilepath().empty()) {
currentFileContentToTransfer->setFilePath(chatMessage->getPrivate()->getFileTransferFilepath());
}
belle_http_request_listener_callbacks_t cbs = { 0 };
......@@ -850,8 +850,8 @@ int FileTransferChatMessageModifier::downloadFile(const shared_ptr<ChatMessage>
}
// THIS IS ONLY FOR BACKWARD C API COMPAT
if (currentFileContentToTransfer->getFilePath().empty() && !chatMessage->getFileTransferFilepath().empty()) {
currentFileContentToTransfer->setFilePath(chatMessage->getFileTransferFilepath());
if (currentFileContentToTransfer->getFilePath().empty() && !chatMessage->getPrivate()->getFileTransferFilepath().empty()) {
currentFileContentToTransfer->setFilePath(chatMessage->getPrivate()->getFileTransferFilepath());
}
belle_http_request_listener_callbacks_t cbs = { 0 };
......
......@@ -42,19 +42,20 @@ static void chat_message_multipart_modifier_base(bool first_file_transfer, bool
Address paulineAddress(linphone_address_as_string_uri_only(pauline->identity));
shared_ptr<ChatRoom> marieRoom = make_shared<BasicChatRoom>(marie->lc->cppCore, paulineAddress);
shared_ptr<ChatMessage> marieMessage;
shared_ptr<ChatMessage> marieMessage = marieRoom->createMessage();
if (first_file_transfer) {
char *send_filepath = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv");
LinphoneContent *content = linphone_core_create_content(marie->lc);
belle_sip_object_set_name(BELLE_SIP_OBJECT(content), "sintel trailer content");
linphone_content_set_type(content,"video");
linphone_content_set_subtype(content,"mkv");
linphone_content_set_name(content,"sintel_trailer_opus_h264.mkv");
marieMessage = marieRoom->createFileTransferMessage(content);
marieMessage->setFileTransferFilepath(send_filepath);
FileContent *content = new FileContent();
content->setContentType("video/mkv");
content->setFilePath(send_filepath);
content->setFileName("sintel_trailer_opus_h264.mkv");
marieMessage->addContent(content);
bc_free(send_filepath);
} else {
marieMessage = marieRoom->createMessage("Hello Part 1");
Content *content = new Content();
content->setContentType(ContentType::PlainText);
content->setBody("Hello Part 1");
marieMessage->addContent(content);
}
if (second_file_transfer) {
......
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