diff --git a/coreapi/chat.c b/coreapi/chat.c index 64f041fef..ff427e12b 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -38,6 +38,7 @@ #include "c-wrapper/c-wrapper.h" #include "chat/chat-room/basic-chat-room.h" #include "chat/chat-room/client-group-chat-room.h" +#include "chat/chat-room/client-group-to-basic-chat-room.h" #include "chat/chat-room/real-time-text-chat-room-p.h" #include "chat/chat-room/real-time-text-chat-room.h" #include "content/content-type.h" @@ -131,10 +132,24 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, localAddress = op->get_to(); } - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( - LinphonePrivate::ChatRoomId(LinphonePrivate::IdentityAddress(peerAddress), LinphonePrivate::IdentityAddress(localAddress)) + // TODO: remove when using signals + LinphoneChatRoom *cr = L_GET_C_BACK_PTR( + L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom( + LinphonePrivate::ChatRoomId(LinphonePrivate::IdentityAddress(peerAddress), + LinphonePrivate::IdentityAddress(localAddress) + )) ); + if (!cr) + return LinphoneReasonNone; + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(cr); + shared_ptr acr; + if (chatRoom->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::Proxy) + acr = static_pointer_cast(chatRoom)->getProxiedChatRoom(); + else + acr = chatRoom; + + L_SET_CPP_PTR_FROM_C_OBJECT(cr, acr); if (chatRoom) reason = L_GET_PRIVATE(chatRoom)->onSipMessageReceived(op, sal_msg); else { @@ -145,6 +160,7 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->onSipMessageReceived(op, sal_msg); linphone_address_unref(addr); } + L_SET_CPP_PTR_FROM_C_OBJECT(cr, chatRoom); return reason; } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 97f03e056..1b79ba040 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2136,10 +2136,14 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve const LinphoneAddress *resource = linphone_event_get_resource(lev); const LinphoneAddress *from = linphone_event_get_from(lev); - shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( - IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), - IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(from)) - )); + // TODO: remove when using signals + LinphoneChatRoom *cr = L_GET_C_BACK_PTR( + L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId( + IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)), + IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(from)) + )) + ); + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(cr); if (chatRoom) { shared_ptr cgcr; @@ -2148,6 +2152,8 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve static_pointer_cast(chatRoom)->getProxiedChatRoom()); else cgcr = static_pointer_cast(chatRoom); + + L_SET_CPP_PTR_FROM_C_OBJECT(cr, cgcr); if (linphone_content_is_multipart(body)) { // TODO : migrate to c++ 'Content'. int i = 0; @@ -2158,6 +2164,8 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve } } else L_GET_PRIVATE(cgcr)->notifyReceived(linphone_content_get_string_buffer(body)); + + L_SET_CPP_PTR_FROM_C_OBJECT(cr, chatRoom); } } } diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index cd6a94f94..b625af3a4 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -28,6 +28,7 @@ #include "chat/chat-message/chat-message-p.h" #include "chat/chat-room/chat-room-p.h" +#include "chat/chat-room/client-group-to-basic-chat-room.h" #include "chat/chat-room/real-time-text-chat-room.h" #include "chat/modifier/cpim-chat-message-modifier.h" #include "chat/modifier/encryption-chat-message-modifier.h" @@ -857,7 +858,20 @@ void ChatMessage::send () { return; } - getChatRoom()->getPrivate()->sendChatMessage(getSharedFromThis()); + // TODO: remove when using signals + LinphoneChatRoom *cr = L_GET_C_BACK_PTR(getCore()->findChatRoom(getChatRoom()->getChatRoomId())); + + shared_ptr chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(cr); + + shared_ptr acr; + if (chatRoom->getCapabilities() & LinphonePrivate::ChatRoom::Capabilities::Proxy) + acr = static_pointer_cast(chatRoom)->getProxiedChatRoom(); + else + acr = chatRoom; + + L_SET_CPP_PTR_FROM_C_OBJECT(cr, acr); + acr->getPrivate()->sendChatMessage(getSharedFromThis()); + L_SET_CPP_PTR_FROM_C_OBJECT(cr, chatRoom); } void ChatMessage::sendDeliveryNotification (LinphoneReason reason) { diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 64ef93d21..d91587f7b 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -52,7 +52,7 @@ void ChatRoomPrivate::sendChatMessage (const shared_ptr &chatMessag LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); - LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_chat_message_sent(cbs); + LinphoneChatRoomCbsChatMessageSentCb cb = linphone_chat_room_cbs_get_chat_message_sent(cbs); // TODO: server currently don't stock message, remove condition in the future. if (cb && !linphone_core_conference_server_enabled(q->getCore()->getCCore())) {