Some Improvements

- DeviceVerificationList change to LinkedList to improve time
    complexity while deleting
    - Downgrade the flow to not use key.verification.done and
    key.verification.ready
This commit is contained in:
CH Chethan Reddy 2020-06-23 23:29:00 +05:30
parent ce013e67a6
commit d49ab15656
5 changed files with 26 additions and 27 deletions

View File

@ -110,6 +110,7 @@ Page {
flow.sender = false; flow.sender = false;
flow.deviceId = deviceId; flow.deviceId = deviceId;
flow.tranId = transactionId; flow.tranId = transactionId;
deviceVerificationList.add(flow.tranId);
var dialog = deviceVerificationDialog.createObject(timelineRoot, var dialog = deviceVerificationDialog.createObject(timelineRoot,
{flow: flow,sender: false}); {flow: flow,sender: false});
dialog.show(); dialog.show();

View File

@ -30,7 +30,11 @@ ApplicationWindow {
implicitHeight: currentItem.implicitHeight implicitHeight: currentItem.implicitHeight
} }
onClosing: stack.replace(newVerificationRequest) onClosing: {
flow.cancelVerification();
deviceVerificationList.remove(flow.tranId);
delete flow;
}
property var flow property var flow
Connections { Connections {
@ -78,7 +82,7 @@ ApplicationWindow {
onClicked: { onClicked: {
dialog.close(); dialog.close();
flow.cancelVerification(); flow.cancelVerification();
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -135,7 +139,7 @@ ApplicationWindow {
onClicked: { onClicked: {
dialog.close(); dialog.close();
flow.cancelVerification(); flow.cancelVerification();
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -179,7 +183,7 @@ ApplicationWindow {
onClicked: { onClicked: {
dialog.close(); dialog.close();
flow.cancelVerification(); flow.cancelVerification();
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -230,7 +234,7 @@ ApplicationWindow {
onClicked: { onClicked: {
dialog.close(); dialog.close();
flow.cancelVerification(); flow.cancelVerification();
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -369,7 +373,7 @@ ApplicationWindow {
onClicked: { onClicked: {
dialog.close(); dialog.close();
flow.cancelVerification(); flow.cancelVerification();
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -413,7 +417,7 @@ ApplicationWindow {
onClicked: { onClicked: {
dialog.close(); dialog.close();
flow.cancelVerification(); flow.cancelVerification();
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -451,7 +455,7 @@ ApplicationWindow {
text: "Close" text: "Close"
onClicked: { onClicked: {
dialog.close() dialog.close()
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -485,8 +489,8 @@ ApplicationWindow {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: "Close" text: "Close"
onClicked: { onClicked: {
dialog.close() dialog.close();
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }
@ -521,7 +525,7 @@ ApplicationWindow {
text: "Close" text: "Close"
onClicked: { onClicked: {
dialog.close() dialog.close()
// deviceVerificationList.remove(flow.tranId); deviceVerificationList.remove(flow.tranId);
delete flow; delete flow;
} }
} }

View File

@ -1,7 +1,6 @@
#include "DeviceVerificationFlow.h" #include "DeviceVerificationFlow.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "Logging.h" #include "Logging.h"
#include "Utils.h"
#include <QDateTime> #include <QDateTime>
#include <QTimer> #include <QTimer>
@ -162,7 +161,10 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
} }
if (msg.content.keys == if (msg.content.keys ==
this->sas->calculate_mac(key_string, info + "KEY_IDS")) { this->sas->calculate_mac(key_string, info + "KEY_IDS")) {
this->sendVerificationDone(); // uncomment this in future to be compatible with the
// MSC2366 this->sendVerificationDone(); and remoeve the
// below line
emit this->deviceVerified();
} else { } else {
this->cancelVerification(); this->cancelVerification();
} }

View File

@ -26,26 +26,17 @@ namespace msgs = mtx::events::msg;
void void
DeviceVerificationList::add(QString tran_id) DeviceVerificationList::add(QString tran_id)
{ {
this->dv_list.push_back(tran_id); this->dv_list.append(tran_id);
} }
void void
DeviceVerificationList::remove(QString tran_id) DeviceVerificationList::remove(QString tran_id)
{ {
for (QVector<QString>::iterator it = 0; it != (this->dv_list).end(); ++it) { this->dv_list.removeOne(tran_id);
if (*it == tran_id) {
this->dv_list.erase(it);
break;
}
}
} }
bool bool
DeviceVerificationList::exist(QString tran_id) DeviceVerificationList::exist(QString tran_id)
{ {
for (int i = 0; i < (this->dv_list).size(); ++i) { return this->dv_list.contains(tran_id);
if (dv_list[i] == tran_id)
return true;
}
return false;
} }
void void
@ -183,7 +174,7 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
msg.content.methods.end(), msg.content.methods.end(),
mtx::events::msg::VerificationMethods::SASv1) != mtx::events::msg::VerificationMethods::SASv1) !=
msg.content.methods.end()) { msg.content.methods.end()) {
flow->sendVerificationReady(); // flow->sendVerificationReady();
emit newDeviceVerificationRequest( emit newDeviceVerificationRequest(
std::move(flow), std::move(flow),
QString::fromStdString(msg.content.transaction_id), QString::fromStdString(msg.content.transaction_id),

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QHash> #include <QHash>
#include <QLinkedList>
#include <QQuickView> #include <QQuickView>
#include <QQuickWidget> #include <QQuickWidget>
#include <QSharedPointer> #include <QSharedPointer>
@ -31,7 +32,7 @@ public:
Q_INVOKABLE bool exist(QString tran_id); Q_INVOKABLE bool exist(QString tran_id);
private: private:
QVector<QString> dv_list; QLinkedList<QString> dv_list;
}; };
class TimelineViewManager : public QObject class TimelineViewManager : public QObject