Skip to content
Snippets Groups Projects
Commit c47cfe44 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Sébastien Blin
Browse files

notifications: gnu/linux: do a lookup for incoming trust requests

Attempt a name directory lookup for trust requests before popping a notification. Fall back to the display name, then peer URI if needed.

Gitlab: #1141
Change-Id: Ie91c3fdf518cb8f27d8f0d6a74f015e9c4034d42
parent 948e2cc8
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
#include "qtutils.h" #include "qtutils.h"
#include "systemtray.h" #include "systemtray.h"
#include "qmlregister.h" #include "qmlregister.h"
#include "qtutils.h"
#include "namedirectory.h"
#include <QApplication> #include <QApplication>
#include <QJsonObject> #include <QJsonObject>
...@@ -232,21 +235,37 @@ ConversationsAdapter::onNewTrustRequest(const QString& accountId, ...@@ -232,21 +235,37 @@ ConversationsAdapter::onNewTrustRequest(const QString& accountId,
if (convInfo.uid.isEmpty()) if (convInfo.uid.isEmpty())
return; return;
} }
auto& accInfo = lrcInstance_->getAccountInfo(accountId);
auto from = accInfo.contactModel->bestNameForContact(peerUri);
auto to = lrcInstance_->accountModel().bestNameForAccount(accountId); auto to = lrcInstance_->accountModel().bestNameForAccount(accountId);
auto preferences = accInfo.conversationModel->getConversationPreferences(convId); auto cb = [this, to, accountId, conv, peerUri](QString peerBestName) {
// Ignore notifications for this conversation auto contactPhoto = Utils::contactPhoto(lrcInstance_, peerUri, QSize(50, 50), accountId);
if (preferences["ignoreNotifications"] == "true") auto notifId = QString("%1;%2").arg(accountId, conv);
return; systemTray_->showNotification(notifId,
auto contactPhoto = Utils::contactPhoto(lrcInstance_, peerUri, QSize(50, 50), accountId); tr("%1 received a new trust request").arg(to),
auto notifId = QString("%1;%2").arg(accountId, conv); "New request from " + peerBestName,
systemTray_->showNotification(notifId, SystemTray::NotificationType::REQUEST,
tr("%1 received a new trust request").arg(to), Utils::QImageToByteArray(contactPhoto));
"New request from " + from, };
SystemTray::NotificationType::REQUEST,
Utils::QImageToByteArray(contactPhoto)); // This peer is not yet a contact, so we don't have a name for it,
// but we can attempt to look it up using the name service before
// falling back to the bestNameForContact.
Utils::oneShotConnect(&NameDirectory::instance(),
&NameDirectory::registeredNameFound,
this,
[this, accountId, peerUri, cb](NameDirectory::LookupStatus status,
const QString& address,
const QString& name) {
if (address == peerUri) {
if (status == NameDirectory::LookupStatus::SUCCESS)
cb(name);
else {
auto& accInfo = lrcInstance_->getAccountInfo(accountId);
cb(accInfo.contactModel->bestNameForContact(peerUri));
}
}
});
std::ignore = NameDirectory::instance().lookupAddress(accountId, peerUri);
} }
#else #else
Q_UNUSED(accountId) Q_UNUSED(accountId)
......
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