aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp57
-rw-r--r--lib/connection.h17
-rw-r--r--lib/room.cpp14
3 files changed, 47 insertions, 41 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 0994d85a..8fd2d6cf 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -1322,18 +1322,11 @@ Connection::sendToDevices(const QString& eventType,
{
QHash<QString, QHash<QString, QJsonObject>> json;
json.reserve(int(eventsMap.size()));
- std::for_each(eventsMap.begin(), eventsMap.end(),
- [&json](const auto& userTodevicesToEvents) {
- auto& jsonUser = json[userTodevicesToEvents.first];
- const auto& devicesToEvents = userTodevicesToEvents.second;
- std::for_each(devicesToEvents.begin(),
- devicesToEvents.end(),
- [&jsonUser](const auto& deviceToEvents) {
- jsonUser.insert(
- deviceToEvents.first,
- deviceToEvents.second->contentJson());
- });
- });
+ for (const auto& [userId, devicesToEvents] : eventsMap) {
+ auto& jsonUser = json[userId];
+ for (const auto& [deviceId, event] : devicesToEvents)
+ jsonUser.insert(deviceId, event->contentJson());
+ }
return callApi<SendToDeviceJob>(BackgroundRequest, eventType,
generateTxnId(), json);
}
@@ -2218,20 +2211,23 @@ QStringList Connection::devicesForUser(const QString& userId) const
return d->deviceKeys[userId].keys();
}
-QString Connection::curveKeyForUserDevice(const QString& user, const QString& device) const
+QString Connection::curveKeyForUserDevice(const QString& userId,
+ const QString& device) const
{
- return d->deviceKeys[user][device].keys["curve25519:" % device];
+ return d->deviceKeys[userId][device].keys["curve25519:" % device];
}
-QString Connection::edKeyForUserDevice(const QString& user, const QString& device) const
+QString Connection::edKeyForUserDevice(const QString& userId,
+ const QString& device) const
{
- return d->deviceKeys[user][device].keys["ed25519:" % device];
+ return d->deviceKeys[userId][device].keys["ed25519:" % device];
}
-bool Connection::isKnownCurveKey(const QString& user, const QString& curveKey)
+bool Connection::isKnownCurveKey(const QString& userId,
+ const QString& curveKey) const
{
auto query = database()->prepareQuery(QStringLiteral("SELECT * FROM tracked_devices WHERE matrixId=:matrixId AND curveKey=:curveKey"));
- query.bindValue(":matrixId", user);
+ query.bindValue(":matrixId", userId);
query.bindValue(":curveKey", curveKey);
database()->execute(query);
return query.next();
@@ -2243,25 +2239,32 @@ bool Connection::hasOlmSession(const QString& user, const QString& deviceId) con
return d->olmSessions.contains(curveKey) && !d->olmSessions[curveKey].empty();
}
-QPair<QOlmMessage::Type, QByteArray> Connection::olmEncryptMessage(const QString& user, const QString& device, const QByteArray& message)
+std::pair<QOlmMessage::Type, QByteArray> Connection::olmEncryptMessage(
+ const QString& userId, const QString& device, const QByteArray& message) const
{
- const auto& curveKey = curveKeyForUserDevice(user, device);
+ const auto& curveKey = curveKeyForUserDevice(userId, device);
QOlmMessage::Type type = d->olmSessions[curveKey][0]->encryptMessageType();
- auto result = d->olmSessions[curveKey][0]->encrypt(message);
- auto pickle = d->olmSessions[curveKey][0]->pickle(picklingMode());
- if (pickle) {
- database()->updateOlmSession(curveKey, d->olmSessions[curveKey][0]->sessionId(), *pickle);
+ const auto result = d->olmSessions[curveKey][0]->encrypt(message);
+ if (const auto pickle =
+ d->olmSessions[curveKey][0]->pickle(picklingMode())) {
+ database()->updateOlmSession(curveKey,
+ d->olmSessions[curveKey][0]->sessionId(),
+ *pickle);
} else {
qCWarning(E2EE) << "Failed to pickle olm session: " << pickle.error();
}
return { type, result.toCiphertext() };
}
-void Connection::createOlmSession(const QString& theirIdentityKey, const QString& theirOneTimeKey)
+void Connection::createOlmSession(const QString& theirIdentityKey,
+ const QString& theirOneTimeKey) const
{
- auto session = QOlmSession::createOutboundSession(olmAccount(), theirIdentityKey, theirOneTimeKey);
+ auto session = QOlmSession::createOutboundSession(olmAccount(),
+ theirIdentityKey,
+ theirOneTimeKey);
if (!session) {
- qCWarning(E2EE) << "Failed to create olm session for " << theirIdentityKey << session.error();
+ qCWarning(E2EE) << "Failed to create olm session for "
+ << theirIdentityKey << session.error();
return;
}
d->saveSession(**session, theirIdentityKey);
diff --git a/lib/connection.h b/lib/connection.h
index 656e597c..72383abb 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -330,8 +330,11 @@ public:
//This assumes that an olm session with (user, device) exists
- QPair<QOlmMessage::Type, QByteArray> olmEncryptMessage(const QString& userId, const QString& device, const QByteArray& message);
- void createOlmSession(const QString& theirIdentityKey, const QString& theirOneTimeKey);
+ std::pair<QOlmMessage::Type, QByteArray> olmEncryptMessage(
+ const QString& userId, const QString& device,
+ const QByteArray& message) const;
+ void createOlmSession(const QString& theirIdentityKey,
+ const QString& theirOneTimeKey) const;
#endif // Quotient_E2EE_ENABLED
Q_INVOKABLE Quotient::SyncJob* syncJob() const;
Q_INVOKABLE int millisToReconnect() const;
@@ -695,10 +698,12 @@ public Q_SLOTS:
PicklingMode picklingMode() const;
QJsonObject decryptNotification(const QJsonObject &notification);
- QStringList devicesForUser(const QString& user) const;
- QString curveKeyForUserDevice(const QString &user, const QString& device) const;
- QString edKeyForUserDevice(const QString& user, const QString& device) const;
- bool isKnownCurveKey(const QString& user, const QString& curveKey);
+ QStringList devicesForUser(const QString& userId) const;
+ QString curveKeyForUserDevice(const QString& userId,
+ const QString& device) const;
+ QString edKeyForUserDevice(const QString& userId,
+ const QString& device) const;
+ bool isKnownCurveKey(const QString& userId, const QString& curveKey) const;
#endif
Q_SIGNALS:
/// \brief Initial server resolution has failed
diff --git a/lib/room.cpp b/lib/room.cpp
index 20ea1159..0cef1025 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -2130,7 +2130,7 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent)
Room::connect(call, &BaseJob::sentRequest, q, [this, txnId] {
auto it = q->findPendingEvent(txnId);
if (it == unsyncedEvents.end()) {
- qCWarning(EVENTS) << "Pending event for transaction" << txnId
+ qWarning(EVENTS) << "Pending event for transaction" << txnId
<< "not found - got synced so soon?";
return;
}
@@ -2140,7 +2140,7 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent)
Room::connect(call, &BaseJob::failure, q,
std::bind(&Room::Private::onEventSendingFailure, this,
txnId, call));
- Room::connect(call, &BaseJob::success, q, [this, call, txnId, _event] {
+ Room::connect(call, &BaseJob::success, q, [this, call, txnId] {
auto it = q->findPendingEvent(txnId);
if (it != unsyncedEvents.end()) {
if (it->deliveryStatus() != EventStatus::ReachedServer) {
@@ -2148,7 +2148,7 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent)
emit q->pendingEventChanged(int(it - unsyncedEvents.begin()));
}
} else
- qCDebug(EVENTS) << "Pending event for transaction" << txnId
+ qDebug(EVENTS) << "Pending event for transaction" << txnId
<< "already merged";
emit q->messageSent(txnId, call->eventId());
@@ -2206,11 +2206,9 @@ QString Room::retryMessage(const QString& txnId)
return d->doSendEvent(it->event());
}
-// Lambda defers actual tr() invocation to the moment when translations are
-// initialised
-const auto FileTransferCancelledMsg = [] {
- return Room::tr("File transfer cancelled");
-};
+// Using a function defers actual tr() invocation to the moment when
+// translations are initialised
+auto FileTransferCancelledMsg() { return Room::tr("File transfer cancelled"); }
void Room::discardMessage(const QString& txnId)
{