diff options
author | Thulinma <jaron@vietors.com> | 2021-10-16 14:17:55 +0200 |
---|---|---|
committer | Thulinma <jaron@vietors.com> | 2021-10-17 00:00:14 +0200 |
commit | 649c5ff86d97ed7036822dc420405d84460d5e96 (patch) | |
tree | b22f528749cc75d60fa1d0266b8d69d0f685ed38 /src | |
parent | Merge pull request #764 from ISSOtm/patch-1 (diff) | |
download | nheko-649c5ff86d97ed7036822dc420405d84460d5e96.tar.xz |
Add support for listing devices that do not support encryption, add support for logging out devices.
Ticks off another box in #23!
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/UserProfile.cpp | 63 | ||||
-rw-r--r-- | src/ui/UserProfile.h | 18 |
2 files changed, 80 insertions, 1 deletions
diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 31ae9f8b..591110af 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -16,6 +16,7 @@ #include "mtx/responses/crypto.hpp" #include "timeline/TimelineModel.h" #include "timeline/TimelineViewManager.h" +#include "ui/UIA.h" UserProfile::UserProfile(QString roomid, QString userid, @@ -138,6 +139,27 @@ UserProfile::isSelf() const } void +UserProfile::signOutDevice(const QString &deviceID) +{ + http::client()->delete_device( + deviceID.toStdString(), + UIA::instance()->genericHandler(tr("Sign out device %1").arg(deviceID)), + [this, deviceID](mtx::http::RequestErr e) { + if (e) { + nhlog::ui()->critical("Failure when attempting to sign out device {}", + deviceID.toStdString()); + return; + } + nhlog::ui()->info("Device {} successfully signed out!", deviceID.toStdString()); + // This is us. Let's update the interface accordingly + if (isSelf() && deviceID.toStdString() == ::http::client()->device_id()) { + ChatPage::instance()->dropToLoginPageCb(tr("You signed out this device.")); + } + refreshDevices(); + }); +} + +void UserProfile::refreshDevices() { cache::client()->markUserKeysOutOfDate({this->userid_.toStdString()}); @@ -221,6 +243,47 @@ UserProfile::updateVerificationStatus() verified}); } + // For self, also query devices without keys + if (isSelf()) { + http::client()->query_devices( + [this, deviceInfo](const mtx::responses::QueryDevices &allDevs, + mtx::http::RequestErr err) mutable { + if (err) { + nhlog::net()->warn("failed to query devices: {} {}", + err->matrix_error.error, + static_cast<int>(err->status_code)); + this->deviceList_.queueReset(std::move(deviceInfo)); + emit devicesChanged(); + return; + } + for (const auto &d : allDevs.devices) { + // First, check if we already have an entry for this device + bool found = false; + for (auto &e : deviceInfo) { + if (e.device_id.toStdString() == d.device_id) { + found = true; + // Gottem! Let's fill in the blanks + e.lastIp = QString::fromStdString(d.last_seen_ip); + e.lastTs = d.last_seen_ts; + break; + } + } + // No entry? Let's add one. + if (!found) { + deviceInfo.push_back({QString::fromStdString(d.device_id), + QString::fromStdString(d.display_name), + verification::NOT_APPLICABLE, + QString::fromStdString(d.last_seen_ip), + d.last_seen_ts}); + } + } + + this->deviceList_.queueReset(std::move(deviceInfo)); + emit devicesChanged(); + }); + return; + } + this->deviceList_.queueReset(std::move(deviceInfo)); emit devicesChanged(); } diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index 68f9c21b..e8bff6ba 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -21,7 +21,8 @@ enum Status SELF, VERIFIED, UNVERIFIED, - BLOCKED + BLOCKED, + NOT_APPLICABLE }; Q_ENUM_NS(Status) } @@ -35,10 +36,22 @@ class DeviceInfo public: DeviceInfo(const QString deviceID, const QString displayName, + verification::Status verification_status_, + const QString lastIp_, + const size_t lastTs_) + : device_id(deviceID) + , display_name(displayName) + , verification_status(verification_status_) + , lastIp(lastIp_) + , lastTs(lastTs_) + {} + DeviceInfo(const QString deviceID, + const QString displayName, verification::Status verification_status_) : device_id(deviceID) , display_name(displayName) , verification_status(verification_status_) + , lastTs(0) {} DeviceInfo() : verification_status(verification::UNVERIFIED) @@ -48,6 +61,8 @@ public: QString display_name; verification::Status verification_status; + QString lastIp; + size_t lastTs; }; class DeviceInfoModel : public QAbstractListModel @@ -121,6 +136,7 @@ public: Q_INVOKABLE void fetchDeviceList(const QString &userID); Q_INVOKABLE void refreshDevices(); Q_INVOKABLE void banUser(); + Q_INVOKABLE void signOutDevice(const QString &deviceID); // Q_INVOKABLE void ignoreUser(); Q_INVOKABLE void kickUser(); Q_INVOKABLE void startChat(); |