Commit 804aa0df authored by Ronan Abhamon's avatar Ronan Abhamon

fix(app): deal with friends without vcard

parent 02ca3cb1
...@@ -71,7 +71,10 @@ inline shared_ptr<belcard::BelCardPhoto> findBelCardPhoto (const list<shared_ptr ...@@ -71,7 +71,10 @@ inline shared_ptr<belcard::BelCardPhoto> findBelCardPhoto (const list<shared_ptr
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
VcardModel::VcardModel (shared_ptr<linphone::Vcard> vcard) : mVcard(vcard) {} VcardModel::VcardModel (shared_ptr<linphone::Vcard> vcard) {
Q_ASSERT(vcard != nullptr);
mVcard = vcard;
}
VcardModel::~VcardModel () { VcardModel::~VcardModel () {
// If it's a detached Vcard, the linked photo must be destroyed from fs. // If it's a detached Vcard, the linked photo must be destroyed from fs.
......
...@@ -36,12 +36,18 @@ ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(pare ...@@ -36,12 +36,18 @@ ContactsListModel::ContactsListModel (QObject *parent) : QAbstractListModel(pare
mLinphoneFriends = CoreManager::getInstance()->getCore()->getFriendsLists().front(); mLinphoneFriends = CoreManager::getInstance()->getCore()->getFriendsLists().front();
// Init contacts with linphone friends list. // Init contacts with linphone friends list.
for (const auto &_friend : mLinphoneFriends->getFriends()) { QQmlEngine *engine = App::getInstance()->getEngine();
ContactModel *contact = new ContactModel(this, _friend); for (const auto &linphoneFriend : mLinphoneFriends->getFriends()) {
if (!linphoneFriend->getVcard()) {
qWarning() << QStringLiteral("Ignore one linphone friend without vcard.");
continue;
}
ContactModel *contact = new ContactModel(this, linphoneFriend);
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership // See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership. // The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership); engine->setObjectOwnership(contact, QQmlEngine::CppOwnership);
addContact(contact); addContact(contact);
} }
...@@ -101,17 +107,17 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcard) { ...@@ -101,17 +107,17 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
ContactModel *contact = new ContactModel(this, vcard); ContactModel *contact = new ContactModel(this, vcard);
App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership); App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership);
qInfo() << "Add contact:" << contact;
if ( if (
mLinphoneFriends->addFriend(contact->mLinphoneFriend) != mLinphoneFriends->addFriend(contact->mLinphoneFriend) !=
linphone::FriendListStatus::FriendListStatusOK linphone::FriendListStatus::FriendListStatusOK
) { ) {
qWarning() << "Unable to add friend from vcard:" << vcard; qWarning() << QStringLiteral("Unable to add contact from vcard:") << vcard;
delete contact; delete contact;
return nullptr; return nullptr;
} }
qInfo() << QStringLiteral("Add contact on vcard:") << vcard << contact;
int row = mList.count(); int row = mList.count();
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
...@@ -124,11 +130,11 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcard) { ...@@ -124,11 +130,11 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcard) {
} }
void ContactsListModel::removeContact (ContactModel *contact) { void ContactsListModel::removeContact (ContactModel *contact) {
qInfo() << "Removing contact:" << contact; qInfo() << QStringLiteral("Removing contact:") << contact;
int index = mList.indexOf(contact); int index = mList.indexOf(contact);
if (index == -1 || !removeRow(index)) if (index == -1 || !removeRow(index))
qWarning() << "Unable to remove contact:" << contact; qWarning() << QStringLiteral("Unable to remove contact:") << contact;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -89,7 +89,9 @@ void CoreHandlers::onNotifyPresenceReceived ( ...@@ -89,7 +89,9 @@ void CoreHandlers::onNotifyPresenceReceived (
const shared_ptr<linphone::Core> &, const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::Friend> &linphoneFriend const shared_ptr<linphone::Friend> &linphoneFriend
) { ) {
linphoneFriend->getData<ContactModel>("contact-model").refreshPresence(); // Ignore friend without vcard because the `contact-model` data doesn't exist.
if (linphoneFriend->getVcard())
linphoneFriend->getData<ContactModel>("contact-model").refreshPresence();
} }
void CoreHandlers::onRegistrationStateChanged ( void CoreHandlers::onRegistrationStateChanged (
......
...@@ -15,6 +15,7 @@ function handleCreation () { ...@@ -15,6 +15,7 @@ function handleCreation () {
) )
if (!contact) { if (!contact) {
// Add a new contact.
var vcard = Linphone.CoreManager.createDetachedVcardModel() var vcard = Linphone.CoreManager.createDetachedVcardModel()
if (sipAddress && sipAddress.length > 0) { if (sipAddress && sipAddress.length > 0) {
...@@ -24,6 +25,7 @@ function handleCreation () { ...@@ -24,6 +25,7 @@ function handleCreation () {
contactEdit._vcard = vcard contactEdit._vcard = vcard
contactEdit._edition = true contactEdit._edition = true
} else { } else {
// See or edit a contact.
contactEdit._vcard = contact.vcard contactEdit._vcard = contact.vcard
} }
} }
......
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