Adding icons to UserProfile

This commit is contained in:
CH Chethan Reddy 2020-07-05 21:33:27 +05:30
parent 08028d5c57
commit 1103cc15cf
9 changed files with 164 additions and 81 deletions

View file

@ -15,9 +15,6 @@ set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Require C++ standard to be supported") set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Require C++ standard to be supported")
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "compile as PIC by default") set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "compile as PIC by default")
# set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
# set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
option(HUNTER_ENABLED "Enable Hunter package manager" OFF) option(HUNTER_ENABLED "Enable Hunter package manager" OFF)
include("cmake/HunterGate.cmake") include("cmake/HunterGate.cmake")
HunterGate( HunterGate(

View file

@ -106,7 +106,7 @@ Page {
} }
Connections { Connections {
target: TimelineManager target: TimelineManager
function onNewDeviceVerificationRequest(flow) { function onNewDeviceVerificationRequest(flow,transactionId,userId,deviceId) {
flow.userId = userId; flow.userId = userId;
flow.sender = false; flow.sender = false;
flow.deviceId = deviceId; flow.deviceId = deviceId;

View file

@ -17,6 +17,13 @@ ApplicationWindow{
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
palette: colors palette: colors
Connections{
target: deviceVerificationList
onUpdateProfile: {
profile.fetchDeviceList(profile.userid)
}
}
Component { Component {
id: deviceVerificationDialog id: deviceVerificationDialog
DeviceVerification {} DeviceVerification {}
@ -139,7 +146,6 @@ ApplicationWindow{
top : 50 top : 50
} }
ColumnLayout{ ColumnLayout{
RowLayout{
Text{ Text{
Layout.fillWidth: true Layout.fillWidth: true
color: colors.text color: colors.text
@ -147,13 +153,6 @@ ApplicationWindow{
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
text: model.deviceId text: model.deviceId
} }
Text{
Layout.fillWidth: true
color:colors.text
Layout.alignment: Qt.AlignLeft
text: (model.verificationStatus == VerificationStatus.VERIFIED?"V":(model.verificationStatus == VerificationStatus.UNVERIFIED?"NV":"B"))
}
}
Text{ Text{
Layout.fillWidth: true Layout.fillWidth: true
color:colors.text color:colors.text
@ -161,16 +160,29 @@ ApplicationWindow{
text: model.deviceName text: model.deviceName
} }
} }
RowLayout{
Image{
Layout.preferredWidth: 20
Layout.preferredHeight: 20
source: ((model.verificationStatus == VerificationStatus.VERIFIED)?"image://colorimage/:/icons/icons/ui/lock.png?green":
((model.verificationStatus == VerificationStatus.UNVERIFIED)?"image://colorimage/:/icons/icons/ui/unlock.png?yellow":
"image://colorimage/:/icons/icons/ui/unlock.png?red"))
}
Button{ Button{
id: verifyButton id: verifyButton
text:"Verify" text:(model.verificationStatus != VerificationStatus.VERIFIED)?"Verify":"Unverify"
onClicked: { onClicked: {
var newFlow = deviceVerificationFlow.createObject(userProfileDialog, var newFlow = deviceVerificationFlow.createObject(userProfileDialog,
{userId : profile.userid, sender: true, deviceId : model.deviceID}); {userId : profile.userid, sender: true, deviceId : model.deviceId});
if(model.verificationStatus == VerificationStatus.VERIFIED){
newFlow.unverify();
deviceVerificationList.updateProfile(newFlow.userId);
}else{
deviceVerificationList.add(newFlow.tranId); deviceVerificationList.add(newFlow.tranId);
var dialog = deviceVerificationDialog.createObject(userProfileDialog, {flow: newFlow}); var dialog = deviceVerificationDialog.createObject(userProfileDialog, {flow: newFlow});
dialog.show(); dialog.show();
} }
}
Layout.margins:{ Layout.margins:{
right: 10 right: 10
} }
@ -187,6 +199,7 @@ ApplicationWindow{
} }
} }
} }
}
Button{ Button{
id: okbutton id: okbutton

View file

@ -33,6 +33,10 @@ ApplicationWindow {
case DeviceVerificationFlow.Decimal: stack.replace(digitVerification); break; case DeviceVerificationFlow.Decimal: stack.replace(digitVerification); break;
case DeviceVerificationFlow.Emoji: stack.replace(emojiVerification); break; case DeviceVerificationFlow.Emoji: stack.replace(emojiVerification); break;
} }
onRefreshProfile: {
deviceVerificationList.updateProfile(flow.userId);
}
} }
Component { Component {

View file

@ -1,4 +1,5 @@
#include "DeviceVerificationFlow.h" #include "DeviceVerificationFlow.h"
#include "Cache.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "Logging.h" #include "Logging.h"
@ -181,9 +182,9 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
// uncomment this in future to be compatible with the // uncomment this in future to be compatible with the
// MSC2366 this->sendVerificationDone(); and remove the // MSC2366 this->sendVerificationDone(); and remove the
// below line // below line
if (this->isMacVerified == true) if (this->isMacVerified == true) {
emit this->deviceVerified(); this->acceptDevice();
else } else
this->isMacVerified = true; this->isMacVerified = true;
} else { } else {
this->cancelVerification( this->cancelVerification(
@ -208,7 +209,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
auto msg = auto msg =
std::get<mtx::events::DeviceEvent<msgs::KeyVerificationDone>>(message); std::get<mtx::events::DeviceEvent<msgs::KeyVerificationDone>>(message);
if (msg.content.transaction_id == this->transaction_id) { if (msg.content.transaction_id == this->transaction_id) {
emit this->deviceVerified(); this->acceptDevice();
} }
}); });
timeout->start(TIMEOUT); timeout->start(TIMEOUT);
@ -261,34 +262,20 @@ DeviceVerificationFlow::setUserId(QString userID)
{ {
this->userId = userID; this->userId = userID;
this->toClient = mtx::identifiers::parse<mtx::identifiers::User>(userID.toStdString()); this->toClient = mtx::identifiers::parse<mtx::identifiers::User>(userID.toStdString());
auto user_cache = cache::getUserCache(userID.toStdString());
mtx::responses::QueryKeys res; if (user_cache.has_value()) {
this->callback_fn(user_cache->keys, {}, userID.toStdString());
} else {
mtx::requests::QueryKeys req; mtx::requests::QueryKeys req;
req.device_keys[userID.toStdString()] = {}; req.device_keys[userID.toStdString()] = {};
http::client()->query_keys( http::client()->query_keys(
req, req,
[user_id = userID.toStdString(), this](const mtx::responses::QueryKeys &res, [user_id = userID.toStdString(), this](const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err) { mtx::http::RequestErr err) {
if (err) { this->callback_fn(res, err, user_id);
nhlog::net()->warn("failed to query device keys: {},{}",
err->matrix_error.errcode,
static_cast<int>(err->status_code));
return;
}
for (auto x : res.device_keys) {
for (auto y : x.second) {
auto z = y.second;
if (z.user_id == user_id &&
z.device_id == this->deviceId.toStdString()) {
for (auto a : z.keys) {
// TODO: Verify Signatures
this->device_keys[a.first] = a.second;
}
}
}
}
}); });
}
} }
void void
@ -482,6 +469,16 @@ DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_c
nhlog::net()->warn("failed to cancel verification request: {} {}", nhlog::net()->warn("failed to cancel verification request: {} {}",
err->matrix_error.error, err->matrix_error.error,
static_cast<int>(err->status_code)); static_cast<int>(err->status_code));
auto verified_cache = cache::getVerifiedCache(this->userId.toStdString());
if (verified_cache.has_value()) {
verified_cache->device_blocked.push_back(this->deviceId.toStdString());
cache::setVerifiedCache(this->userId.toStdString(),
verified_cache.value());
} else {
cache::setVerifiedCache(
this->userId.toStdString(),
DeviceVerifiedCache{{}, {this->deviceId.toStdString()}});
}
this->deleteLater(); this->deleteLater();
}); });
} }
@ -546,7 +543,7 @@ DeviceVerificationFlow::sendVerificationMac()
static_cast<int>(err->status_code)); static_cast<int>(err->status_code));
if (this->isMacVerified == true) if (this->isMacVerified == true)
emit this->deviceVerified(); this->acceptDevice();
else else
this->isMacVerified = true; this->isMacVerified = true;
}); });
@ -555,8 +552,69 @@ DeviceVerificationFlow::sendVerificationMac()
void void
DeviceVerificationFlow::acceptDevice() DeviceVerificationFlow::acceptDevice()
{ {
emit deviceVerified(); auto verified_cache = cache::getVerifiedCache(this->userId.toStdString());
this->deleteLater(); if (verified_cache.has_value()) {
verified_cache->device_verified.push_back(this->deviceId.toStdString());
for (auto it = verified_cache->device_blocked.begin();
it != verified_cache->device_blocked.end();
it++) {
if (*it == this->deviceId.toStdString()) {
verified_cache->device_blocked.erase(it);
}
}
cache::setVerifiedCache(this->userId.toStdString(), verified_cache.value());
} else {
cache::setVerifiedCache(this->userId.toStdString(),
DeviceVerifiedCache{{this->deviceId.toStdString()}, {}});
}
// Yet to add send to_device message emit deviceVerified();
emit refreshProfile();
this->deleteLater();
}
//! callback function to keep track of devices
void
DeviceVerificationFlow::callback_fn(const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err,
std::string user_id)
{
if (err) {
nhlog::net()->warn("failed to query device keys: {},{}",
err->matrix_error.errcode,
static_cast<int>(err->status_code));
return;
}
if (res.device_keys.empty() || (res.device_keys.find(user_id) == res.device_keys.end())) {
nhlog::net()->warn("no devices retrieved {}", user_id);
return;
}
for (auto x : res.device_keys) {
for (auto y : x.second) {
auto z = y.second;
if (z.user_id == user_id && z.device_id == this->deviceId.toStdString()) {
for (auto a : z.keys) {
// TODO: Verify Signatures
this->device_keys[a.first] = a.second;
}
}
}
}
}
void
DeviceVerificationFlow::unverify()
{
auto verified_cache = cache::getVerifiedCache(this->userId.toStdString());
if (verified_cache.has_value()) {
auto it = std::remove(verified_cache->device_verified.begin(),
verified_cache->device_verified.end(),
this->deviceId.toStdString());
verified_cache->device_verified.erase(it);
cache::setVerifiedCache(this->userId.toStdString(), verified_cache.value());
}
emit refreshProfile();
this->deleteLater();
} }

