Commit 1b6788f0 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(src/components/sip-addresses/SipAddressesModel): try to map to other...

fix(src/components/sip-addresses/SipAddressesModel): try to map to other contact when a contact of one sip address is removed
parent 24878cf2
......@@ -112,6 +112,16 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
// -----------------------------------------------------------------------------
ContactModel *ContactsListModel::findContactModelFromSipAddress (const QString &sipAddress) const {
auto it = find_if(mList.begin(), mList.end(), [sipAddress](ContactModel *contactModel) {
return contactModel->getVcardModel()->getSipAddresses().contains(sipAddress);
});
return it != mList.end() ? *it : nullptr;
}
// -----------------------------------------------------------------------------
ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
ContactModel *contact = new ContactModel(this, vcard);
App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership);
......
......@@ -47,6 +47,8 @@ public:
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
ContactModel *findContactModelFromSipAddress (const QString &sipAddress) const;
Q_INVOKABLE ContactModel *addContact (VcardModel *vcard);
Q_INVOKABLE void removeContact (ContactModel *contact);
......
......@@ -76,7 +76,9 @@ void CoreManager::init (QObject *parent, const QString &configPath) {
// -----------------------------------------------------------------------------
VcardModel *CoreManager::createDetachedVcardModel () {
return new VcardModel(linphone::Factory::get()->createVcard());
VcardModel *vcardModel = new VcardModel(linphone::Factory::get()->createVcard(), false);
qInfo() << QStringLiteral("Create detached vcard:") << vcardModel;
return vcardModel;
}
void CoreManager::forceRefreshRegisters () {
......
......@@ -47,9 +47,10 @@ SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(pare
QObject::connect(contacts, &ContactsListModel::sipAddressAdded, this, &SipAddressesModel::handleSipAddressAdded);
QObject::connect(contacts, &ContactsListModel::sipAddressRemoved, this, &SipAddressesModel::handleSipAddressRemoved);
QObject::connect(mCoreHandlers.get(), &CoreHandlers::messageReceived, this, &SipAddressesModel::handleMessageReceived);
QObject::connect(mCoreHandlers.get(), &CoreHandlers::callStateChanged, this, &SipAddressesModel::handleCallStateChanged);
QObject::connect(mCoreHandlers.get(), &CoreHandlers::presenceReceived, this, &SipAddressesModel::handlePresenceReceived);
CoreHandlers *intHandlers = mCoreHandlers.get();
QObject::connect(intHandlers, &CoreHandlers::messageReceived, this, &SipAddressesModel::handleMessageReceived);
QObject::connect(intHandlers, &CoreHandlers::callStateChanged, this, &SipAddressesModel::handleCallStateChanged);
QObject::connect(intHandlers, &CoreHandlers::presenceReceived, this, &SipAddressesModel::handlePresenceReceived);
}
// -----------------------------------------------------------------------------
......@@ -183,12 +184,10 @@ QString SipAddressesModel::addTransportToSipAddress (const QString &sipAddress,
return ::Utils::linphoneStringToQString(address->asString());
}
bool SipAddressesModel::sipAddressIsValid (const QString &sipAddress) const {
shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress(
::Utils::qStringToLinphoneString(sipAddress)
);
return !!address;
bool SipAddressesModel::sipAddressIsValid (const QString &sipAddress) {
return !!linphone::Factory::get()->createAddress(
::Utils::qStringToLinphoneString(sipAddress)
);
}
// -----------------------------------------------------------------------------
......@@ -347,8 +346,14 @@ void SipAddressesModel::handleMessagesCountReset (const QString &sipAddress) {
// -----------------------------------------------------------------------------
void SipAddressesModel::addOrUpdateSipAddress (QVariantMap &map, ContactModel *contact) {
map["contact"] = QVariant::fromValue(contact);
updateObservers(map["sipAddress"].toString(), contact);
QString sipAddress = map["sipAddress"].toString();
if (contact)
map["contact"] = QVariant::fromValue(contact);
else if (map.remove("contact") == 0)
qWarning() << QStringLiteral("`contact` field is empty on sip address: `%1`.").arg(sipAddress);
updateObservers(sipAddress, contact);
}
void SipAddressesModel::addOrUpdateSipAddress (QVariantMap &map, const shared_ptr<linphone::Call> &call) {
......@@ -406,16 +411,18 @@ void SipAddressesModel::removeContactOfSipAddress (const QString &sipAddress) {
return;
}
updateObservers(sipAddress, nullptr);
// Try to map other contact on this sip address.
ContactModel *contactModel = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(sipAddress);
updateObservers(sipAddress, contactModel);
if (it->remove("contact") == 0)
qWarning() << QStringLiteral("`contact` field is empty on sip address: `%1`.").arg(sipAddress);
qInfo() << QStringLiteral("Map new contact on sip address: `%1`.").arg(sipAddress) << contactModel;
addOrUpdateSipAddress(*it, contactModel);
int row = mRefs.indexOf(&(*it));
Q_ASSERT(row != -1);
// History exists, signal changes.
if (it->contains("timestamp")) {
if (it->contains("timestamp") || contactModel) {
emit dataChanged(index(row, 0), index(row, 0));
return;
}
......
......@@ -58,7 +58,8 @@ public:
Q_INVOKABLE QString getTransportFromSipAddress (const QString &sipAddress) const;
Q_INVOKABLE QString addTransportToSipAddress (const QString &sipAddress, const QString &transport) const;
Q_INVOKABLE bool sipAddressIsValid (const QString &sipAddress) const;
Q_INVOKABLE static bool sipAddressIsValid (const QString &sipAddress);
// ---------------------------------------------------------------------------
......
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