From 5290d59d769c90f18f720b07495061ba6dcbbb84 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 5 Apr 2018 17:08:37 +0200 Subject: [PATCH] Various fixes regarding callbacks of chat rooms. --- coreapi/chat.c | 4 ++-- include/linphone/core.h | 5 +++-- src/c-wrapper/api/c-chat-room.cpp | 1 + src/chat/chat-message/chat-message.cpp | 2 +- src/chat/chat-room/chat-room.h | 1 + src/core/core-chat-room.cpp | 4 ++-- src/core/core.h | 2 +- tester/group_chat_tester.c | 10 +++++----- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index ac9c8dcf0..edc8b861b 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -84,8 +84,8 @@ LinphoneChatRoom *linphone_core_get_chat_room (LinphoneCore *lc, const LinphoneA return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getOrCreateBasicChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(addr))); } -LinphoneChatRoom *linphone_core_create_client_group_chat_room (LinphoneCore *lc, const char *subject) { - return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->createClientGroupChatRoom(L_C_TO_STRING(subject))); +LinphoneChatRoom *linphone_core_create_client_group_chat_room (LinphoneCore *lc, const char *subject, bool_t fallback) { + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->createClientGroupChatRoom(L_C_TO_STRING(subject), !!fallback)); } LinphoneChatRoom *_linphone_core_create_server_group_chat_room (LinphoneCore *lc, LinphonePrivate::SalCallOp *op) { diff --git a/include/linphone/core.h b/include/linphone/core.h index 24ae79627..ce01ec878 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -4976,13 +4976,14 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC const char *linphone_core_get_chat_database_ /** * Create a client-side group chat room. When calling this function the chat room is only created - * at the client-side and is empty. Pou need to call linphone_chat_room_add_participants() to + * at the client-side and is empty. You need to call linphone_chat_room_add_participants() to * create at the server side and add participants to it. * @param[in] lc A #LinphoneCore object * @param[in] subject The subject of the group chat room + * @param[in] fallback Boolean value telling whether we should plan on being able to fallback to a basic chat room if the client-side group chat room creation fails * @return The newly created client-side group chat room. */ -LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject); +LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject, bool_t fallback); /** * Get a basic chat room whose peer is the supplied address. If it does not exist yet, it will be created. diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 3e3f7bb4c..faf919bee 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -442,6 +442,7 @@ const bctbx_list_t *linphone_chat_room_get_callbacks_list(const LinphoneChatRoom if (cb) \ cb(__VA_ARGS__); \ } \ + linphone_chat_room_set_current_callbacks(cr, nullptr); \ bctbx_list_free(callbacksCopy); void _linphone_chat_room_notify_is_composing_received(LinphoneChatRoom *cr, const LinphoneAddress *remoteAddr, bool_t isComposing) { diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index 0fcde7521..90eb244c2 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -500,7 +500,7 @@ static void forceUtf8Content (Content &content) { void ChatMessagePrivate::notifyReceiving () { L_Q(); - LinphoneChatRoom *chatRoom = L_GET_C_BACK_PTR(q->getChatRoom()); + LinphoneChatRoom *chatRoom = static_pointer_cast(q->getChatRoom())->getPrivate()->getCChatRoom(); if ((getContentType() != ContentType::Imdn) && (getContentType() != ContentType::ImIsComposing)) { _linphone_chat_room_notify_chat_message_should_be_stored(chatRoom, L_GET_C_BACK_PTR(q->getSharedFromThis())); if (toBeStored) diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index 40cad5ae3..40bc7a05e 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -30,6 +30,7 @@ class ChatRoomPrivate; class LINPHONE_PUBLIC ChatRoom : public AbstractChatRoom { public: + friend class ChatMessagePrivate; friend class ProxyChatRoomPrivate; L_OVERRIDE_SHARED_FROM_THIS(ChatRoom); diff --git a/src/core/core-chat-room.cpp b/src/core/core-chat-room.cpp index b02d072bf..cac503c2c 100644 --- a/src/core/core-chat-room.cpp +++ b/src/core/core-chat-room.cpp @@ -265,9 +265,9 @@ shared_ptr Core::findOneToOneChatRoom ( return nullptr; } -shared_ptr Core::createClientGroupChatRoom (const string &subject) { +shared_ptr Core::createClientGroupChatRoom (const string &subject, bool fallback) { L_D(); - return d->createClientGroupChatRoom(subject); + return d->createClientGroupChatRoom(subject, "", Content(), fallback); } shared_ptr Core::getOrCreateBasicChatRoom (const ChatRoomId &chatRoomId, bool isRtt) { diff --git a/src/core/core.h b/src/core/core.h index a8a15630a..72b037003 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -101,7 +101,7 @@ public: const IdentityAddress &participantAddress ) const; - std::shared_ptr createClientGroupChatRoom (const std::string &subject); + std::shared_ptr createClientGroupChatRoom (const std::string &subject, bool fallback = true); std::shared_ptr createClientGroupChatRoom ( const std::string &subject, const IdentityAddress &localAddress diff --git a/tester/group_chat_tester.c b/tester/group_chat_tester.c index 14c0ab1d0..d1672bb10 100644 --- a/tester/group_chat_tester.c +++ b/tester/group_chat_tester.c @@ -282,7 +282,7 @@ static LinphoneChatRoom * check_creation_chat_room_client_side(bctbx_list_t *lcs } static LinphoneChatRoom * create_chat_room_client_side(bctbx_list_t *lcs, LinphoneCoreManager *lcm, stats *initialStats, bctbx_list_t *participantsAddresses, const char* initialSubject, int expectedParticipantSize) { - LinphoneChatRoom *chatRoom = linphone_core_create_client_group_chat_room(lcm->lc, initialSubject); + LinphoneChatRoom *chatRoom = linphone_core_create_client_group_chat_room(lcm->lc, initialSubject, FALSE); if (!chatRoom) return NULL; BC_ASSERT_TRUE(wait_for_list(lcs, &lcm->stat.number_of_LinphoneChatRoomStateInstantiated, initialStats->number_of_LinphoneChatRoomStateInstantiated + 1, 100)); @@ -2139,7 +2139,7 @@ static void group_chat_room_fallback_to_basic_chat_room (void) { stats initialPaulineStats = pauline->stat; // Marie creates a new group chat room - LinphoneChatRoom *marieCr = linphone_core_create_client_group_chat_room(marie->lc, "Fallback"); + LinphoneChatRoom *marieCr = linphone_core_create_client_group_chat_room(marie->lc, "Fallback", TRUE); BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_LinphoneChatRoomStateInstantiated, initialMarieStats.number_of_LinphoneChatRoomStateInstantiated + 1, 100)); // Add participants @@ -2195,13 +2195,13 @@ static void group_chat_room_creation_fails_if_invited_participants_dont_support_ stats initialMarieStats = marie->stat; // Marie creates a new group chat room - LinphoneChatRoom *marieCr = linphone_core_create_client_group_chat_room(marie->lc, "Hello there"); + LinphoneChatRoom *marieCr = linphone_core_create_client_group_chat_room(marie->lc, "Hello there", FALSE); BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_LinphoneChatRoomStateInstantiated, initialMarieStats.number_of_LinphoneChatRoomStateInstantiated + 1, 100)); // Add participants linphone_chat_room_add_participants(marieCr, participantsAddresses); - // Check that the group chat room creation fails and that a fallback to a basic chat room is done + // Check that the group chat room creation fails BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_LinphoneChatRoomStateCreationPending, initialMarieStats.number_of_LinphoneChatRoomStateCreationPending + 1, 10000)); BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_LinphoneChatRoomStateCreationFailed, initialMarieStats.number_of_LinphoneChatRoomStateCreationFailed + 1, 10000)); bctbx_list_free_with_data(participantsAddresses, (bctbx_list_free_func)linphone_address_unref); @@ -2367,7 +2367,7 @@ static void group_chat_room_migrate_from_basic_to_client_fail (void) { stats initialPaulineStats = pauline->stat; // Marie creates a new group chat room - LinphoneChatRoom *marieCr = linphone_core_create_client_group_chat_room(marie->lc, "Fallback"); + LinphoneChatRoom *marieCr = linphone_core_create_client_group_chat_room(marie->lc, "Fallback", TRUE); BC_ASSERT_TRUE(wait_for_list(coresList, &marie->stat.number_of_LinphoneChatRoomStateInstantiated, initialMarieStats.number_of_LinphoneChatRoomStateInstantiated + 1, 100)); // Add participants