Commit 593055be authored by Ronan Abhamon's avatar Ronan Abhamon

fix(CoreManager): avoid in getChatModelFromSipAddress when migration chat room is used

parent 912b6761
......@@ -94,15 +94,18 @@ shared_ptr<ChatModel> CoreManager::getChatModelFromSipAddress (const QString &si
// Create a new chat model.
if (!mChatModels.contains(sipAddress)) {
Q_ASSERT(mCore->createAddress(::Utils::appStringToCoreString(sipAddress)) != nullptr);
Q_CHECK_PTR(mCore->createAddress(::Utils::appStringToCoreString(sipAddress)));
auto deleter = [this](ChatModel *chatModel) {
mChatModels.remove(chatModel->getSipAddress());
delete chatModel;
};
// Don't use chatModel->getSipAddress() in lambda.
// If it is a migration chat room the chat room sip address can be changed!!!
auto deleter = [this, sipAddress](ChatModel *chatModel) {
bool removed = mChatModels.remove(sipAddress);
Q_ASSERT(removed);
delete chatModel;
};
shared_ptr<ChatModel> chatModel(new ChatModel(sipAddress), deleter);
mChatModels[chatModel->getSipAddress()] = chatModel;
mChatModels[sipAddress] = chatModel;
emit chatModelCreated(chatModel);
......@@ -111,7 +114,7 @@ shared_ptr<ChatModel> CoreManager::getChatModelFromSipAddress (const QString &si
// Returns an existing chat model.
shared_ptr<ChatModel> chatModel = mChatModels[sipAddress].lock();
Q_CHECK_PTR(chatModel.get());
Q_CHECK_PTR(chatModel);
return chatModel;
}
......
......@@ -163,7 +163,7 @@ private:
SettingsModel *mSettingsModel = nullptr;
AccountSettingsModel *mAccountSettingsModel = nullptr;
QHash<QString, std::weak_ptr<ChatModel> > mChatModels;
QHash<QString, std::weak_ptr<ChatModel>> mChatModels;
QTimer *mCbsTimer = nullptr;
......
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