Fix crash with CardDav
This commit is contained in:
parent
f4e3db8a07
commit
6ff3cc0ae7
2 changed files with 58 additions and 43 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "core/path/Paths.hpp"
|
#include "core/path/Paths.hpp"
|
||||||
#include "model/core/CoreModel.hpp"
|
#include "model/core/CoreModel.hpp"
|
||||||
|
#include "model/setting/SettingsModel.hpp"
|
||||||
#include "model/tool/ToolModel.hpp"
|
#include "model/tool/ToolModel.hpp"
|
||||||
#include "tool/Utils.hpp"
|
#include "tool/Utils.hpp"
|
||||||
#include "tool/providers/AvatarProvider.hpp"
|
#include "tool/providers/AvatarProvider.hpp"
|
||||||
|
|
@ -394,6 +395,11 @@ bool FriendModel::isThisFriend(const std::shared_ptr<linphone::Friend> &data) {
|
||||||
|
|
||||||
void FriendModel::remove() {
|
void FriendModel::remove() {
|
||||||
if (!mMonitor) return;
|
if (!mMonitor) return;
|
||||||
|
auto friendList = mMonitor->getFriendList();
|
||||||
|
if (friendList && friendList == SettingsModel::getCardDAVListForNewFriends()) {
|
||||||
|
friendList->removeFriend(mMonitor);
|
||||||
|
friendList->synchronizeFriendsFromServer();
|
||||||
|
}
|
||||||
auto temp = mMonitor;
|
auto temp = mMonitor;
|
||||||
temp->remove(); // mMonitor become null
|
temp->remove(); // mMonitor become null
|
||||||
emit CoreModel::getInstance()->friendRemoved(temp);
|
emit CoreModel::getInstance()->friendRemoved(temp);
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ std::shared_ptr<FriendsManager> FriendsManager::gFriendsManager;
|
||||||
FriendsManager::FriendsManager(QObject *parent) : QObject(parent) {
|
FriendsManager::FriendsManager(QObject *parent) : QObject(parent) {
|
||||||
moveToThread(CoreModel::getInstance()->thread());
|
moveToThread(CoreModel::getInstance()->thread());
|
||||||
|
|
||||||
connect(CoreModel::getInstance().get(), &CoreModel::friendRemoved, this, [this] (const std::shared_ptr<linphone::Friend> &f) {
|
connect(CoreModel::getInstance().get(), &CoreModel::friendRemoved, this,
|
||||||
|
[this](const std::shared_ptr<linphone::Friend> &f) {
|
||||||
auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr);
|
auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
if (key != nullptr) {
|
if (key != nullptr) {
|
||||||
mKnownFriends.remove(key);
|
mKnownFriends.remove(key);
|
||||||
|
|
@ -39,18 +40,24 @@ FriendsManager::FriendsManager(QObject *parent) : QObject(parent) {
|
||||||
if (unknown != nullptr) {
|
if (unknown != nullptr) {
|
||||||
mUnknownFriends.remove(unknown);
|
mUnknownFriends.remove(unknown);
|
||||||
}
|
}
|
||||||
|
if (f->getAddress()) {
|
||||||
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
||||||
mOtherAddresses.removeAll(address);
|
mOtherAddresses.removeAll(address);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
connect(CoreModel::getInstance().get(), &CoreModel::friendCreated, this, [this] (const std::shared_ptr<linphone::Friend> &f) {
|
connect(CoreModel::getInstance().get(), &CoreModel::friendCreated, this,
|
||||||
|
[this](const std::shared_ptr<linphone::Friend> &f) {
|
||||||
auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr);
|
auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
if (unknown != nullptr) {
|
if (unknown != nullptr) {
|
||||||
mUnknownFriends.remove(unknown);
|
mUnknownFriends.remove(unknown);
|
||||||
}
|
}
|
||||||
|
if (f->getAddress()) {
|
||||||
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
||||||
mOtherAddresses.removeAll(address);
|
mOtherAddresses.removeAll(address);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
connect(CoreModel::getInstance().get(), &CoreModel::friendUpdated, this, [this] (const std::shared_ptr<linphone::Friend> &f) {
|
connect(CoreModel::getInstance().get(), &CoreModel::friendUpdated, this,
|
||||||
|
[this](const std::shared_ptr<linphone::Friend> &f) {
|
||||||
auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr);
|
auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
if (key != nullptr) {
|
if (key != nullptr) {
|
||||||
mKnownFriends.remove(key);
|
mKnownFriends.remove(key);
|
||||||
|
|
@ -59,8 +66,10 @@ FriendsManager::FriendsManager(QObject *parent) : QObject(parent) {
|
||||||
if (unknown != nullptr) {
|
if (unknown != nullptr) {
|
||||||
mUnknownFriends.remove(unknown);
|
mUnknownFriends.remove(unknown);
|
||||||
}
|
}
|
||||||
|
if (f->getAddress()) {
|
||||||
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
||||||
mOtherAddresses.removeAll(address);
|
mOtherAddresses.removeAll(address);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +122,8 @@ bool FriendsManager::isInOtherAddresses(const QString& key) {
|
||||||
return mOtherAddresses.contains(key);
|
return mOtherAddresses.contains(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendsManager::appendKnownFriend(std::shared_ptr<linphone::Address> address, std::shared_ptr<linphone::Friend> f) {
|
void FriendsManager::appendKnownFriend(std::shared_ptr<linphone::Address> address,
|
||||||
|
std::shared_ptr<linphone::Friend> f) {
|
||||||
auto key = Utils::coreStringToAppString(address->asStringUriOnly());
|
auto key = Utils::coreStringToAppString(address->asStringUriOnly());
|
||||||
if (mKnownFriends.contains(key)) {
|
if (mKnownFriends.contains(key)) {
|
||||||
qDebug() << "friend is already in konwn list, return";
|
qDebug() << "friend is already in konwn list, return";
|
||||||
|
|
@ -122,8 +132,8 @@ void FriendsManager::appendKnownFriend(std::shared_ptr<linphone::Address> addres
|
||||||
mKnownFriends.insert(key, QVariant::fromValue(f));
|
mKnownFriends.insert(key, QVariant::fromValue(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendsManager::appendUnknownFriend(std::shared_ptr<linphone::Address> address,
|
||||||
void FriendsManager::appendUnknownFriend(std::shared_ptr<linphone::Address> address, std::shared_ptr<linphone::Friend> f) {
|
std::shared_ptr<linphone::Friend> f) {
|
||||||
auto key = Utils::coreStringToAppString(address->asStringUriOnly());
|
auto key = Utils::coreStringToAppString(address->asStringUriOnly());
|
||||||
if (mUnknownFriends.contains(key)) {
|
if (mUnknownFriends.contains(key)) {
|
||||||
qDebug() << "friend is already in unkonwn list, return";
|
qDebug() << "friend is already in unkonwn list, return";
|
||||||
|
|
@ -132,7 +142,6 @@ void FriendsManager::appendUnknownFriend(std::shared_ptr<linphone::Address> addr
|
||||||
mUnknownFriends.insert(key, QVariant::fromValue(f));
|
mUnknownFriends.insert(key, QVariant::fromValue(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FriendsManager::appendOtherAddress(QString address) {
|
void FriendsManager::appendOtherAddress(QString address) {
|
||||||
if (mOtherAddresses.contains(address)) {
|
if (mOtherAddresses.contains(address)) {
|
||||||
qDebug() << "friend is already in other addresses, return";
|
qDebug() << "friend is already in other addresses, return";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue