summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authorCH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com>2020-08-09 08:35:15 +0530
committerCH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com>2020-08-09 08:35:15 +0530
commit2e20049b3695d0aa7ca09db079bcc39c0485d098 (patch)
tree664dfdabdd940f217fac4d55c55e9f47358036ee /src/ui
parentAdd Room Verification Messages (diff)
downloadnheko-2e20049b3695d0aa7ca09db079bcc39c0485d098.tar.xz
[WIP] Room-Verification Messages
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/UserProfile.cpp56
-rw-r--r--src/ui/UserProfile.h6
2 files changed, 41 insertions, 21 deletions
diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp
index 3499384c..1eaa9d27 100644
--- a/src/ui/UserProfile.cpp
+++ b/src/ui/UserProfile.cpp
@@ -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);
-
-        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
+        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
                                           << 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));
+        }
 }
\ No newline at end of file
diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h
index 3f9cbe6f..3d0d2981 100644
--- a/src/ui/UserProfile.h
+++ b/src/ui/UserProfile.h
@@ -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,