diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 07de8fa2b..ebfda5738 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -555,17 +555,14 @@ static LinphoneChatMessageState chatStatusSal2Linphone(SalMessageDeliveryStatus return LinphoneChatMessageStateIdle; } -static void message_delivery_update(SalOp *op, SalMessageDeliveryStatus status){ - LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )op->get_user_pointer(); +static void message_delivery_update(SalOp *op, SalMessageDeliveryStatus status) { + LinphonePrivate::ChatMessage *msg = reinterpret_cast(op->get_user_pointer()); + if (!msg) + return; // Do not handle delivery status for isComposing messages. - if (chat_msg == NULL) { - // Do not handle delivery status for isComposing messages. - return; - } - // check that the message does not belong to an already destroyed chat room - if so, do not invoke callbacks - if (linphone_chat_message_get_chat_room(chat_msg) != NULL) { - linphone_chat_message_update_state(chat_msg, chatStatusSal2Linphone(status)); - } + // Check that the message does not belong to an already destroyed chat room - if so, do not invoke callbacks + if (msg->getChatRoom()) + msg->updateState((LinphonePrivate::ChatMessage::State)chatStatusSal2Linphone(status)); } static void info_received(SalOp *op, SalBodyHandler *body_handler) { diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index a040301fe..19d341955 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -543,7 +543,7 @@ void ChatMessagePrivate::send () { core->getCCore(), op, peer, getSalCustomHeaders(), !!lp_config_get_int(core->getCCore()->config, "sip", "chat_msg_with_contact", 0) ); - op->set_user_pointer(L_GET_C_BACK_PTR(q)); /* If out of call, directly store msg */ + op->set_user_pointer(q); /* If out of call, directly store msg */ linphone_address_unref(peer); } op->set_from(q->getFromAddress().asString().c_str()); @@ -712,8 +712,10 @@ ChatMessage::~ChatMessage () { for (Content *content : d->contents) delete content; - if (d->salOp) - d->salOp->release(); + if (d->salOp) { + d->salOp->set_user_pointer(nullptr); + d->salOp->unref(); + } if (d->salCustomHeaders) sal_custom_header_unref(d->salCustomHeaders); }