View file

@ -51,6 +51,9 @@ public:
void setDeviceId(QString deviceID); void setDeviceId(QString deviceID);
void setMethod(Method method_); void setMethod(Method method_);
void setSender(bool sender_); void setSender(bool sender_);
void callback_fn(const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err,
std::string user_id);
nlohmann::json canonical_json; nlohmann::json canonical_json;
@ -73,12 +76,15 @@ public slots:
void sendVerificationMac(); void sendVerificationMac();
//! Completes the verification flow //! Completes the verification flow
void acceptDevice(); void acceptDevice();
//! unverifies a device
void unverify();
signals: signals:
void verificationRequestAccepted(Method method); void verificationRequestAccepted(Method method);
void deviceVerified(); void deviceVerified();
void timedout(); void timedout();
void verificationCanceled(); void verificationCanceled();
void refreshProfile();
private: private:
QString userId; QString userId;

View file

@ -29,6 +29,8 @@ public:
Q_INVOKABLE void add(QString tran_id); Q_INVOKABLE void add(QString tran_id);
Q_INVOKABLE void remove(QString tran_id); Q_INVOKABLE void remove(QString tran_id);
Q_INVOKABLE bool exist(QString tran_id); Q_INVOKABLE bool exist(QString tran_id);
signals:
void updateProfile(QString userId);
private: private:
QVector<QString> deviceVerificationList; QVector<QString> deviceVerificationList;

