diff --git a/src/c-wrapper/api/c-chat-message.cpp b/src/c-wrapper/api/c-chat-message.cpp index 9fe96f8b4..0b0ead9b3 100644 --- a/src/c-wrapper/api/c-chat-message.cpp +++ b/src/c-wrapper/api/c-chat-message.cpp @@ -43,7 +43,6 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(ChatMessage, LinphoneChatMessageCbs *cbs; LinphoneAddress *from; // cache for shared_ptr
LinphoneAddress *to; // cache for shared_ptr
- LinphoneErrorInfo *ei; LinphoneChatMessageStateChangedCb message_state_changed_cb; void* message_state_changed_user_data; ) @@ -245,6 +244,10 @@ const char *linphone_chat_message_get_custom_header(LinphoneChatMessage *msg, co return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getSalCustomHeaderValue(header_name).c_str(); } +const LinphoneErrorInfo *linphone_chat_message_get_error_info(LinphoneChatMessage *msg) { + return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getErrorInfo(); +} + // ============================================================================= // Methods // ============================================================================= @@ -273,19 +276,16 @@ void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMe L_GET_CPP_PTR_FROM_C_OBJECT(msg)->updateState((LinphonePrivate::ChatMessage::State) new_state); } void linphone_chat_message_send_imdn(LinphoneChatMessage *msg, ImdnType imdn_type, LinphoneReason reason) { - //TODO - L_GET_CPP_PTR_FROM_C_OBJECT(msg)->sendImdn(); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->sendImdn(imdn_type, reason); } void linphone_chat_message_deactivate(LinphoneChatMessage *msg){ L_GET_CPP_PTR_FROM_C_OBJECT(msg)->cancelFileTransfer(); - // TODO ? - //msg->chat_room = NULL; + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setChatRoom(nullptr); } void linphone_chat_message_send_delivery_notification(LinphoneChatMessage *msg, LinphoneReason reason) { - //TODO - L_GET_CPP_PTR_FROM_C_OBJECT(msg)->sendDeliveryNotification(); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->sendDeliveryNotification(reason); } void linphone_chat_message_send_display_notification(LinphoneChatMessage *msg) { @@ -334,14 +334,11 @@ int linphone_chat_message_set_text(LinphoneChatMessage *msg, const char* text) { } LinphoneContent *linphone_chat_message_get_file_transfer_information(LinphoneChatMessage *msg) { - //return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFileTransferInformation(); - //TODO - return NULL; + return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFileTransferInformation(); } void linphone_chat_message_set_file_transfer_information(LinphoneChatMessage *msg, LinphoneContent *content) { - //TODO - L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setFileTransferInformation(nullptr); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setFileTransferInformation(content); } // ============================================================================= @@ -359,12 +356,6 @@ const LinphoneAddress *linphone_chat_message_get_local_address(LinphoneChatMessa return linphone_chat_message_get_to_address(msg); } -const LinphoneErrorInfo *linphone_chat_message_get_error_info(const LinphoneChatMessage *msg) { - if (!msg->ei) ((LinphoneChatMessage*)msg)->ei = linphone_error_info_new(); /*let's do it mutable*/ - linphone_error_info_from_sal_op(msg->ei, linphone_chat_message_get_sal_op(msg)); - return msg->ei; -} - LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage *msg) { return linphone_error_info_get_reason(linphone_chat_message_get_error_info(msg)); } diff --git a/src/chat/chat-message-p.h b/src/chat/chat-message-p.h index 2b756812f..17da7bb79 100644 --- a/src/chat/chat-message-p.h +++ b/src/chat/chat-message-p.h @@ -54,10 +54,14 @@ private: std::shared_ptr internalContent; std::unordered_map customHeaders; std::shared_ptr eventsDb; - std::shared_ptr errorInfo; + LinphoneErrorInfo * errorInfo; belle_http_request_t *httpRequest; SalOp *salOp; SalCustomHeader *salCustomHeaders; + // Used for compatibility with previous C API + std::string cContentType; + std::string cText; + LinphoneContent *cFileTransferInformation; L_DECLARE_PUBLIC(ChatMessage); }; diff --git a/src/chat/chat-message.cpp b/src/chat/chat-message.cpp index c9bc60bae..325fcce97 100644 --- a/src/chat/chat-message.cpp +++ b/src/chat/chat-message.cpp @@ -37,14 +37,18 @@ LINPHONE_BEGIN_NAMESPACE using namespace std; -// ----------------------------------------------------------------------------- +// ============================================================================= +// ChatMessagePrivate +// ============================================================================= ChatMessagePrivate::ChatMessagePrivate (const shared_ptr &room) : chatRoom(room) {} ChatMessagePrivate::~ChatMessagePrivate () {} -// ----------------------------------------------------------------------------- +// ============================================================================= +// ChatMessage +// ============================================================================= ChatMessage::ChatMessage (const shared_ptr &room) : Object(*new ChatMessagePrivate(room)) {} @@ -59,6 +63,11 @@ shared_ptr ChatMessage::getChatRoom () const { return d->chatRoom; } +void ChatMessage::setChatRoom (shared_ptr chatRoom) { + L_D(ChatMessage); + d->chatRoom = chatRoom; +} + // ----------------------------------------------------------------------------- string ChatMessage::getExternalBodyUrl() const { @@ -215,41 +224,32 @@ void ChatMessage::setIsToBeStored(bool store) { string ChatMessage::getContentType() const { L_D(const ChatMessage); - if (d->internalContent) { - return d->internalContent->getContentType().asString(); - } - if (d->contents.size() > 0) { - return d->contents.front()->getContentType().asString(); - } - return ""; + return d->cContentType; } void ChatMessage::setContentType(string contentType) { - //TODO + L_D(ChatMessage); + d->cContentType = contentType; } string ChatMessage::getText() const { L_D(const ChatMessage); - if (d->internalContent) { - return d->internalContent->getBodyAsString(); - } - if (d->contents.size() > 0) { - return d->contents.front()->getBodyAsString(); - } - return ""; + return d->cText; } void ChatMessage::setText(string text) { - //TODO + L_D(ChatMessage); + d->cText = text; } -shared_ptr ChatMessage::getFileTransferInformation() const { - //TODO - return nullptr; +LinphoneContent * ChatMessage::getFileTransferInformation() const { + L_D(const ChatMessage); + return d->cFileTransferInformation; } -void ChatMessage::setFileTransferInformation(shared_ptr content) { - //TODO +void ChatMessage::setFileTransferInformation(LinphoneContent *content) { + L_D(ChatMessage); + d->cFileTransferInformation = content; } unsigned int ChatMessage::getStorageId() const { @@ -307,12 +307,64 @@ string ChatMessage::getSalCustomHeaderValue(string name) { return sal_custom_header_find(d->salCustomHeaders, name.c_str()); } -shared_ptr ChatMessage::getErrorInfo () const { - L_D(const ChatMessage); - //TODO +const LinphoneErrorInfo * ChatMessage::getErrorInfo() { + L_D(ChatMessage); + if (!d->errorInfo) d->errorInfo = linphone_error_info_new(); //let's do it mutable + linphone_error_info_from_sal_op(d->errorInfo, d->salOp); return d->errorInfo; } +bool ChatMessage::isReadOnly () const { + L_D(const ChatMessage); + return d->isReadOnly; +} + +list > ChatMessage::getContents () const { + L_D(const ChatMessage); + list > contents; + for (const auto &content : d->contents) + contents.push_back(content); + return contents; +} + +void ChatMessage::addContent (const shared_ptr &content) { + L_D(ChatMessage); + if (d->isReadOnly) return; + + d->contents.push_back(content); +} + +void ChatMessage::removeContent (const shared_ptr &content) { + L_D(ChatMessage); + if (d->isReadOnly) return; + + d->contents.remove(const_pointer_cast(content)); +} + +string ChatMessage::getCustomHeaderValue (const string &headerName) const { + L_D(const ChatMessage); + try { + return d->customHeaders.at(headerName); + } catch (const exception &) { + // Key doesn't exist. + } + return ""; +} + +void ChatMessage::addCustomHeader (const string &headerName, const string &headerValue) { + L_D(ChatMessage); + if (d->isReadOnly) return; + + d->customHeaders[headerName] = headerValue; +} + +void ChatMessage::removeCustomHeader (const string &headerName) { + L_D(ChatMessage); + if (d->isReadOnly) return; + + d->customHeaders.erase(headerName); +} + // ----------------------------------------------------------------------------- void ChatMessage::updateState(State state) { @@ -325,6 +377,26 @@ void ChatMessage::updateState(State state) { }*/ } +void ChatMessage::send () { + L_D(ChatMessage); + + if (d->contents.size() > 1) { + MultipartChatMessageModifier mcmm; + mcmm.encode(d); + } + + LinphoneCore *lc = getChatRoom()->getCore(); + LpConfig *lpc = linphone_core_get_config(lc); + if (lp_config_get_int(lpc, "sip", "use_cpim", 0) == 1) { + CpimChatMessageModifier ccmm; + ccmm.encode(d); + } + + // TODO. + + d->isReadOnly = true; +} + void ChatMessage::reSend() { //TODO /*LinphoneChatMessageState state = linphone_chat_message_get_state(msg); @@ -482,7 +554,7 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle return content; }*/ -void ChatMessage::sendImdn() { +void ChatMessage::sendImdn(ImdnType imdnType, LinphoneReason reason) { //TODO /*char *content = linphone_chat_message_create_imdn_xml(cm, imdn_type, reason); if (content) { @@ -491,7 +563,7 @@ void ChatMessage::sendImdn() { }*/ } -void ChatMessage::sendDeliveryNotification() { +void ChatMessage::sendDeliveryNotification(LinphoneReason reason) { //TODO /*LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(cm); LinphoneCore *lc = linphone_chat_room_get_core(cr); @@ -1122,82 +1194,4 @@ int ChatMessage::putCharacter(uint32_t character) { return -1; } -// ----------------------------------------------------------------------------- - -void ChatMessage::send () { - L_D(ChatMessage); - - if (d->contents.size() > 1) { - MultipartChatMessageModifier mcmm; - mcmm.encode(d); - } - - LinphoneCore *lc = getChatRoom()->getCore(); - LpConfig *lpc = linphone_core_get_config(lc); - if (lp_config_get_int(lpc, "sip", "use_cpim", 0) == 1) { - CpimChatMessageModifier ccmm; - ccmm.encode(d); - } - - // TODO. - - d->isReadOnly = true; -} - -bool ChatMessage::containsReadableText () const { - // TODO: Check content type. - return true; -} - -bool ChatMessage::isReadOnly () const { - L_D(const ChatMessage); - return d->isReadOnly; -} - -list > ChatMessage::getContents () const { - L_D(const ChatMessage); - list > contents; - for (const auto &content : d->contents) - contents.push_back(content); - return contents; -} - -void ChatMessage::addContent (const shared_ptr &content) { - L_D(ChatMessage); - if (d->isReadOnly) return; - - d->contents.push_back(content); -} - -void ChatMessage::removeContent (const shared_ptr &content) { - L_D(ChatMessage); - if (d->isReadOnly) return; - - d->contents.remove(const_pointer_cast(content)); -} - -string ChatMessage::getCustomHeaderValue (const string &headerName) const { - L_D(const ChatMessage); - try { - return d->customHeaders.at(headerName); - } catch (const exception &) { - // Key doesn't exist. - } - return ""; -} - -void ChatMessage::addCustomHeader (const string &headerName, const string &headerValue) { - L_D(ChatMessage); - if (d->isReadOnly) return; - - d->customHeaders[headerName] = headerValue; -} - -void ChatMessage::removeCustomHeader (const string &headerName) { - L_D(ChatMessage); - if (d->isReadOnly) return; - - d->customHeaders.erase(headerName); -} - LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-message.h b/src/chat/chat-message.h index 7faa8be72..1c4ccc43f 100644 --- a/src/chat/chat-message.h +++ b/src/chat/chat-message.h @@ -64,16 +64,16 @@ public: LinphoneChatMessage * getBackPtr(); std::shared_ptr getChatRoom () const; - void setChatRoom (std::shared_ptr cr); // ----------------------------------------------------------------------------- // Methods // ----------------------------------------------------------------------------- void updateState(State state); + void send(); void reSend(); - void sendImdn(); - void sendDeliveryNotification(); + void sendImdn(ImdnType imdnType, LinphoneReason reason); + void sendDeliveryNotification(LinphoneReason reason); void sendDisplayNotification(); int uploadFile(); int downloadFile(); @@ -119,10 +119,24 @@ public: bool isToBeStored() const; void setIsToBeStored(bool store); + + const LinphoneErrorInfo * getErrorInfo (); + + bool isReadOnly () const; + + std::list > getContents () const; + void addContent (const std::shared_ptr &content); + void removeContent (const std::shared_ptr &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); // ----------------------------------------------------------------------------- // Deprecated methods, only used for C wrapper // ----------------------------------------------------------------------------- + + void setChatRoom (std::shared_ptr chatRoom); std::string getContentType() const; void setContentType(std::string contentType); @@ -130,8 +144,8 @@ public: std::string getText() const; void setText(std::string text); - std::shared_ptr getFileTransferInformation() const; - void setFileTransferInformation(std::shared_ptr content); + LinphoneContent * getFileTransferInformation() const; + void setFileTransferInformation(LinphoneContent *content); unsigned int getStorageId() const; void setStorageId(unsigned int id); @@ -150,24 +164,6 @@ public: void addSalCustomHeader(std::string name, std::string value); void removeSalCustomHeader(std::string name); std::string getSalCustomHeaderValue(std::string name); - - // ----------------------------------------------------------------------------- - - std::shared_ptr getErrorInfo () const; - - void send (); - - bool containsReadableText () const; - - bool isReadOnly () const; - - std::list > getContents () const; - void addContent (const std::shared_ptr &content); - void removeContent (const std::shared_ptr &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); protected: explicit ChatMessage (ChatMessagePrivate &p);