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 @@
#include "qtutils.h"
#include "systemtray.h"
#include "qmlregister.h"
#include "qtutils.h"
#include "namedirectory.h"
#include <QApplication>
#include <QJsonObject>
......@@ -232,21 +235,37 @@ ConversationsAdapter::onNewTrustRequest(const QString& accountId,
if (convInfo.uid.isEmpty())
return;
}
auto& accInfo = lrcInstance_->getAccountInfo(accountId);
auto from = accInfo.contactModel->bestNameForContact(peerUri);
auto to = lrcInstance_->accountModel().bestNameForAccount(accountId);
auto preferences = accInfo.conversationModel->getConversationPreferences(convId);
// Ignore notifications for this conversation
if (preferences["ignoreNotifications"] == "true")
return;
auto contactPhoto = Utils::contactPhoto(lrcInstance_, peerUri, QSize(50, 50), accountId);
auto notifId = QString("%1;%2").arg(accountId, conv);
systemTray_->showNotification(notifId,
tr("%1 received a new trust request").arg(to),
"New request from " + from,
SystemTray::NotificationType::REQUEST,
Utils::QImageToByteArray(contactPhoto));
auto cb = [this, to, accountId, conv, peerUri](QString peerBestName) {
auto contactPhoto = Utils::contactPhoto(lrcInstance_, peerUri, QSize(50, 50), accountId);
auto notifId = QString("%1;%2").arg(accountId, conv);
systemTray_->showNotification(notifId,
tr("%1 received a new trust request").arg(to),
"New request from " + peerBestName,
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
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