to_be_stored_api && do not filter SIP message notified to app

This commit is contained in:
Benjamin Reis 2017-02-28 17:00:29 +01:00
parent e71c6a8c10
commit b18702cf9e
4 changed files with 81 additions and 22 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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
*

View file

@ -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");