mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Remove duplicated verification status calculation
This commit is contained in:
parent
456a41bcdf
commit
47db1e5c65
2 changed files with 55 additions and 53 deletions
|
@ -34,6 +34,7 @@ UserProfile::UserProfile(QString roomid,
|
|||
this,
|
||||
&UserProfile::setGlobalUsername,
|
||||
Qt::QueuedConnection);
|
||||
connect(this, &UserProfile::verificationStatiChanged, &UserProfile::updateVerificationStatus);
|
||||
|
||||
if (isGlobalUserProfile()) {
|
||||
getGlobalProfileData();
|
||||
|
@ -48,22 +49,7 @@ UserProfile::UserProfile(QString roomid,
|
|||
if (user_id != this->userid_.toStdString())
|
||||
return;
|
||||
|
||||
auto status = cache::verificationStatus(user_id);
|
||||
if (!status)
|
||||
return;
|
||||
this->isUserVerified = status->user_verified;
|
||||
emit userStatusChanged();
|
||||
|
||||
for (auto &deviceInfo : deviceList_.deviceList_) {
|
||||
deviceInfo.verification_status =
|
||||
std::find(status->verified_devices.begin(),
|
||||
status->verified_devices.end(),
|
||||
deviceInfo.device_id.toStdString()) == status->verified_devices.end()
|
||||
? verification::UNVERIFIED
|
||||
: verification::VERIFIED;
|
||||
}
|
||||
deviceList_.reset(deviceList_.deviceList_);
|
||||
emit devicesChanged();
|
||||
emit verificationStatiChanged();
|
||||
});
|
||||
fetchDeviceList(this->userid_);
|
||||
}
|
||||
|
@ -170,20 +156,18 @@ UserProfile::fetchDeviceList(const QString &userID)
|
|||
|
||||
cache::client()->query_keys(
|
||||
userID.toStdString(),
|
||||
[other_user_id = userID.toStdString(), this](const UserKeyCache &other_user_keys,
|
||||
[other_user_id = userID.toStdString(), this](const UserKeyCache &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
nhlog::net()->warn("failed to query device keys: {},{}",
|
||||
mtx::errors::to_string(err->matrix_error.errcode),
|
||||
static_cast<int>(err->status_code));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure local key cache is up to date
|
||||
cache::client()->query_keys(
|
||||
utils::localUser().toStdString(),
|
||||
[other_user_id, other_user_keys, this](const UserKeyCache &,
|
||||
mtx::http::RequestErr err) {
|
||||
[this](const UserKeyCache &, mtx::http::RequestErr err) {
|
||||
using namespace mtx;
|
||||
std::string local_user_id = utils::localUser().toStdString();
|
||||
|
||||
|
@ -191,42 +175,56 @@ UserProfile::fetchDeviceList(const QString &userID)
|
|||
nhlog::net()->warn("failed to query device keys: {},{}",
|
||||
mtx::errors::to_string(err->matrix_error.errcode),
|
||||
static_cast<int>(err->status_code));
|
||||
}
|
||||
|
||||
emit verificationStatiChanged();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
UserProfile::updateVerificationStatus()
|
||||
{
|
||||
if (!cache::client() || !cache::client()->isDatabaseReady())
|
||||
return;
|
||||
|
||||
auto user_keys = cache::client()->userKeys(userid_.toStdString());
|
||||
if (!user_keys) {
|
||||
this->hasMasterKey = false;
|
||||
this->isUserVerified = crypto::Trust::Unverified;
|
||||
this->deviceList_.reset({});
|
||||
emit userStatusChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
this->hasMasterKey = !other_user_keys.master_keys.keys.empty();
|
||||
this->hasMasterKey = !user_keys->master_keys.keys.empty();
|
||||
|
||||
std::vector<DeviceInfo> deviceInfo;
|
||||
auto devices = other_user_keys.device_keys;
|
||||
auto verificationStatus = cache::client()->verificationStatus(other_user_id);
|
||||
auto devices = user_keys->device_keys;
|
||||
auto verificationStatus = cache::client()->verificationStatus(userid_.toStdString());
|
||||
|
||||
isUserVerified = verificationStatus.user_verified;
|
||||
this->isUserVerified = verificationStatus.user_verified;
|
||||
emit userStatusChanged();
|
||||
|
||||
for (const auto &d : devices) {
|
||||
auto device = d.second;
|
||||
verification::Status verified = verification::Status::UNVERIFIED;
|
||||
|
||||
if (std::find(verificationStatus.verified_devices.begin(),
|
||||
verification::Status verified =
|
||||
std::find(verificationStatus.verified_devices.begin(),
|
||||
verificationStatus.verified_devices.end(),
|
||||
device.device_id) != verificationStatus.verified_devices.end() &&
|
||||
mtx::crypto::verify_identity_signature(
|
||||
device, DeviceId(device.device_id), UserId(other_user_id)))
|
||||
verified = verification::Status::VERIFIED;
|
||||
device.device_id) == verificationStatus.verified_devices.end()
|
||||
? verification::UNVERIFIED
|
||||
: verification::VERIFIED;
|
||||
|
||||
if (isSelf() && device.device_id == ::http::client()->device_id())
|
||||
verified = verification::Status::SELF;
|
||||
|
||||
deviceInfo.push_back(
|
||||
{QString::fromStdString(d.first),
|
||||
deviceInfo.push_back({QString::fromStdString(d.first),
|
||||
QString::fromStdString(device.unsigned_info.device_display_name),
|
||||
verified});
|
||||
}
|
||||
|
||||
this->deviceList_.queueReset(std::move(deviceInfo));
|
||||
emit devicesChanged();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -137,11 +137,15 @@ signals:
|
|||
void globalUsernameRetrieved(const QString &globalUser);
|
||||
void devicesChanged();
|
||||
|
||||
// internal
|
||||
void verificationStatiChanged();
|
||||
|
||||
public slots:
|
||||
void updateAvatarUrl();
|
||||
|
||||
protected slots:
|
||||
private slots:
|
||||
void setGlobalUsername(const QString &globalUser);
|
||||
void updateVerificationStatus();
|
||||
|
||||
private:
|
||||
void updateRoomMemberState(mtx::events::state::Member member);
|
||||
|
|
Loading…
Reference in a new issue