diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 86f59c52..94e6a0d7 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -143,9 +143,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
, colorImgProvider(new ColorImageProvider())
, blurhashProvider(new BlurhashProvider())
, jdenticonProvider(new JdenticonProvider())
- , callManager_(callManager)
, rooms_(new RoomlistModel(this))
, communities_(new CommunitiesModel(this))
+ , callManager_(callManager)
+ , verificationManager_(new VerificationManager(this))
{
qRegisterMetaType<mtx::events::msg::KeyVerificationAccept>();
qRegisterMetaType<mtx::events::msg::KeyVerificationCancel>();
@@ -244,6 +245,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
"im.nheko", 1, 0, "Nheko", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new Nheko();
});
+ qmlRegisterSingletonInstance("im.nheko", 1, 0, "VerificationManager", verificationManager_);
qmlRegisterSingletonType<SelfVerificationStatus>(
"im.nheko", 1, 0, "SelfVerificationStatus", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new SelfVerificationStatus();
@@ -285,63 +287,16 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
connect(parent, &ChatPage::themeChanged, this, &TimelineViewManager::updateColorPalette);
connect(dynamic_cast<ChatPage *>(parent),
&ChatPage::receivedRoomDeviceVerificationRequest,
- this,
- [this](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &message,
- TimelineModel *model) {
- if (this->isInitialSync_)
- return;
-
- auto event_id = QString::fromStdString(message.event_id);
- if (!this->dvList.contains(event_id)) {
- if (auto flow = DeviceVerificationFlow::NewInRoomVerification(
- this,
- model,
- message.content,
- QString::fromStdString(message.sender),
- event_id)) {
- dvList[event_id] = flow;
- emit newDeviceVerificationRequest(flow.data());
- }
- }
- });
+ verificationManager_,
+ &VerificationManager::receivedRoomDeviceVerificationRequest);
connect(dynamic_cast<ChatPage *>(parent),
&ChatPage::receivedDeviceVerificationRequest,
- this,
- [this](const mtx::events::msg::KeyVerificationRequest &msg, std::string sender) {
- if (this->isInitialSync_)
- return;
-
- if (!msg.transaction_id)
- return;
-
- auto txnid = QString::fromStdString(msg.transaction_id.value());
- if (!this->dvList.contains(txnid)) {
- if (auto flow = DeviceVerificationFlow::NewToDeviceVerification(
- this, msg, QString::fromStdString(sender), txnid)) {
- dvList[txnid] = flow;
- emit newDeviceVerificationRequest(flow.data());
- }
- }
- });
+ verificationManager_,
+ &VerificationManager::receivedDeviceVerificationRequest);
connect(dynamic_cast<ChatPage *>(parent),
&ChatPage::receivedDeviceVerificationStart,
- this,
- [this](const mtx::events::msg::KeyVerificationStart &msg, std::string sender) {
- if (this->isInitialSync_)
- return;
-
- if (!msg.transaction_id)
- return;
-
- auto txnid = QString::fromStdString(msg.transaction_id.value());
- if (!this->dvList.contains(txnid)) {
- if (auto flow = DeviceVerificationFlow::NewToDeviceVerification(
- this, msg, QString::fromStdString(sender), txnid)) {
- dvList[txnid] = flow;
- emit newDeviceVerificationRequest(flow.data());
- }
- }
- });
+ verificationManager_,
+ &VerificationManager::receivedDeviceVerificationStart);
connect(parent, &ChatPage::loggedOut, this, [this]() {
isInitialSync_ = true;
emit initialSyncChanged(true);
@@ -476,58 +431,6 @@ TimelineViewManager::openImageOverlayInternal(QString eventId, QImage img)
}
void
-TimelineViewManager::verifyUser(QString userid)
-{
- 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(), (userid).toStdString()) !=
- room_members.end()) {
- if (auto model = rooms_->getRoomById(QString::fromStdString(room_id))) {
- auto flow =
- DeviceVerificationFlow::InitiateUserVerification(this, model.data(), userid);
- connect(model.data(),
- &TimelineModel::updateFlowEventId,
- this,
- [this, flow](std::string eventId) {
- dvList[QString::fromStdString(eventId)] = flow;
- });
- emit newDeviceVerificationRequest(flow.data());
- return;
- }
- }
- }
- }
-
- emit ChatPage::instance()->showNotification(
- tr("No encrypted private chat found with this user. Create an "
- "encrypted private chat with this user and try again."));
-}
-
-void
-TimelineViewManager::removeVerificationFlow(DeviceVerificationFlow *flow)
-{
- for (auto it = dvList.keyValueBegin(); it != dvList.keyValueEnd(); ++it) {
- if ((*it).second == flow) {
- dvList.remove((*it).first);
- return;
- }
- }
-}
-
-void
-TimelineViewManager::verifyDevice(QString userid, QString deviceid)
-{
- auto flow = DeviceVerificationFlow::InitiateDeviceVerification(this, userid, deviceid);
- this->dvList[flow->transactionId()] = flow;
- emit newDeviceVerificationRequest(flow.data());
-}
-
-void
TimelineViewManager::updateReadReceipts(const QString &room_id,
const std::vector<QString> &event_ids)
{
|