mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-09-10 03:53:23 +02:00
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
This commit is contained in:
parent
948e2cc837
commit
c47cfe446d
1 changed files with 32 additions and 13 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue