Skip to content
Snippets Groups Projects
Commit 815d3241 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

contactmodel: move profile creation on dedicated thread

This avoid a heavy I/O operation on the main pool

Change-Id: Ic5068d9d1c291b8f27ffc563933d4920af42e890
GitLab: #1450
parent 2343f34b
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,8 @@
#include "api/contactmodel.h"
#include <QThreadPool>
// LRC
#include "api/account.h"
#include "api/contact.h"
......@@ -121,6 +123,8 @@ public:
QString searchStatus_ {};
QMap<QString, QString> nonContactLookup_;
QThreadPool profileThreadPool;
public Q_SLOTS:
/**
* Listen CallbacksHandler when a presence update occurs
......@@ -690,6 +694,7 @@ ContactModelPimpl::~ContactModelPimpl()
&ConfigurationManagerInterface::userSearchEnded,
this,
&ContactModelPimpl::slotUserSearchEnded);
profileThreadPool.waitForDone();
}
bool
......@@ -1196,44 +1201,46 @@ ContactModelPimpl::slotProfileReceived(const QString& accountId,
if (accountId != linked.owner.id)
return;
QFile vCardFile(path);
if (!vCardFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&vCardFile);
auto vCard = in.readAll();
profile::Info profileInfo;
profileInfo.uri = peer;
profileInfo.type = profile::Type::JAMI;
for (auto& e : QString(vCard).split("\n")) {
if (e.contains("PHOTO")) {
auto splitted = e.split(":");
if (splitted.size() > 1)
profileInfo.avatar = e.split(":")[1];
} else if (e.contains("FN")) {
auto splitted = e.split(":");
if (splitted.size() > 1)
profileInfo.alias = e.split(":")[1];
profileThreadPool.start([=] {
QFile vCardFile(path);
if (!vCardFile.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&vCardFile);
auto vCard = in.readAll();
profile::Info profileInfo;
profileInfo.uri = peer;
profileInfo.type = profile::Type::JAMI;
for (auto& e : QString(vCard).split("\n")) {
if (e.contains("PHOTO")) {
auto splitted = e.split(":");
if (splitted.size() > 1)
profileInfo.avatar = e.split(":")[1];
} else if (e.contains("FN")) {
auto splitted = e.split(":");
if (splitted.size() > 1)
profileInfo.alias = e.split(":")[1];
}
}
}
if (peer == linked.owner.profileInfo.uri) {
if (profileInfo.avatar.isEmpty())
return; // In this case, probably a new device without avatar.
// Profile is saved by daemon, just update client
linked.owner.accountModel->setAlias(linked.owner.id, profileInfo.alias, false);
linked.owner.accountModel->setAvatar(linked.owner.id, profileInfo.avatar, false);
return;
}
vCardFile.remove();
if (peer == linked.owner.profileInfo.uri) {
if (profileInfo.avatar.isEmpty())
return; // In this case, probably a new device without avatar.
// Profile is saved by daemon, just update client
linked.owner.accountModel->setAlias(linked.owner.id, profileInfo.alias, false);
linked.owner.accountModel->setAvatar(linked.owner.id, profileInfo.avatar, false);
return;
}
vCardFile.remove();
contact::Info contactInfo;
contactInfo.profileInfo = profileInfo;
contact::Info contactInfo;
contactInfo.profileInfo = profileInfo;
linked.owner.contactModel->addContact(contactInfo);
contactInfo.profileInfo.avatar.clear(); // Do not store after update
linked.owner.contactModel->addContact(contactInfo);
contactInfo.profileInfo.avatar.clear(); // Do not store after update
});
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment