diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index dbd93d1f..7c018aff 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -1,19 +1,7 @@
-/*
- * nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+// SPDX-FileCopyrightText: 2017 Konstantinos Sideris <siderisk@auth.gr>
+// SPDX-FileCopyrightText: 2021 Nheko Contributors
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
#include <QApplication>
#include <QImageReader>
@@ -252,6 +240,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
this, &ChatPage::updateGroupsInfo, communitiesList_, &CommunitiesList::setCommunities);
connect(this, &ChatPage::leftRoom, this, &ChatPage::removeRoom);
+ connect(this, &ChatPage::newRoom, this, &ChatPage::changeRoom, Qt::QueuedConnection);
connect(this, &ChatPage::notificationsRetrieved, this, &ChatPage::sendNotifications);
connect(this,
&ChatPage::highlightedNotifsRetrieved,
@@ -474,6 +463,8 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
http::client()->set_server(homeserver.toStdString());
http::client()->set_access_token(token.toStdString());
+ http::client()->verify_certificates(
+ !UserSettings::instance()->disableCertificateValidation());
// The Olm client needs the user_id & device_id that will be included
// in the generated payloads & keys.
@@ -762,7 +753,11 @@ ChatPage::startInitialSync()
const auto err_code = mtx::errors::to_string(err->matrix_error.errcode);
const int status_code = static_cast<int>(err->status_code);
- nhlog::net()->error("initial sync error: {} {}", status_code, err_code);
+ nhlog::net()->error("initial sync error: {} {} {} {}",
+ err->parse_error,
+ status_code,
+ err->error_code.message(),
+ err_code);
// non http related errors
if (status_code <= 0 || status_code >= 600) {
@@ -865,11 +860,14 @@ ChatPage::trySync()
http::client()->sync(
opts,
- [this, since = cache::nextBatchToken()](const mtx::responses::Sync &res,
- mtx::http::RequestErr err) {
- if (since != cache::nextBatchToken()) {
- nhlog::net()->warn("Duplicate sync, dropping");
- return;
+ [this, since = opts.since](const mtx::responses::Sync &res, mtx::http::RequestErr err) {
+ try {
+ if (since != cache::nextBatchToken()) {
+ nhlog::net()->warn("Duplicate sync, dropping");
+ return;
+ }
+ } catch (const lmdb::error &e) {
+ nhlog::db()->warn("Logged out in the mean time, dropping sync");
}
if (err) {
@@ -888,7 +886,11 @@ ChatPage::trySync()
return;
}
- nhlog::net()->error("sync error: {} {}", status_code, err_code);
+ nhlog::net()->error("initial sync error: {} {} {} {}",
+ err->parse_error,
+ status_code,
+ err->error_code.message(),
+ err_code);
emit tryDelayedSyncCb();
return;
}
@@ -901,12 +903,22 @@ void
ChatPage::joinRoom(const QString &room)
{
const auto room_id = room.toStdString();
- joinRoomVia(room_id, {});
+ joinRoomVia(room_id, {}, false);
}
void
-ChatPage::joinRoomVia(const std::string &room_id, const std::vector<std::string> &via)
+ChatPage::joinRoomVia(const std::string &room_id,
+ const std::vector<std::string> &via,
+ bool promptForConfirmation)
{
+ if (promptForConfirmation &&
+ QMessageBox::Yes !=
+ QMessageBox::question(
+ this,
+ tr("Confirm join"),
+ tr("Do you really want to join %1?").arg(QString::fromStdString(room_id))))
+ return;
+
http::client()->join_room(
room_id, via, [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) {
if (err) {
@@ -947,8 +959,9 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req)
return;
}
- emit showNotification(
- tr("Room %1 created.").arg(QString::fromStdString(res.room_id.to_string())));
+ QString newRoomId = QString::fromStdString(res.room_id.to_string());
+ emit showNotification(tr("Room %1 created.").arg(newRoomId));
+ emit newRoom(newRoomId);
});
}
@@ -970,6 +983,13 @@ ChatPage::leaveRoom(const QString &room_id)
}
void
+ChatPage::changeRoom(const QString &room_id)
+{
+ view_manager_->setHistoryView(room_id);
+ room_list_->highlightSelectedRoom(room_id);
+}
+
+void
ChatPage::inviteUser(QString userid, QString reason)
{
auto room = current_room_;
@@ -1295,6 +1315,13 @@ ChatPage::startChat(QString userid)
}
}
+ if (QMessageBox::Yes !=
+ QMessageBox::question(
+ this,
+ tr("Confirm invite"),
+ tr("Do you really want to start a private chat with %1?").arg(userid)))
+ return;
+
mtx::requests::CreateRoom req;
req.preset = mtx::requests::Preset::PrivateChat;
req.visibility = mtx::common::RoomVisibility::Private;
@@ -1349,7 +1376,7 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
return;
QString mxid2;
- if (segments.size() == 4 && segments[2] == "e") {
+ if (segments.size() == 4 && segments[2] == "event") {
if (segments[3].isEmpty())
return;
else
@@ -1383,11 +1410,11 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
for (auto roomid : joined_rooms) {
if (roomid == targetRoomId) {
room_list_->highlightSelectedRoom(mxid1);
- break;
+ return;
}
}
- if (action == "join") {
+ if (action == "join" || action.isEmpty()) {
joinRoomVia(targetRoomId, vias);
}
} else if (sigil1 == "r") {
@@ -1400,12 +1427,12 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
if (aliases->alias == targetRoomAlias) {
room_list_->highlightSelectedRoom(
QString::fromStdString(roomid));
- break;
+ return;
}
}
}
- if (action == "join") {
+ if (action == "join" || action.isEmpty()) {
joinRoomVia(mxid1.toStdString(), vias);
}
}
|