[WIP] Room-Verification Messages

This commit is contained in:
CH Chethan Reddy 2020-08-09 08:35:15 +05:30
parent 3635c185e9
commit 2e20049b36
15 changed files with 392 additions and 484 deletions

View file

@ -5,13 +5,15 @@
#include "Logging.h"
#include "Utils.h"
#include "mtx/responses/crypto.hpp"
#include "timeline/TimelineModel.h"
#include <iostream> // only for debugging
UserProfile::UserProfile(QString roomid, QString userid, QObject *parent)
UserProfile::UserProfile(QString roomid, QString userid, TimelineModel *parent)
: QObject(parent)
, roomid_(roomid)
, userid_(userid)
, model(parent)
{
fetchDeviceList(this->userid_);
}
@ -185,27 +187,43 @@ UserProfile::startChat()
emit ChatPage::instance()->createRoom(req);
}
void
UserProfile::verifyUser()
DeviceVerificationFlow *
UserProfile::createFlow(bool isVerifyUser)
{
std::cout << "Checking if to start to device verification or room message verification"
<< std::endl;
auto joined_rooms = cache::joinedRooms();
auto room_infos = cache::getRoomInfo(joined_rooms);
if (!isVerifyUser)
return (new DeviceVerificationFlow(this, DeviceVerificationFlow::Type::ToDevice));
else {
std::cout << "CHECKING IF IT TO START ROOM_VERIFICATION OR TO_DEVICE VERIFICATION"
<< std::endl;
auto joined_rooms = cache::joinedRooms();
auto room_infos = cache::getRoomInfo(joined_rooms);
for (std::string room_id : joined_rooms) {
if ((room_infos[QString::fromStdString(room_id)].member_count == 2) &&
cache::isRoomEncrypted(room_id)) {
auto room_members = cache::roomMembers(room_id);
if (std::find(room_members.begin(),
room_members.end(),
(this->userid()).toStdString()) != room_members.end()) {
std::cout << "FOUND A ENCRYPTED ROOM WITH THIS USER : " << room_id
for (std::string room_id : joined_rooms) {
if ((room_infos[QString::fromStdString(room_id)].member_count == 2) &&
cache::isRoomEncrypted(room_id)) {
auto room_members = cache::roomMembers(room_id);
if (std::find(room_members.begin(),
room_members.end(),
(this->userid()).toStdString()) !=
room_members.end()) {
std::cout
<< "FOUND A ENCRYPTED ROOM WITH THIS USER : " << room_id
<< std::endl;
return;
if (this->roomid_.toStdString() == room_id) {
auto newflow = new DeviceVerificationFlow(
this, DeviceVerificationFlow::Type::RoomMsg);
newflow->setModel(this->model);
return (std::move(newflow));
} else {
std::cout << "FOUND A ENCRYPTED ROOM BUT CURRENTLY "
"NOT IN THAT ROOM : "
<< room_id << std::endl;
}
}
}
}
}
std::cout << "DIDN'T FIND A ENCRYPTED ROOM WITH THIS USER" << std::endl;
std::cout << "DIDN'T FIND A ENCRYPTED ROOM WITH THIS USER" << std::endl;
return (new DeviceVerificationFlow(this, DeviceVerificationFlow::Type::ToDevice));
}
}

View file

@ -20,6 +20,7 @@ Q_ENUM_NS(Status)
}
class DeviceVerificationFlow;
class TimelineModel;
class DeviceInfo
{
@ -83,7 +84,7 @@ class UserProfile : public QObject
Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT)
Q_PROPERTY(bool isUserVerified READ getUserStatus CONSTANT)
public:
UserProfile(QString roomid, QString userid, QObject *parent = 0);
UserProfile(QString roomid, QString userid, TimelineModel *parent = nullptr);
DeviceInfoModel *deviceList();
@ -92,18 +93,19 @@ public:
QString avatarUrl();
bool getUserStatus();
Q_INVOKABLE DeviceVerificationFlow *createFlow(bool isVerifyUser);
Q_INVOKABLE void fetchDeviceList(const QString &userID);
Q_INVOKABLE void banUser();
// Q_INVOKABLE void ignoreUser();
Q_INVOKABLE void kickUser();
Q_INVOKABLE void startChat();
Q_INVOKABLE void verifyUser();
private:
QString roomid_, userid_;
std::optional<std::string> cross_verified;
DeviceInfoModel deviceList_;
bool isUserVerified = false;
TimelineModel *model;
void callback_fn(const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err,