Commit fc88ff95 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components/contacts/Contacts): use `setData` on wrapped...

feat(components/contacts/Contacts): use `setData` on wrapped `linphone::Friend` instead of a hashtable to map `ContactModel` from `linphone::Friend`
parent 1459d293
......@@ -46,6 +46,7 @@ class ContactModel : public QObject {
public:
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend) {
linphone_friend->setData("contact-model", *this);
m_linphone_friend = linphone_friend;
}
......
......@@ -22,7 +22,6 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
contact, QQmlEngine::CppOwnership
);
m_friend_to_contact[friend_.get()] = contact;
m_list << contact;
}
}
......@@ -61,7 +60,6 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
ContactModel *contact = m_list[row];
m_list.removeAt(row);
m_friend_to_contact.remove(contact->m_linphone_friend.get());
m_linphone_friends->removeFriend(contact->m_linphone_friend);
contact->deleteLater();
......@@ -76,15 +74,19 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const {
// Maybe use a hashtable in future version to get a lower cost?
ContactModel *contact = m_friend_to_contact.value(
m_linphone_friends->findFriendByUri(
Utils::qStringToLinphoneString(sipAddress)
).get()
std::shared_ptr<linphone::Friend> friend_ = m_linphone_friends->findFriendByUri(
Utils::qStringToLinphoneString(sipAddress)
);
qInfo() << "Map sip address to contact:" << sipAddress << "->" << contact;
if (!friend_) {
qInfo() << "Map sip address to contact:" << sipAddress << "-> nullptr";
return nullptr;
}
ContactModel &contact = friend_->getData<ContactModel>("contact-model");
qInfo() << "Map sip address to contact:" << sipAddress << "->" << &contact;
return contact;
return &contact;
}
void ContactsListModel::removeContact (ContactModel *contact) {
......
......@@ -35,8 +35,6 @@ public slots:
private:
QList<ContactModel *> m_list;
QHash<const linphone::Friend *, ContactModel *> m_friend_to_contact;
std::shared_ptr<linphone::FriendList> m_linphone_friends;
};
......
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