remove friend from friendsmanager maps when created, updated, removed
This commit is contained in:
parent
8463c3e5f9
commit
a2c0bfe558
3 changed files with 36 additions and 3 deletions
|
|
@ -678,12 +678,13 @@ void FriendCore::save() { // Save Values to model
|
||||||
if (contact != nullptr) {
|
if (contact != nullptr) {
|
||||||
auto friendModel = Utils::makeQObject_ptr<FriendModel>(contact);
|
auto friendModel = Utils::makeQObject_ptr<FriendModel>(contact);
|
||||||
friendModel->setSelf(friendModel);
|
friendModel->setSelf(friendModel);
|
||||||
mCoreModelConnection->invokeToCore([this, thisCopy, friendModel] {
|
mCoreModelConnection->invokeToCore([this, thisCopy, friendModel, contact] {
|
||||||
mFriendModel = friendModel;
|
mFriendModel = friendModel;
|
||||||
mCoreModelConnection->invokeToModel([this, thisCopy] {
|
mCoreModelConnection->invokeToModel([this, thisCopy, contact] {
|
||||||
thisCopy->writeIntoModel(mFriendModel);
|
thisCopy->writeIntoModel(mFriendModel);
|
||||||
thisCopy->deleteLater();
|
thisCopy->deleteLater();
|
||||||
mVCardString = mFriendModel->getVCardAsString();
|
mVCardString = mFriendModel->getVCardAsString();
|
||||||
|
emit CoreModel::getInstance()->friendUpdated(contact);
|
||||||
mCoreModelConnection->invokeToCore([this] {
|
mCoreModelConnection->invokeToCore([this] {
|
||||||
setIsSaved(true);
|
setIsSaved(true);
|
||||||
emit saved();
|
emit saved();
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,39 @@ DEFINE_ABSTRACT_OBJECT(FriendsManager)
|
||||||
std::shared_ptr<FriendsManager> FriendsManager::gFriendsManager;
|
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) {
|
||||||
|
auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
|
if (key != nullptr) {
|
||||||
|
mKnownFriends.remove(key);
|
||||||
|
}
|
||||||
|
auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
|
if (unknown != nullptr) {
|
||||||
|
mUnknownFriends.remove(unknown);
|
||||||
|
}
|
||||||
|
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
||||||
|
mOtherAddresses.removeAll(address);
|
||||||
|
});
|
||||||
|
connect(CoreModel::getInstance().get(), &CoreModel::friendCreated, this, [this] (const std::shared_ptr<linphone::Friend> &f) {
|
||||||
|
auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
|
if (unknown != nullptr) {
|
||||||
|
mUnknownFriends.remove(unknown);
|
||||||
|
}
|
||||||
|
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
||||||
|
mOtherAddresses.removeAll(address);
|
||||||
|
});
|
||||||
|
connect(CoreModel::getInstance().get(), &CoreModel::friendUpdated, this, [this] (const std::shared_ptr<linphone::Friend> &f) {
|
||||||
|
auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
|
if (key != nullptr) {
|
||||||
|
mKnownFriends.remove(key);
|
||||||
|
}
|
||||||
|
auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr);
|
||||||
|
if (unknown != nullptr) {
|
||||||
|
mUnknownFriends.remove(unknown);
|
||||||
|
}
|
||||||
|
auto address = QString::fromStdString(f->getAddress()->asStringUriOnly());
|
||||||
|
mOtherAddresses.removeAll(address);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendsManager::~FriendsManager() {
|
FriendsManager::~FriendsManager() {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@ private:
|
||||||
QVariantMap mKnownFriends;
|
QVariantMap mKnownFriends;
|
||||||
QVariantMap mUnknownFriends;
|
QVariantMap mUnknownFriends;
|
||||||
QStringList mOtherAddresses;
|
QStringList mOtherAddresses;
|
||||||
//core model connection + reset unknown et other quand friend ajouté, supprimé, updated
|
|
||||||
DECLARE_ABSTRACT_OBJECT
|
DECLARE_ABSTRACT_OBJECT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue