Commit 12cdc62a authored by Sylvain Berfini's avatar Sylvain Berfini 🐮
Browse files

Do not call the message_sent callback on core when message is resent after error

parent 6a3d4ded
......@@ -195,7 +195,9 @@ typedef void (*LinphoneCoreTextMessageReceivedCb)(LinphoneCore *lc, LinphoneChat
typedef void (*LinphoneCoreCbsMessageReceivedCb)(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message);
/**
* Chat message callback prototype
* Called after the #send method of the #LinphoneChatMessage was called.
* The message will be in state InProgress.
* In case of resend this callback won't be called.
* @param lc #LinphoneCore object
* @param room #LinphoneChatRoom involved in this conversation. Can be be created by the framework in case \link #LinphoneAddress the from \endlink is not present in any chat room.
* @param #LinphoneChatMessage outgoing message
......
......@@ -52,6 +52,8 @@ void ChatRoomPrivate::sendChatMessage (const shared_ptr<ChatMessage> &chatMessag
L_Q();
ChatMessagePrivate *dChatMessage = chatMessage->getPrivate();
bool isResend = chatMessage->getState() == ChatMessage::State::NotDelivered;
dChatMessage->setTime(ms_time(0));
if (!q->canHandleCpim()) {
//if not using cpim, ImdnMessageId = SIP Message call id, so should be computed each time, specially in case of resend.
......@@ -68,8 +70,11 @@ void ChatRoomPrivate::sendChatMessage (const shared_ptr<ChatMessage> &chatMessag
if (!event)
event = make_shared<ConferenceChatMessageEvent>(time(nullptr), chatMessage);
_linphone_chat_room_notify_chat_message_sent(cr, L_GET_C_BACK_PTR(event));
linphone_core_notify_message_sent(q->getCore()->getCCore(), cr, L_GET_C_BACK_PTR(chatMessage));
if (!isResend) {
// Do not notify message sent callback when it's a resend
_linphone_chat_room_notify_chat_message_sent(cr, L_GET_C_BACK_PTR(event));
linphone_core_notify_message_sent(q->getCore()->getCCore(), cr, L_GET_C_BACK_PTR(chatMessage));
}
}
if (isComposing)
......
......@@ -200,6 +200,7 @@ typedef struct _stats {
int number_of_LinphoneMessageFileTransferInProgress;
int number_of_LinphoneMessageDeliveredToUser;
int number_of_LinphoneMessageDisplayed;
int number_of_LinphoneMessageSent;
int number_of_LinphoneIsComposingActiveReceived;
int number_of_LinphoneIsComposingIdleReceived;
int progress_of_LinphoneFileTransfer;
......@@ -448,6 +449,7 @@ const char *liblinphone_tester_get_subscribe_content(void);
const char *liblinphone_tester_get_notify_content(void);
void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state);
void liblinphone_tester_chat_room_msg_sent(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg);
void core_chat_room_state_changed (LinphoneCore *core, LinphoneChatRoom *cr, LinphoneChatRoomState state);
void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee);
......
......@@ -345,9 +345,11 @@ static void text_message_with_send_error(void) {
LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageSent, 0, int, "%d");
/*simulate a network error*/
sal_set_send_error(linphone_core_get_sal(marie->lc), -1);
linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
linphone_chat_message_send(msg);
char *message_id = ms_strdup(linphone_chat_message_get_message_id(msg));
BC_ASSERT_STRING_NOT_EQUAL(message_id, "");
......@@ -363,10 +365,13 @@ static void text_message_with_send_error(void) {
/* the msg should have been discarded from transient list after an error */
BC_ASSERT_EQUAL(_linphone_chat_room_get_transient_message_count(chat_room), 0, int, "%d");
// Even if error the message should be notified in sent callback
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageSent, 1, int, "%d");
sal_set_send_error(linphone_core_get_sal(marie->lc), 0);
// resend the message
linphone_chat_message_send(msg);
linphone_chat_message_resend(msg);
const char *message_id_2 = linphone_chat_message_get_message_id(msg);
BC_ASSERT_STRING_NOT_EQUAL(message_id_2, "");
......@@ -378,6 +383,9 @@ static void text_message_with_send_error(void) {
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageDeliveredToUser,1));
BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived, 1, int, "%d");
// In case of resend the send callback should not be called again
BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageSent, 1, int, "%d");
/*give a chance to register again to allow linphone_core_manager_destroy to properly unregister*/
linphone_core_refresh_registers(marie->lc);
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneRegistrationOk,marie->stat.number_of_LinphoneRegistrationOk + 1));
......
......@@ -463,6 +463,7 @@ void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, c
linphone_core_cbs_set_dtmf_received(mgr->cbs, dtmf_received);
linphone_core_cbs_set_call_stats_updated(mgr->cbs, call_stats_updated);
linphone_core_cbs_set_global_state_changed(mgr->cbs, global_state_changed);
linphone_core_cbs_set_message_sent(mgr->cbs, liblinphone_tester_chat_room_msg_sent);
mgr->phone_alias = phone_alias ? ms_strdup(phone_alias) : NULL;
......@@ -1526,6 +1527,11 @@ void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg,
ms_error("Unexpected state [%s] for msg [%p]",linphone_chat_message_state_to_string(state), msg);
}
void liblinphone_tester_chat_room_msg_sent(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
stats *counters = get_stats(lc);
counters->number_of_LinphoneMessageSent++;
}
/*
* function called when the file transfer is initiated. file content should be feed into object LinphoneContent
* */
......
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