View file

@ -1,6 +1,7 @@
#include "UserProfile.h" #include "UserProfile.h"
#include "Cache.h" #include "Cache.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "DeviceVerificationFlow.h"
#include "Logging.h" #include "Logging.h"
#include "Utils.h" #include "Utils.h"
#include "mtx/responses/crypto.hpp" #include "mtx/responses/crypto.hpp"
@ -122,10 +123,10 @@ UserProfile::callback_fn(const mtx::responses::QueryKeys &res,
verified}); verified});
} }
// std::sort( std::sort(
// deviceInfo.begin(), deviceInfo.end(), [](const DeviceInfo &a, const DeviceInfo &b) { deviceInfo.begin(), deviceInfo.end(), [](const DeviceInfo &a, const DeviceInfo &b) {
// return a.device_id > b.device_id; return a.device_id > b.device_id;
// }); });
this->deviceList_.queueReset(std::move(deviceInfo)); this->deviceList_.queueReset(std::move(deviceInfo));
} }

View file

@ -19,6 +19,8 @@ enum Status
Q_ENUM_NS(Status) Q_ENUM_NS(Status)
} }
class DeviceVerificationFlow;
class DeviceInfo class DeviceInfo
{ {
public: public:
@ -88,7 +90,7 @@ public:
QString displayName(); QString displayName();
QString avatarUrl(); QString avatarUrl();
void fetchDeviceList(const QString &userID); Q_INVOKABLE void fetchDeviceList(const QString &userID);
Q_INVOKABLE void banUser(); Q_INVOKABLE void banUser();
// Q_INVOKABLE void ignoreUser(); // Q_INVOKABLE void ignoreUser();
Q_INVOKABLE void kickUser(); Q_INVOKABLE void kickUser();