diff --git a/coreapi/chat.c b/coreapi/chat.c index 9888c2519..b920b860a 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -543,17 +543,6 @@ void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg) { _linphone_chat_room_send_message(cr, linphone_chat_room_create_message(cr, msg)); } -void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc, LinphoneChatMessage *msg) { - if (msg->message) { - /*legacy API*/ - linphone_core_notify_text_message_received(lc, cr, msg->from, msg->message); - } - linphone_core_notify_message_received(lc, cr, msg); - cr->remote_is_composing = LinphoneIsComposingIdle; - linphone_core_notify_is_composing_received(cr->lc, cr); - linphone_chat_message_send_delivery_notification(msg, LinphoneReasonNone); -} - static bool_t is_file_transfer(const char *content_type) { return (strcmp("application/vnd.gsma.rcs-ft-http+xml", content_type) == 0); } @@ -566,6 +555,23 @@ static bool_t is_imdn(const char *content_type) { return (strcmp("message/imdn+xml", content_type) == 0); } +static bool_t is_text(const char *content_type) { + return (strcmp("text/plain", content_type) == 0); +} + +void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc, LinphoneChatMessage *msg) { + if (msg->message) { + /*legacy API*/ + linphone_core_notify_text_message_received(lc, cr, msg->from, msg->message); + } + linphone_core_notify_message_received(lc, cr, msg); + if(!is_imdn(msg->content_type) && !is_im_iscomposing(msg->content_type)) { + cr->remote_is_composing = LinphoneIsComposingIdle; + linphone_core_notify_is_composing_received(cr->lc, cr); + linphone_chat_message_send_delivery_notification(msg, LinphoneReasonNone); + } +} + static void create_file_transfer_information_from_vnd_gsma_rcs_ft_http_xml(LinphoneChatMessage *msg) { xmlChar *file_url = NULL; xmlDocPtr xmlMessageBody; @@ -718,23 +724,28 @@ LinphoneReason linphone_core_message_received(LinphoneCore *lc, SalOp *op, const if (is_file_transfer(msg->content_type)) { create_file_transfer_information_from_vnd_gsma_rcs_ft_http_xml(msg); + linphone_chat_message_set_to_be_stored(msg, TRUE); } else if (is_im_iscomposing(msg->content_type)) { linphone_chat_room_notify_is_composing(cr, msg->message); - goto end; + linphone_chat_message_set_to_be_stored(msg, FALSE); } else if (is_imdn(msg->content_type)) { linphone_chat_room_notify_imdn(cr, msg->message); - goto end; + linphone_chat_message_set_to_be_stored(msg, FALSE); + } else if (is_text(msg->content_type)) { + linphone_chat_message_set_to_be_stored(msg, TRUE); } - msg->storage_id = linphone_chat_message_store(msg); - - if (cr->unread_count < 0) - cr->unread_count = 1; - else - cr->unread_count++; - linphone_chat_room_message_received(cr, lc, msg); - + + if(linphone_chat_message_get_to_be_stored(msg)) { + msg->storage_id = linphone_chat_message_store(msg); + + if (cr->unread_count < 0) + cr->unread_count = 1; + else + cr->unread_count++; + } + end: linphone_address_unref(addr); if (msg != NULL) linphone_chat_message_unref(msg); @@ -1503,6 +1514,22 @@ void linphone_chat_message_set_content_type(LinphoneChatMessage *msg, const char msg->content_type = content_type ? ms_strdup(content_type) : NULL; } +bool_t linphone_chat_message_is_file_transfer(LinphoneChatMessage *msg) { + return is_file_transfer(msg->content_type); +} + +bool_t linphone_chat_message_is_text(LinphoneChatMessage *msg) { + return is_text(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; +} + const char *linphone_chat_message_get_appdata(const LinphoneChatMessage *msg) { return msg->appdata; } diff --git a/coreapi/private.h b/coreapi/private.h index 72fe5273a..5a5b4734e 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -247,6 +247,7 @@ struct _LinphoneChatMessage { SalOp *op; LinphoneContent *file_transfer_information; /**< used to store file transfer information when the message is of file transfer type */ char *content_type; /**< is used to specified the type of message to be sent, used only for file transfer message */ + bool_t to_be_stored; belle_http_request_t *http_request; /**< keep a reference to the http_request in case of file transfer in order to be able to cancel the transfer */ belle_http_request_listener_t *http_listener; /* our listener, only owned by us*/ char *file_transfer_filepath; diff --git a/include/linphone/chat.h b/include/linphone/chat.h index b041674fa..fc3e89e56 100644 --- a/include/linphone/chat.h +++ b/include/linphone/chat.h @@ -390,6 +390,37 @@ LINPHONE_PUBLIC const char * linphone_chat_message_get_content_type(const Linpho */ LINPHONE_PUBLIC void linphone_chat_message_set_content_type(LinphoneChatMessage *message, const char *content_type); +/** + * Return whether or not a chat message is a file tranfer. + * This content type must match a content that is text representable, such as text/plain, text/html or image/svg+xml. + * @param[in] message LinphoneChatMessage object + * @return Whether or not the message is a file tranfer + */ +LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer(LinphoneChatMessage *message); + +/** + * Return whether or not a chat message is a text. + * This content type must match a content that is text representable, such as text/plain, text/html or image/svg+xml. + * @param[in] message LinphoneChatMessage object + * @return Whether or not the message is a text + */ +LINPHONE_PUBLIC bool_t linphone_chat_message_is_text(LinphoneChatMessage *message); + +/** + * Get if a chat message is to be stored. + * @param[in] message LinphoneChatMessage object + * @return Whether or not the message is to be stored + */ +LINPHONE_PUBLIC bool_t linphone_chat_message_get_to_be_stored(const LinphoneChatMessage *message); + +/** + * Set if a chat message is to be stored. + * This content type must match a content that is text representable, such as text/plain, text/html or image/svg+xml. + * @param[in] message LinphoneChatMessage object + * @param[in] to_be_stored Whether or not the chat message is to be stored + */ +LINPHONE_PUBLIC void linphone_chat_message_set_to_be_stored(LinphoneChatMessage *message, bool_t to_be_stored); + /** * Start the download of the file from remote server * diff --git a/tester/message_tester.c b/tester/message_tester.c index f28cfea1e..e5093421e 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -759,7 +759,7 @@ static void file_transfer_2_messages_simultaneously(void) { linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); linphone_chat_message_download_file(msg2); - BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,2)); + BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,2,50000)); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,4, int, "%d"); BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,2, int, "%d");