From 0d0256698e33452efc87dbf7936a7aba778256a3 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 25 Sep 2017 17:29:41 +0200 Subject: [PATCH] More work on C to CPP ChatMessage --- coreapi/private.h | 1 - src/c-wrapper/api/c-chat-message.cpp | 141 ++++++++++++--------------- src/chat/chat-message-p.h | 1 - src/chat/chat-message.cpp | 13 ++- src/chat/chat-message.h | 1 - src/chat/chat-room.cpp | 1 - 6 files changed, 69 insertions(+), 89 deletions(-) diff --git a/coreapi/private.h b/coreapi/private.h index 3899a8509..0cd36ff8e 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1090,7 +1090,6 @@ void linphone_chat_message_set_message_state_changed_cb_user_data(LinphoneChatMe void * linphone_chat_message_get_message_state_changed_cb_user_data(LinphoneChatMessage* msg); void linphone_chat_message_set_state(LinphoneChatMessage *msg, LinphoneChatMessageState state); void linphone_chat_message_set_message_id(LinphoneChatMessage *msg, char *id); -void linphone_chat_message_set_is_read(LinphoneChatMessage *msg, bool_t is_read); void linphone_chat_message_set_storage_id(LinphoneChatMessage *msg, unsigned int id); SalCustomHeader * linphone_chat_message_get_sal_custom_headers(const LinphoneChatMessage *msg); void linphone_chat_message_set_sal_custom_headers(LinphoneChatMessage *msg, SalCustomHeader *header); diff --git a/src/c-wrapper/api/c-chat-message.cpp b/src/c-wrapper/api/c-chat-message.cpp index d8292eaf2..3a8bc06d5 100644 --- a/src/c-wrapper/api/c-chat-message.cpp +++ b/src/c-wrapper/api/c-chat-message.cpp @@ -97,11 +97,18 @@ void linphone_chat_message_set_user_data (LinphoneChatMessage *msg, void *ud) { L_SET_USER_DATA_FROM_C_OBJECT(msg, ud); } +LinphoneChatMessageCbs *linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg) { + return msg->cbs; +} // ============================================================================= // Getter and setters // ============================================================================= +LinphoneChatRoom *linphone_chat_message_get_chat_room(const LinphoneChatMessage *msg) { + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getChatRoom()); +} + const char *linphone_chat_message_get_external_body_url(const LinphoneChatMessage *msg) { return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getExternalBodyUrl().c_str(); } @@ -130,6 +137,10 @@ bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage *msg) { return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isOutgoing(); } +LinphoneChatMessageDir linphone_chat_message_get_direction(const LinphoneChatMessage *msg) { + return ((LinphoneChatMessageDir)L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getDirection()); +} + void linphone_chat_message_set_incoming(LinphoneChatMessage *msg) { L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setDirection(LinphonePrivate::ChatMessage::Direction::Incoming); } @@ -170,10 +181,8 @@ void linphone_chat_message_set_storage_id(LinphoneChatMessage *msg, unsigned int L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setStorageId(id); } -void linphone_chat_message_set_is_read(LinphoneChatMessage *msg, bool_t is_read) { - if (is_read) { - L_GET_CPP_PTR_FROM_C_OBJECT(msg)->markAsRead(); - } +bool_t linphone_chat_message_is_read(LinphoneChatMessage *msg) { + return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isRead(); } const char *linphone_chat_message_get_appdata(const LinphoneChatMessage *msg) { @@ -211,8 +220,6 @@ const LinphoneAddress *linphone_chat_message_get_to_address(const LinphoneChatMe return NULL; } -// ============================================================================= - void linphone_chat_message_set_message_state_changed_cb(LinphoneChatMessage* msg, LinphoneChatMessageStateChangedCb cb) { msg->message_state_changed_cb = cb; } @@ -243,6 +250,10 @@ int linphone_chat_message_set_text(LinphoneChatMessage *msg, const char* text) { return 0; } +LinphoneContent *linphone_chat_message_get_file_transfer_information(LinphoneChatMessage *msg) { + return msg->file_transfer_information; +} + SalCustomHeader * linphone_chat_message_get_sal_custom_headers(const LinphoneChatMessage *msg) { return msg->sal_custom_headers; } @@ -263,14 +274,6 @@ void linphone_chat_message_set_file_transfer_information(LinphoneChatMessage *ms msg->file_transfer_information = content; } -LinphoneChatMessageDir linphone_chat_message_get_direction(const LinphoneChatMessage *msg) { - return msg->dir; -} - -LinphoneChatRoom *linphone_chat_message_get_chat_room(const LinphoneChatMessage *msg) { - return msg->chat_room; -} - SalOp * linphone_chat_message_get_sal_op(const LinphoneChatMessage *msg) { return msg->op; } @@ -287,6 +290,52 @@ const char *linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage return msg->file_transfer_filepath; } +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, msg->op); + return msg->ei; +} + +LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage *msg) { + return linphone_error_info_get_reason(linphone_chat_message_get_error_info(msg)); +}const LinphoneAddress *linphone_chat_message_get_peer_address(LinphoneChatMessage *msg) { + return linphone_chat_room_get_peer_address(msg->chat_room); +} + +bool_t linphone_chat_message_is_file_transfer(const LinphoneChatMessage *msg) { + return LinphonePrivate::ContentType::isFileTransfer(msg->content_type); +} + +bool_t linphone_chat_message_is_text(const LinphoneChatMessage *msg) { + return LinphonePrivate::ContentType::isText(msg->content_type); +} + +bool_t linphone_chat_message_get_to_be_stored(const LinphoneChatMessage *msg) { + return msg->to_be_stored; +} + +void linphone_chat_message_set_to_be_stored(LinphoneChatMessage *msg, bool_t to_be_stored) { + msg->to_be_stored = to_be_stored; +} + +LinphoneAddress *linphone_chat_message_get_local_address(const LinphoneChatMessage *msg) { + return msg->dir == LinphoneChatMessageOutgoing ? msg->from : msg->to; +} + +void linphone_chat_message_add_custom_header(LinphoneChatMessage *msg, const char *header_name, + const char *header_value) { + msg->sal_custom_headers = sal_custom_header_append(msg->sal_custom_headers, header_name, header_value); +} + +const char *linphone_chat_message_get_custom_header(LinphoneChatMessage *msg, const char *header_name) { + return sal_custom_header_find(msg->sal_custom_headers, header_name); +} + +void linphone_chat_message_remove_custom_header(LinphoneChatMessage *msg, const char *header_name) { + msg->sal_custom_headers = sal_custom_header_remove(msg->sal_custom_headers, header_name); +} + +// ============================================================================= // ============================================================================= void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state) { @@ -508,52 +557,6 @@ const char *linphone_chat_message_state_to_string(const LinphoneChatMessageState return NULL; } -const LinphoneAddress *linphone_chat_message_get_peer_address(LinphoneChatMessage *msg) { - return linphone_chat_room_get_peer_address(msg->chat_room); -} - -bool_t linphone_chat_message_is_file_transfer(const LinphoneChatMessage *msg) { - return LinphonePrivate::ContentType::isFileTransfer(msg->content_type); -} - -bool_t linphone_chat_message_is_text(const LinphoneChatMessage *msg) { - return LinphonePrivate::ContentType::isText(msg->content_type); -} - -bool_t linphone_chat_message_get_to_be_stored(const LinphoneChatMessage *msg) { - return msg->to_be_stored; -} - -void linphone_chat_message_set_to_be_stored(LinphoneChatMessage *msg, bool_t to_be_stored) { - msg->to_be_stored = to_be_stored; -} - -LinphoneAddress *linphone_chat_message_get_local_address(const LinphoneChatMessage *msg) { - return msg->dir == LinphoneChatMessageOutgoing ? msg->from : msg->to; -} - -void linphone_chat_message_add_custom_header(LinphoneChatMessage *msg, const char *header_name, - const char *header_value) { - msg->sal_custom_headers = sal_custom_header_append(msg->sal_custom_headers, header_name, header_value); -} - -const char *linphone_chat_message_get_custom_header(LinphoneChatMessage *msg, const char *header_name) { - return sal_custom_header_find(msg->sal_custom_headers, header_name); -} - -void linphone_chat_message_remove_custom_header(LinphoneChatMessage *msg, const char *header_name) { - msg->sal_custom_headers = sal_custom_header_remove(msg->sal_custom_headers, header_name); -} - -bool_t linphone_chat_message_is_read(LinphoneChatMessage *msg) { - LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg); - LinphoneCore *lc = linphone_chat_room_get_core(cr); - LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc); - if ((linphone_im_notif_policy_get_recv_imdn_displayed(policy) == TRUE) && (msg->state == LinphoneChatMessageStateDisplayed)) return TRUE; - if ((linphone_im_notif_policy_get_recv_imdn_delivered(policy) == TRUE) && (msg->state == LinphoneChatMessageStateDeliveredToUser || msg->state == LinphoneChatMessageStateDisplayed)) return TRUE; - return (msg->state == LinphoneChatMessageStateDelivered || msg->state == LinphoneChatMessageStateDisplayed || msg->state == LinphoneChatMessageStateDeliveredToUser); -} - LinphoneChatMessage *linphone_chat_message_clone(const LinphoneChatMessage *msg) { LinphoneChatMessage *new_message = linphone_chat_room_create_message(msg->chat_room, msg->message); if (msg->external_body_url) @@ -588,20 +591,6 @@ void linphone_chat_message_release(LinphoneChatMessage *msg) { linphone_chat_message_unref(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, msg->op); - return msg->ei; -} - -LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage *msg) { - return linphone_error_info_get_reason(linphone_chat_message_get_error_info(msg)); -} - -LinphoneChatMessageCbs *linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg) { - return msg->cbs; -} - static bool_t file_transfer_in_progress_and_valid(LinphoneChatMessage* msg) { return (linphone_chat_message_get_chat_room(msg) && linphone_chat_room_get_core(linphone_chat_message_get_chat_room(msg)) && @@ -937,10 +926,6 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co } } -LinphoneContent *linphone_chat_message_get_file_transfer_information(LinphoneChatMessage *msg) { - return msg->file_transfer_information; -} - static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t *m, void *data, size_t offset, uint8_t *buffer, size_t size) { LinphoneChatMessage *msg = (LinphoneChatMessage *)data; LinphoneCore *lc = NULL; diff --git a/src/chat/chat-message-p.h b/src/chat/chat-message-p.h index d39522ce7..0145f1187 100644 --- a/src/chat/chat-message-p.h +++ b/src/chat/chat-message-p.h @@ -46,7 +46,6 @@ private: time_t time = 0; std::string id; std::string appData; - bool isRead = false; bool isSecured = false; bool isReadOnly = false; std::list > contents; diff --git a/src/chat/chat-message.cpp b/src/chat/chat-message.cpp index 3d2575047..de28edd49 100644 --- a/src/chat/chat-message.cpp +++ b/src/chat/chat-message.cpp @@ -151,13 +151,12 @@ void ChatMessage::setId (string id) { } bool ChatMessage::isRead() const { - L_D(const ChatMessage); - return d->isRead; -} - -void ChatMessage::markAsRead() { - L_D(ChatMessage); - d->isRead = true; + //L_D(const ChatMessage); + return false; + /*shared_ptr policy =d->chatRoom->core->getImNotifPolicy(); + if (policy->getRecvImdnDisplayed() && d->state == Displayed) return true; + if (policy->getRecvImdnDelivered() && (d->state == DeliveredToUser || d->state == Displayed)) return true; + return d->state == Delivered || d->state == Displayed || d->state == DeliveredToUser;*/ } // ----------------------------------------------------------------------------- diff --git a/src/chat/chat-message.h b/src/chat/chat-message.h index b2f903776..c14a4998e 100644 --- a/src/chat/chat-message.h +++ b/src/chat/chat-message.h @@ -85,7 +85,6 @@ public: void setId (std::string); bool isRead() const; - void markAsRead(); std::string getAppdata () const; void setAppdata (const std::string &appData); diff --git a/src/chat/chat-room.cpp b/src/chat/chat-room.cpp index 19774db04..29102a8fb 100644 --- a/src/chat/chat-room.cpp +++ b/src/chat/chat-room.cpp @@ -286,7 +286,6 @@ int ChatRoomPrivate::createChatMessageFromDb (int argc, char **argv, char **colN linphone_address_unref(peer); linphone_chat_message_set_time(newMessage, (time_t)atol(argv[9])); - linphone_chat_message_set_is_read(newMessage, !!atoi(argv[6])); linphone_chat_message_set_state(newMessage, static_cast(atoi(argv[7]))); linphone_chat_message_set_storage_id(newMessage, storageId); linphone_chat_message_set_external_body_url(newMessage, ms_strdup(argv[8]));