diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index d604bf8e0..0386a1016 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -537,8 +537,6 @@ void ChatRoomPrivate::onIsComposingRefreshNeeded () { // ============================================================================= -ChatRoom::ChatRoom (LinphoneCore *core) : Object(*new ChatRoomPrivate(core)) {} - ChatRoom::ChatRoom (ChatRoomPrivate &p) : Object(p) {} // ----------------------------------------------------------------------------- diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index fc883fb6b..b0e29e3ef 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -43,7 +43,6 @@ public: typedef int CapabilitiesMask; - ChatRoom (LinphoneCore *core); virtual ~ChatRoom () = default; virtual CapabilitiesMask getCapabilities () const = 0; diff --git a/src/core/core-chat-room.cpp b/src/core/core-chat-room.cpp index fd3b50175..5cbe89f40 100644 --- a/src/core/core-chat-room.cpp +++ b/src/core/core-chat-room.cpp @@ -45,6 +45,16 @@ static inline Address getCleanedPeerAddress (const Address &peerAddress) { return cleanedAddress; } +// TODO: Remove me later. +static inline string resolveWorkaroundClientGroupChatRoomAddress ( + const CorePrivate &corePrivate, + const Address &peerAddress +) { + Address workaroundAddress = peerAddress; + workaroundAddress.setDomain(Address(linphone_core_get_conference_factory_uri(corePrivate.cCore)).getDomain()); + return workaroundAddress.asStringUriOnly(); +} + // ----------------------------------------------------------------------------- shared_ptr CorePrivate::createChatRoom (const Address &peerAddress, bool isRtt) { @@ -66,7 +76,12 @@ void CorePrivate::insertChatRoom (const shared_ptr &chatRoom) { L_ASSERT(chatRoom); L_ASSERT(chatRoom->getState() == ChatRoom::State::Created); - string peerAddress = getCleanedPeerAddress(chatRoom->getPeerAddress()).asStringUriOnly(); + Address cleanedPeerAddress = getCleanedPeerAddress(chatRoom->getPeerAddress()); + + const string peerAddress = chatRoom->getCapabilities() & static_cast(ChatRoom::Capabilities::Conference) + ? resolveWorkaroundClientGroupChatRoomAddress(*this, cleanedPeerAddress) + : cleanedPeerAddress.asStringUriOnly(); + deleteChatRoom(peerAddress); chatRooms.push_back(chatRoom); @@ -84,31 +99,19 @@ void CorePrivate::deleteChatRoom (const string &peerAddress) { return; } - // TODO: Remove me, temp workaround. - string workaroundAddress; - { - Address address(peerAddress); - address.setDomain(Address(linphone_core_get_conference_factory_uri(cCore)).getDomain()); - workaroundAddress = address.asStringUriOnly(); - } - - lWarning() << "We don't find the chat room with address " << peerAddress << - " as a temporary workaround, searching with " << workaroundAddress; - it = find_if(chatRooms.begin(), chatRooms.end(), [&workaroundAddress](const shared_ptr &chatRoom) { - return workaroundAddress == chatRoom->getPeerAddress().asStringUriOnly(); - }); - if (it != chatRooms.end()) - chatRooms.erase(it); - else - lError() << "Unable to remove chat room: " << peerAddress; + lError() << "Unable to remove chat room: " << peerAddress; } } void CorePrivate::insertChatRoomWithDb (const shared_ptr &chatRoom) { insertChatRoom(chatRoom); + + ChatRoom::CapabilitiesMask capabilities = chatRoom->getCapabilities(); mainDb->insertChatRoom( - getCleanedPeerAddress(chatRoom->getPeerAddress()).asStringUriOnly(), - chatRoom->getCapabilities() + capabilities & static_cast(ChatRoom::Capabilities::Conference) + ? resolveWorkaroundClientGroupChatRoomAddress(*this, chatRoom->getPeerAddress()) + : chatRoom->getPeerAddress().asStringUriOnly(), + capabilities ); } @@ -132,24 +135,23 @@ shared_ptr Core::findChatRoom (const Address &peerAddress) const { if (it != d->chatRoomsByUri.cend()) return it->second; - // TODO: Remove me, temp workaround. - cleanedAddress.setDomain(Address(linphone_core_get_conference_factory_uri(d->cCore)).getDomain()); - lWarning() << "We don't find the chat room with address " << peerAddress.asString() << - " as a temporary workaround, searching with " << cleanedAddress.asString(); + lInfo() << "Unable to find chat room: `" << peerAddress.asStringUriOnly() << "`."; - it = d->chatRoomsByUri.find(cleanedAddress.asStringUriOnly()); + // TODO: Remove me, temp workaround. + const string workaroundAddress = resolveWorkaroundClientGroupChatRoomAddress(*d, cleanedAddress); + lWarning() << "Workaround: searching chat room with: `" << workaroundAddress << "`."; + it = d->chatRoomsByUri.find(workaroundAddress); return it == d->chatRoomsByUri.cend() ? shared_ptr() : it->second; } shared_ptr Core::createClientGroupChatRoom (const string &subject) { L_D(); - - const char *factoryUri = linphone_core_get_conference_factory_uri(d->cCore); - if (!factoryUri) - return nullptr; - return L_GET_CPP_PTR_FROM_C_OBJECT( - _linphone_client_group_chat_room_new(d->cCore, factoryUri, L_STRING_TO_C(subject)) + _linphone_client_group_chat_room_new( + d->cCore, + linphone_core_get_conference_factory_uri(d->cCore), + L_STRING_TO_C(subject) + ) ); } @@ -187,8 +189,12 @@ shared_ptr Core::getOrCreateBasicChatRoom (const string &peerAddress, void Core::deleteChatRoom (const shared_ptr &chatRoom) { CorePrivate *d = chatRoom->getCore()->cppCore->getPrivate(); - string peerAddress = getCleanedPeerAddress(chatRoom->getPeerAddress()).asStringUriOnly(); - d->deleteChatRoomWithDb(peerAddress); + const Address cleanedPeerAddress = getCleanedPeerAddress(chatRoom->getPeerAddress()); + d->deleteChatRoomWithDb( + chatRoom->getCapabilities() & static_cast(ChatRoom::Capabilities::Conference) + ? resolveWorkaroundClientGroupChatRoomAddress(*d, cleanedPeerAddress) + : cleanedPeerAddress.asStringUriOnly() + ); } LINPHONE_END_NAMESPACE diff --git a/src/core/core-p.h b/src/core/core-p.h index 36c70a3a7..227c0bea3 100644 --- a/src/core/core-p.h +++ b/src/core/core-p.h @@ -34,13 +34,12 @@ public: LinphoneCore *cCore = nullptr; void insertChatRoomWithDb (const std::shared_ptr &chatRoom); - void deleteChatRoomWithDb (const std::string &peerAddress); - std::shared_ptr createChatRoom (const Address &peerAddress, bool isRtt); private: void insertChatRoom (const std::shared_ptr &chatRoom); void deleteChatRoom (const std::string &peerAddress); + void deleteChatRoomWithDb (const std::string &peerAddress); std::list> chatRooms; std::unordered_map> chatRoomsByUri;