Add support for listing devices that do not support encryption, add support for logging out devices.
Ticks off another box in #23!
This commit is contained in:
parent
4dce2bce7b
commit
649c5ff86d
5 changed files with 92 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
@ -137,6 +138,27 @@ UserProfile::isSelf() const
|
|||
return this->userid_ == utils::localUser();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue