Adding DeviceList for userprofile

This commit is contained in:
Chethan2k1 2020-05-22 11:17:02 +05:30 committed by CH Chethan Reddy
parent 64f204d984
commit a54a973ad6
5 changed files with 79 additions and 32 deletions

View file

@ -3,6 +3,8 @@ import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2 import QtQuick.Layouts 1.2
import QtQuick.Window 2.3 import QtQuick.Window 2.3
import im.nheko 1.0
ApplicationWindow{ ApplicationWindow{
property var user_data property var user_data
property var colors: currentActivePalette property var colors: currentActivePalette
@ -18,7 +20,21 @@ ApplicationWindow{
userProfileAvatar.url = chat.model.avatarUrl(user_data.userId).replace("mxc://", "image://MxcImage/") userProfileAvatar.url = chat.model.avatarUrl(user_data.userId).replace("mxc://", "image://MxcImage/")
userProfileName.text = user_data.userName userProfileName.text = user_data.userName
matrixUserID.text = user_data.userId matrixUserID.text = user_data.userId
console.log("this is happening"); userProfile.userId = user_data.userId
log_devices()
}
function log_devices()
{
console.log(userProfile.deviceList);
userProfile.deviceList.forEach((item,index)=>{
console.log(item.device_id)
console.log(item.display_name)
})
}
UserProfileContent{
id: userProfile
} }
background: Item{ background: Item{

View file

@ -267,11 +267,7 @@ ApplicationWindow {
model: 7 model: 7
delegate: Rectangle { delegate: Rectangle {
color: "transparent" color: "transparent"
<<<<<<< HEAD
implicitHeight: Qt.application.font.pixelSize * 3
=======
implicitHeight: Qt.application.font.pixelSize * 8 implicitHeight: Qt.application.font.pixelSize * 8
>>>>>>> Add DeviceVerificationFlow dummy and verification test button
implicitWidth: col.width implicitWidth: col.width
ColumnLayout { ColumnLayout {
id: col id: col
@ -414,11 +410,7 @@ ApplicationWindow {
property string title: "Verification timed out" property string title: "Verification timed out"
ColumnLayout { ColumnLayout {
spacing: 16 spacing: 16
<<<<<<< HEAD
Label {
=======
Text { Text {
>>>>>>> Add DeviceVerificationFlow dummy and verification test button
Layout.maximumWidth: 400 Layout.maximumWidth: 400
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true

View file

@ -15,6 +15,7 @@
#include "dialogs/ImageOverlay.h" #include "dialogs/ImageOverlay.h"
#include "emoji/EmojiModel.h" #include "emoji/EmojiModel.h"
#include "emoji/Provider.h" #include "emoji/Provider.h"
#include "../ui/UserProfile.h"
Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents)
@ -86,6 +87,8 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice"); qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice");
qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser"); qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser");
qmlRegisterType<DeviceVerificationFlow>("im.nheko", 1, 0, "DeviceVerificationFlow"); qmlRegisterType<DeviceVerificationFlow>("im.nheko", 1, 0, "DeviceVerificationFlow");
qmlRegisterType<UserProfile>("im.nheko",1,0,"UserProfileContent");
qRegisterMetaType<DeviceInfo>();
qRegisterMetaType<mtx::events::collections::TimelineEvents>(); qRegisterMetaType<mtx::events::collections::TimelineEvents>();
qmlRegisterType<emoji::EmojiModel>("im.nheko.EmojiModel", 1, 0, "EmojiModel"); qmlRegisterType<emoji::EmojiModel>("im.nheko.EmojiModel", 1, 0, "EmojiModel");
qmlRegisterType<emoji::EmojiProxyModel>("im.nheko.EmojiModel", 1, 0, "EmojiProxyModel"); qmlRegisterType<emoji::EmojiProxyModel>("im.nheko.EmojiModel", 1, 0, "EmojiProxyModel");
@ -467,9 +470,3 @@ TimelineViewManager::startDummyVerification()
{ {
emit deviceVerificationRequest(new DeviceVerificationFlow(this)); emit deviceVerificationRequest(new DeviceVerificationFlow(this));
} }
void
TimelineViewManager::startDummyVerification()
{
emit deviceVerificationRequest(new DeviceVerificationFlow(this));
}

View file

@ -1,28 +1,43 @@
#include "UserProfile.h" #include "UserProfile.h"
#include "Logging.h" #include "Logging.h"
#include "MatrixClient.h"
#include "Utils.h" #include "Utils.h"
#include "mtx/responses/crypto.hpp"
#include <iostream>
UserProfile::UserProfile(QObject *parent) UserProfile::UserProfile(QObject *parent)
: QObject(parent) : QObject(parent)
{} {}
QMap<QString, QString> QVector<DeviceInfo>
UserProfile::getDeviceList() UserProfile::getDeviceList(){
{ UserProfile::fetchDeviceList(this->userId);
return this->deviceList; return this->deviceList;
} }
QString
UserProfile::getUserId (){
return this->userId;
}
void void
UserProfile::fetchDeviceList(const QString &userId) UserProfile::setUserId (const QString &user_id){
if(this->userId != userId)
return;
else
this->userId = user_id;
}
void
UserProfile::fetchDeviceList(const QString &userID)
{ {
auto localUser = utils::localUser(); auto localUser = utils::localUser();
mtx::requests::QueryKeys req; mtx::requests::QueryKeys req;
req.device_keys[userId.toStdString()] = {}; mtx::responses::QueryKeys res;
req.device_keys[userID.toStdString()] = {};
http::client()->query_keys( http::client()->query_keys(
req, req,
[user_id = userId.toStdString()](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) { if (err) {
nhlog::net()->warn("failed to query device keys: {} {}", nhlog::net()->warn("failed to query device keys: {} {}",
@ -39,14 +54,18 @@ UserProfile::fetchDeviceList(const QString &userId)
auto devices = res.device_keys.at(user_id); auto devices = res.device_keys.at(user_id);
std::vector<DeviceInfo> deviceInfo; QVector<DeviceInfo> deviceInfo;
for (const auto &d : devices) { for (const auto &d : devices) {
auto device = d.second; auto device = d.second;
// TODO: Verify signatures and ignore those that don't pass. // TODO: Verify signatures and ignore those that don't pass.
deviceInfo.emplace_back(DeviceInfo{ // std::cout<<d.first<<std::endl;
QString::fromStdString(d.first), // std::cout<<device.unsigned_info.device_display_name<<std::endl;
QString::fromStdString(device.unsigned_info.device_display_name)}); DeviceInfo newdevice(QString::fromStdString(d.first),QString::fromStdString(device.unsigned_info.device_display_name))
newdevice->device_id = QString::fromStdString(d.first);
newdevice->display_name = QString::fromStdString(device.unsigned_info.device_display_name)
deviceInfo.append(std::move(newdevice));
} }
std::sort(deviceInfo.begin(), std::sort(deviceInfo.begin(),
@ -54,5 +73,8 @@ UserProfile::fetchDeviceList(const QString &userId)
[](const DeviceInfo &a, const DeviceInfo &b) { [](const DeviceInfo &a, const DeviceInfo &b) {
return a.device_id > b.device_id; return a.device_id > b.device_id;
}); });
this->deviceList = deviceInfo;
emit UserProfile::deviceListUpdated();
}); });
} }

View file

@ -1,29 +1,49 @@
#pragma once #pragma once
#include <QMap>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
struct DeviceInfo #include "MatrixClient.h"
class DeviceInfo
{ {
public:
explicit DeviceInfo(QString device_id,QString display_name){
this->device_id = device_id;
this->display_name = display_name;
}
~DeviceInfo() = default;
DeviceInfo(const DeviceInfo &device){
this->device_id = device.device_id;
this->display_name = device.display_name;
}
QString device_id; QString device_id;
QString display_name; QString display_name;
}; };
Q_DECLARE_METATYPE(DeviceInfo);
class UserProfile : public QObject class UserProfile : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QMap deviceList READ getDeviceList NOTIFY DeviceListUpdated) Q_PROPERTY(QVector<DeviceInfo> deviceList READ getDeviceList NOTIFY deviceListUpdated)
Q_PROPERTY(QString userId READ getUserId WRITE setUserId)
public: public:
// constructor
explicit UserProfile(QObject *parent = 0); explicit UserProfile(QObject *parent = 0);
QMap<QString, QString> getDeviceList(); // getters
QVector<DeviceInfo> getDeviceList();
QString getUserId();
// setters
void setUserId(const QString &userId);
Q_INVOKABLE void fetchDeviceList(const QString &userID); Q_INVOKABLE void fetchDeviceList(const QString &userID);
signals: signals:
void DeviceListUpdated(); void deviceListUpdated();
private: private:
QMap<QString, QString> deviceList; QVector<DeviceInfo> deviceList;
QString userId;
}; };