diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-07-15 19:09:08 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-07-15 19:09:08 +0300 |
commit | 33490eddab385ca488b11d6d50683ddb6a18da6c (patch) | |
tree | f597b53c3baf0c96a0d7226f28f50740acd8b256 /src | |
parent | User reverse iterator instead of while loop (diff) | |
download | nheko-33490eddab385ca488b11d6d50683ddb6a18da6c.tar.xz |
Remove the v2 namespace from the http client
Diffstat (limited to 'src')
-rw-r--r-- | src/AvatarProvider.cc | 2 | ||||
-rw-r--r-- | src/ChatPage.cc | 72 | ||||
-rw-r--r-- | src/CommunitiesList.cc | 8 | ||||
-rw-r--r-- | src/LoginPage.cc | 34 | ||||
-rw-r--r-- | src/MainWindow.cc | 20 | ||||
-rw-r--r-- | src/MatrixClient.cc | 9 | ||||
-rw-r--r-- | src/Olm.cpp | 33 | ||||
-rw-r--r-- | src/RegisterPage.cc | 17 | ||||
-rw-r--r-- | src/RoomList.cc | 2 | ||||
-rw-r--r-- | src/dialogs/ReCaptcha.cpp | 4 | ||||
-rw-r--r-- | src/dialogs/RoomSettings.cpp | 6 | ||||
-rw-r--r-- | src/main.cc | 4 | ||||
-rw-r--r-- | src/timeline/TimelineItem.cc | 22 | ||||
-rw-r--r-- | src/timeline/TimelineView.cc | 69 | ||||
-rw-r--r-- | src/timeline/widgets/AudioItem.cc | 2 | ||||
-rw-r--r-- | src/timeline/widgets/FileItem.cc | 6 | ||||
-rw-r--r-- | src/timeline/widgets/ImageItem.cc | 42 |
17 files changed, 173 insertions, 179 deletions
diff --git a/src/AvatarProvider.cc b/src/AvatarProvider.cc index 391f57d9..b4c1188a 100644 --- a/src/AvatarProvider.cc +++ b/src/AvatarProvider.cc @@ -52,7 +52,7 @@ resolve(const QString &room_id, const QString &user_id, QObject *receiver, Avata mtx::http::ThumbOpts opts; opts.mxc_url = avatarUrl.toStdString(); - http::v2::client()->get_thumbnail( + http::client()->get_thumbnail( opts, [opts, proxy = std::move(proxy)](const std::string &res, mtx::http::RequestErr err) { if (err) { diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 7f6306f6..ff059cee 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -133,7 +133,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) connect(this, &ChatPage::connectionLost, this, [this]() { nhlog::net()->info("connectivity lost"); isConnected_ = false; - http::v2::client()->shutdown(); + http::client()->shutdown(); text_input_->disableInput(); }); connect(this, &ChatPage::connectionRestored, this, [this]() { @@ -142,18 +142,18 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) isConnected_ = true; // Drop all pending connections. - http::v2::client()->shutdown(); + http::client()->shutdown(); trySync(); }); connectivityTimer_.setInterval(CHECK_CONNECTIVITY_INTERVAL); connect(&connectivityTimer_, &QTimer::timeout, this, [=]() { - if (http::v2::client()->access_token().empty()) { + if (http::client()->access_token().empty()) { connectivityTimer_.stop(); return; } - http::v2::client()->versions( + http::client()->versions( [this](const mtx::responses::Versions &, mtx::http::RequestErr err) { if (err) { emit connectionLost(); @@ -167,7 +167,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) connect(this, &ChatPage::loggedOut, this, &ChatPage::logout); connect(user_info_widget_, &UserInfoWidget::logout, this, [this]() { - http::v2::client()->logout( + http::client()->logout( [this](const mtx::responses::Logout &, mtx::http::RequestErr err) { if (err) { // TODO: handle special errors @@ -193,7 +193,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) QTimer::singleShot(ii * 500, this, [this, room_id, ii, users]() { const auto user = users.at(ii); - http::v2::client()->invite_user( + http::client()->invite_user( room_id, user.toStdString(), [this, user](const mtx::responses::RoomInvite &, @@ -254,7 +254,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) if (current_room_.isEmpty()) return; - http::v2::client()->stop_typing( + http::client()->stop_typing( current_room_.toStdString(), [](mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to stop typing notifications: {}", @@ -303,7 +303,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) auto payload = std::string(bin.data(), bin.size()); auto dimensions = QImageReader(dev.data()).size(); - http::v2::client()->upload( + http::client()->upload( payload, mime.name().toStdString(), QFileInfo(fn).fileName().toStdString(), @@ -348,7 +348,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) auto bin = dev->readAll(); auto payload = std::string(bin.data(), bin.size()); - http::v2::client()->upload( + http::client()->upload( payload, mime.name().toStdString(), QFileInfo(fn).fileName().toStdString(), @@ -391,7 +391,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) auto bin = dev->readAll(); auto payload = std::string(bin.data(), bin.size()); - http::v2::client()->upload( + http::client()->upload( payload, mime.name().toStdString(), QFileInfo(fn).fileName().toStdString(), @@ -433,7 +433,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) auto bin = dev->readAll(); auto payload = std::string(bin.data(), bin.size()); - http::v2::client()->upload( + http::client()->upload( payload, mime.name().toStdString(), QFileInfo(fn).fileName().toStdString(), @@ -567,7 +567,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) } if (hasNotifications) - http::v2::client()->notifications( + http::client()->notifications( 5, [this](const mtx::responses::Notifications &res, mtx::http::RequestErr err) { @@ -627,7 +627,7 @@ ChatPage::dropToLoginPage(const QString &msg) deleteConfigs(); resetUI(); - http::v2::client()->shutdown(); + http::client()->shutdown(); connectivityTimer_.stop(); emit showLoginPage(msg); @@ -659,7 +659,7 @@ ChatPage::deleteConfigs() settings.endGroup(); cache::client()->deleteData(); - http::v2::client()->clear(); + http::client()->clear(); } void @@ -668,19 +668,19 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token) using namespace mtx::identifiers; try { - http::v2::client()->set_user(parse<User>(userid.toStdString())); + http::client()->set_user(parse<User>(userid.toStdString())); } catch (const std::invalid_argument &e) { nhlog::ui()->critical("bootstrapped with invalid user_id: {}", userid.toStdString()); } - http::v2::client()->set_server(homeserver.toStdString()); - http::v2::client()->set_access_token(token.toStdString()); + http::client()->set_server(homeserver.toStdString()); + http::client()->set_access_token(token.toStdString()); // The Olm client needs the user_id & device_id that will be included // in the generated payloads & keys. - olm::client()->set_user_id(http::v2::client()->user_id().to_string()); - olm::client()->set_device_id(http::v2::client()->device_id()); + olm::client()->set_user_id(http::client()->user_id().to_string()); + olm::client()->set_device_id(http::client()->device_id()); try { cache::init(userid); @@ -998,7 +998,7 @@ ChatPage::tryInitialSync() nhlog::crypto()->info("generating one time keys"); olm::client()->generate_one_time_keys(MAX_ONETIME_KEYS); - http::v2::client()->upload_keys( + http::client()->upload_keys( olm::client()->create_upload_keys_request(), [this](const mtx::responses::UploadKeys &res, mtx::http::RequestErr err) { if (err) { @@ -1021,11 +1021,11 @@ ChatPage::tryInitialSync() mtx::http::SyncOpts opts; opts.timeout = 0; - http::v2::client()->sync(opts, - std::bind(&ChatPage::initialSyncHandler, - this, - std::placeholders::_1, - std::placeholders::_2)); + http::client()->sync(opts, + std::bind(&ChatPage::initialSyncHandler, + this, + std::placeholders::_1, + std::placeholders::_2)); }); } @@ -1044,7 +1044,7 @@ ChatPage::trySync() return; } - http::v2::client()->sync( + http::client()->sync( opts, [this](const mtx::responses::Sync &res, mtx::http::RequestErr err) { if (err) { const auto error = QString::fromStdString(err->matrix_error.error); @@ -1055,7 +1055,7 @@ ChatPage::trySync() nhlog::net()->error("sync error: {} {}", status_code, err_code); if (status_code <= 0 || status_code >= 600) { - if (!http::v2::is_logged_in()) + if (!http::is_logged_in()) return; emit tryDelayedSyncCb(); @@ -1070,7 +1070,7 @@ ChatPage::trySync() return; } default: { - if (!http::v2::is_logged_in()) + if (!http::is_logged_in()) return; if (err->matrix_error.errcode == @@ -1113,7 +1113,7 @@ ChatPage::joinRoom(const QString &room) { const auto room_id = room.toStdString(); - http::v2::client()->join_room( + http::client()->join_room( room_id, [this, room_id](const nlohmann::json &, mtx::http::RequestErr err) { if (err) { emit showNotification( @@ -1137,7 +1137,7 @@ ChatPage::joinRoom(const QString &room) void ChatPage::createRoom(const mtx::requests::CreateRoom &req) { - http::v2::client()->create_room( + http::client()->create_room( req, [this](const mtx::responses::CreateRoom &res, mtx::http::RequestErr err) { if (err) { emit showNotification( @@ -1154,7 +1154,7 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req) void ChatPage::leaveRoom(const QString &room_id) { - http::v2::client()->leave_room( + http::client()->leave_room( room_id.toStdString(), [this, room_id](const json &, mtx::http::RequestErr err) { if (err) { emit showNotification( @@ -1173,7 +1173,7 @@ ChatPage::sendTypingNotifications() if (!userSettings_->isTypingNotificationsEnabled()) return; - http::v2::client()->start_typing( + http::client()->start_typing( current_room_.toStdString(), 10'000, [](mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to send typing notification: {}", @@ -1236,7 +1236,7 @@ ChatPage::ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts) nhlog::crypto()->info("uploading {} {} keys", nkeys, entry.first); olm::client()->generate_one_time_keys(nkeys); - http::v2::client()->upload_keys( + http::client()->upload_keys( olm::client()->create_upload_keys_request(), [](const mtx::responses::UploadKeys &, mtx::http::RequestErr err) { if (err) { @@ -1259,7 +1259,7 @@ ChatPage::getProfileInfo() QSettings settings; const auto userid = settings.value("auth/user_id").toString().toStdString(); - http::v2::client()->get_profile( + http::client()->get_profile( userid, [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to retrieve own profile info"); @@ -1279,7 +1279,7 @@ ChatPage::getProfileInfo() if (res.avatar_url.empty()) return; - http::v2::client()->download( + http::client()->download( res.avatar_url, [this, res](const std::string &data, const std::string &, @@ -1301,7 +1301,7 @@ ChatPage::getProfileInfo() }); }); - http::v2::client()->joined_groups( + http::client()->joined_groups( [this](const mtx::responses::JoinedGroups &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->critical("failed to retrieve joined groups: {} {}", diff --git a/src/CommunitiesList.cc b/src/CommunitiesList.cc index b2742f59..f2fb0438 100644 --- a/src/CommunitiesList.cc +++ b/src/CommunitiesList.cc @@ -1,5 +1,5 @@ -#include "CommunitiesList.h" #include "Cache.h" +#include "CommunitiesList.h" #include "Logging.hpp" #include "MatrixClient.h" @@ -94,7 +94,7 @@ CommunitiesList::addCommunity(const std::string &group_id) this, &CommunitiesList::highlightSelectedCommunity); - http::v2::client()->group_profile( + http::client()->group_profile( group_id, [id, this](const mtx::responses::GroupProfile &res, mtx::http::RequestErr err) { if (err) { return; @@ -103,7 +103,7 @@ CommunitiesList::addCommunity(const std::string &group_id) emit groupProfileRetrieved(id, res); }); - http::v2::client()->group_rooms( + http::client()->group_rooms( group_id, [id, this](const nlohmann::json &res, mtx::http::RequestErr err) { if (err) { return; @@ -164,7 +164,7 @@ CommunitiesList::fetchCommunityAvatar(const QString &id, const QString &avatarUr mtx::http::ThumbOpts opts; opts.mxc_url = avatarUrl.toStdString(); - http::v2::client()->get_thumbnail( + http::client()->get_thumbnail( opts, [this, opts, id](const std::string &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to download avatar: {} - ({} {})", diff --git a/src/LoginPage.cc b/src/LoginPage.cc index d695a759..6a3b925c 100644 --- a/src/LoginPage.cc +++ b/src/LoginPage.cc @@ -181,7 +181,7 @@ LoginPage::onMatrixIdEntered() inferredServerAddress_ = homeServer; serverInput_->setText(homeServer); - http::v2::client()->set_server(user.hostname()); + http::client()->set_server(user.hostname()); checkHomeserverVersion(); } } @@ -189,7 +189,7 @@ LoginPage::onMatrixIdEntered() void LoginPage::checkHomeserverVersion() { - http::v2::client()->versions( + http::client()->versions( [this](const mtx::responses::Versions &, mtx::http::RequestErr err) { if (err) { using namespace boost::beast::http; @@ -219,7 +219,7 @@ void LoginPage::onServerAddressEntered() { error_label_->setText(""); - http::v2::client()->set_server(serverInput_->text().toStdString()); + http::client()->set_server(serverInput_->text().toStdString()); checkHomeserverVersion(); serverLayout_->removeWidget(errorIcon_); @@ -268,20 +268,20 @@ LoginPage::onLoginButtonClicked() if (password_input_->text().isEmpty()) return loginError(tr("Empty password")); - http::v2::client()->set_server(serverInput_->text().toStdString()); - http::v2::client()->login( - user.localpart(), - password_input_->text().toStdString(), - initialDeviceName(), - [this](const mtx::responses::Login &res, mtx::http::RequestErr err) { - if (err) { - emit loginError(QString::fromStdString(err->matrix_error.error)); - emit errorOccurred(); - return; - } - - emit loginOk(res); - }); + http::client()->set_server(serverInput_->text().toStdString()); + http::client()->login(user.localpart(), + password_input_->text().toStdString(), + initialDeviceName(), + [this](const mtx::responses::Login &res, mtx::http::RequestErr err) { + if (err) { + emit loginError( + QString::fromStdString(err->matrix_error.error)); + emit errorOccurred(); + return; + } + + emit loginOk(res); + }); emit loggingIn(); } diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 37b806d0..749e7caf 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -122,7 +122,7 @@ MainWindow::MainWindow(QWidget *parent) chat_page_, &ChatPage::showUserSettingsPage, this, &MainWindow::showUserSettingsPage); connect(login_page_, &LoginPage::loginOk, this, [this](const mtx::responses::Login &res) { - http::v2::client()->set_user(res.user_id); + http::client()->set_user(res.user_id); showChatPage(); }); @@ -147,13 +147,13 @@ MainWindow::MainWindow(QWidget *parent) QString user_id = settings.value("auth/user_id").toString(); QString device_id = settings.value("auth/device_id").toString(); - http::v2::client()->set_access_token(token.toStdString()); - http::v2::client()->set_server(home_server.toStdString()); - http::v2::client()->set_device_id(device_id.toStdString()); + http::client()->set_access_token(token.toStdString()); + http::client()->set_server(home_server.toStdString()); + http::client()->set_device_id(device_id.toStdString()); try { using namespace mtx::identifiers; - http::v2::client()->set_user(parse<User>(user_id.toStdString())); + http::client()->set_user(parse<User>(user_id.toStdString())); } catch (const std::invalid_argument &e) { nhlog::ui()->critical("bootstrapped with invalid user_id: {}", user_id.toStdString()); @@ -248,11 +248,11 @@ MainWindow::removeOverlayProgressBar() void MainWindow::showChatPage() { - auto userid = QString::fromStdString(http::v2::client()->user_id().to_string()); - auto device_id = QString::fromStdString(http::v2::client()->device_id()); - auto homeserver = QString::fromStdString(http::v2::client()->server() + ":" + - std::to_string(http::v2::client()->port())); - auto token = QString::fromStdString(http::v2::client()->access_token()); + auto userid = QString::fromStdString(http::client()->user_id().to_string()); + auto device_id = QString::fromStdString(http::client()->device_id()); + auto homeserver = QString::fromStdString(http::client()->server() + ":" + + std::to_string(http::client()->port())); + auto token = QString::fromStdString(http::client()->access_token()); QSettings settings; settings.setValue("auth/access_token", token); diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 9e69dbbd..e41c66c1 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -3,26 +3,23 @@ #include <memory> namespace { -auto v2_client_ = std::make_shared<mtx::http::Client>(); +auto client_ = std::make_shared<mtx::http::Client>(); } namespace http { -namespace v2 { mtx::http::Client * client() { - return v2_client_.get(); + return client_.get(); } bool is_logged_in() { - return !v2_client_->access_token().empty(); + return !client_->access_token().empty(); } -} // namespace v2 - void init() { diff --git a/src/Olm.cpp b/src/Olm.cpp index d040e0ca..b3bb4316 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -274,7 +274,7 @@ request_keys(const std::string &room_id, const std::string &event_id) { nhlog::crypto()->info("requesting keys for event {} at {}", event_id, room_id); - http::v2::client()->get_event( + http::client()->get_event( room_id, event_id, [event_id, room_id](const mtx::events::collections::TimelineEvents &res, @@ -306,8 +306,8 @@ send_key_request_for(const std::string &room_id, nhlog::crypto()->debug("sending key request: {}", json(e).dump(2)); auto payload = json{{"action", "request"}, - {"request_id", http::v2::client()->generate_txn_id()}, - {"requesting_device_id", http::v2::client()->device_id()}, + {"request_id", http::client()->generate_txn_id()}, + {"requesting_device_id", http::client()->device_id()}, {"body", {{"algorithm", MEGOLM_ALGO}, {"room_id", room_id}, @@ -320,18 +320,17 @@ send_key_request_for(const std::string &room_id, nhlog::crypto()->debug("m.room_key_request: {}", body.dump(2)); - http::v2::client()->send_to_device( - "m.room_key_request", body, [e](mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn("failed to send " - "send_to_device " - "message: {}", - err->matrix_error.error); - } + http::client()->send_to_device("m.room_key_request", body, [e](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to send " + "send_to_device " + "message: {}", + err->matrix_error.error); + } - nhlog::net()->info( - "m.room_key_request sent to {}:{}", e.sender, e.content.device_id); - }); + nhlog::net()->info( + "m.room_key_request sent to {}:{}", e.sender, e.content.device_id); + }); } void @@ -389,7 +388,7 @@ send_megolm_key_to_device(const std::string &user_id, mtx::requests::QueryKeys req; req.device_keys[user_id] = {device_id}; - http::v2::client()->query_keys( + http::client()->query_keys( req, [payload, user_id, device_id](const mtx::responses::QueryKeys &res, mtx::http::RequestErr err) { @@ -447,7 +446,7 @@ send_megolm_key_to_device(const std::string &user_id, ->create_room_key_event(UserId(user_id), pks.ed25519, payload) .dump(); - http::v2::client()->claim_keys( + http::client()->claim_keys( user_id, {device_id}, [room_key, user_id, device_id, pks](const mtx::responses::ClaimKeys &res, @@ -512,7 +511,7 @@ send_megolm_key_to_device(const std::string &user_id, nhlog::net()->info( "sending m.room_key event to {}:{}", user_id, device_id); - http::v2::client()->send_to_device( + http::client()->send_to_device( "m.room.encrypted", body, [user_id](mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to send " diff --git a/src/RegisterPage.cc b/src/RegisterPage.cc index db52e101..4894d122 100644 --- a/src/RegisterPage.cc +++ b/src/RegisterPage.cc @@ -145,7 +145,7 @@ RegisterPage::RegisterPage(QWidget *parent) captchaDialog_->close(); emit registering(); - http::v2::client()->flow_response( + http::client()->flow_response( user, pass, session, @@ -162,9 +162,8 @@ RegisterPage::RegisterPage(QWidget *parent) return; } - http::v2::client()->set_user(res.user_id); - http::v2::client()->set_access_token( - res.access_token); + http::client()->set_user(res.user_id); + http::client()->set_access_token(res.access_token); emit registerOk(); }); @@ -208,15 +207,15 @@ RegisterPage::onRegisterButtonClicked() auto password = password_input_->text().toStdString(); auto server = server_input_->text().toStdString(); - http::v2::client()->set_server(server); - http::v2::client()->registration( + http::client()->set_server(server); + http::client()->registration( username, password, [this, username, password](const mtx::responses::Register &res, mtx::http::RequestErr err) { if (!err) { - http::v2::client()->set_user(res.user_id); - http::v2::client()->set_access_token(res.access_token); + http::client()->set_user(res.user_id); + http::client()->set_access_token(res.access_token); emit registerOk(); return; @@ -224,7 +223,7 @@ RegisterPage::onRegisterButtonClicked() // The server requires registration flows. if (err->status_code == boost::beast::http::status::unauthorized) { - http::v2::client()->flow_register( + http::client()->flow_register( username, password, [this, username, password]( diff --git a/src/RoomList.cc b/src/RoomList.cc index 5f094a1c..418a5d6f 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -93,7 +93,7 @@ RoomList::updateAvatar(const QString &room_id, const QString &url) if (savedImgData.isEmpty()) { mtx::http::ThumbOpts opts; opts.mxc_url = url.toStdString(); - http::v2::client()->get_thumbnail( + http::client()->get_thumbnail( opts, [room_id, opts, this](const std::string &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->warn( diff --git a/src/dialogs/ReCaptcha.cpp b/src/dialogs/ReCaptcha.cpp index 6b1143b5..ba54268c 100644 --- a/src/dialogs/ReCaptcha.cpp +++ b/src/dialogs/ReCaptcha.cpp @@ -55,8 +55,8 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent) connect(openCaptchaBtn_, &QPushButton::clicked, [session]() { const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/" "fallback/web?session=%3") - .arg(QString::fromStdString(http::v2::client()->server())) - .arg(http::v2::client()->port()) + .arg(QString::fromStdString(http::client()->server())) + .arg(http::client()->port()) .arg(session); QDesktopServices::openUrl(url); diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index 74d08478..3f40ae89 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -103,7 +103,7 @@ EditModal::EditModal(const QString &roomId, QWidget *parent) state::Name body; body.name = newName.toStdString(); - http::v2::client()->send_state_event<state::Name, EventType::RoomName>( + http::client()->send_state_event<state::Name, EventType::RoomName>( roomId_.toStdString(), body, [this, newName](const mtx::responses::EventId &, @@ -122,7 +122,7 @@ EditModal::EditModal(const QString &roomId, QWidget *parent) state::Topic body; body.topic = newTopic.toStdString(); - http::v2::client()->send_state_event<state::Topic, EventType::RoomTopic>( + http::client()->send_state_event<state::Topic, EventType::RoomTopic>( roomId_.toStdString(), body, [this](const mtx::responses::EventId &, mtx::http::RequestErr err) { @@ -412,7 +412,7 @@ void RoomSettings::enableEncryption() { const auto room_id = room_id_.toStdString(); - http::v2::client()->enable_encryption( + http::client()->enable_encryption( room_id, [room_id, this](const mtx::responses::EventId &, mtx::http::RequestErr err) { if (err) { int status_code = static_cast<int>(err->status_code); diff --git a/src/main.cc b/src/main.cc index 67c98339..b776e902 100644 --- a/src/main.cc +++ b/src/main.cc @@ -200,9 +200,9 @@ main(int argc, char *argv[]) QObject::connect(&app, &QApplication::aboutToQuit, &w, [&w]() { w.saveCurrentWindowSize(); - if (http::v2::client() != nullptr) { + if (http::client() != nullptr) { nhlog::net()->debug("shutting down all I/O threads & open connections"); - http::v2::client()->close(true); + http::client()->close(true); nhlog::net()->debug("bye"); } }); diff --git a/src/timeline/TimelineItem.cc b/src/timeline/TimelineItem.cc index 274c1d43..d756ca26 100644 --- a/src/timeline/TimelineItem.cc +++ b/src/timeline/TimelineItem.cc @@ -152,7 +152,7 @@ TimelineItem::init() }); connect(redactMsg_, &QAction::triggered, this, [this]() { if (!event_id_.isEmpty()) - http::v2::client()->redact_event( + http::client()->redact_event( room_id_.toStdString(), event_id_.toStdString(), [this](const mtx::responses::EventId &, mtx::http::RequestErr err) { @@ -721,14 +721,14 @@ void TimelineItem::sendReadReceipt() const { if (!event_id_.isEmpty()) - http::v2::client()->read_event(room_id_.toStdString(), - event_id_.toStdString(), - [this](mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn( - "failed to read_event ({}, {})", - room_id_.toStdString(), - event_id_.toStdString()); - } - }); + http::client()->read_event(room_id_.toStdString(), + event_id_.toStdString(), + [this](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn( + "failed to read_event ({}, {})", + room_id_.toStdString(), + event_id_.toStdString()); + } + }); } diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index 967436ff..0204bbd2 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -510,7 +510,7 @@ TimelineView::getMessages() opts.room_id = room_id_.toStdString(); opts.from = prev_batch_token_.toStdString(); - http::v2::client()->messages( + http::client()->messages( opts, [this, opts](const mtx::responses::Messages &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->error("failed to call /messages ({}): {} - {}", @@ -630,7 +630,7 @@ TimelineView::addUserMessage(mtx::events::MessageType ty, const QString &body) PendingMessage message; message.ty = ty; - message.txn_id = http::v2::client()->generate_txn_id(); + message.txn_id = http::client()->generate_txn_id(); message.body = body; message.widget = view_item; @@ -684,7 +684,7 @@ TimelineView::sendNextPendingMessage() switch (m.ty) { case mtx::events::MessageType::Audio: { - http::v2::client()->send_room_message<msg::Audio, EventType::RoomMessage>( + http::client()->send_room_message<msg::Audio, EventType::RoomMessage>( room_id_.toStdString(), m.txn_id, toRoomMessage<msg::Audio>(m), @@ -697,7 +697,7 @@ TimelineView::sendNextPendingMessage() break; } case mtx::events::MessageType::Image: { - http::v2::client()->send_room_message<msg::Image, EventType::RoomMessage>( + http::client()->send_room_message<msg::Image, EventType::RoomMessage>( room_id_.toStdString(), m.txn_id, toRoomMessage<msg::Image>(m), @@ -710,7 +710,7 @@ TimelineView::sendNextPendingMessage() break; } case mtx::events::MessageType::Video: { - http::v2::client()->send_room_message<msg::Video, EventType::RoomMessage>( + http::client()->send_room_message<msg::Video, EventType::RoomMessage>( room_id_.toStdString(), m.txn_id, toRoomMessage<msg::Video>(m), @@ -723,7 +723,7 @@ TimelineView::sendNextPendingMessage() break; } case mtx::events::MessageType::File: { - http::v2::client()->send_room_message<msg::File, EventType::RoomMessage>( + http::client()->send_room_message<msg::File, EventType::RoomMessage>( room_id_.toStdString(), m.txn_id, toRoomMessage<msg::File>(m), @@ -736,7 +736,7 @@ TimelineView::sendNextPendingMessage() break; } case mtx::events::MessageType::Text: { - http::v2::client()->send_room_message<msg::Text, EventType::RoomMessage>( + http::client()->send_room_message<msg::Text, EventType::RoomMessage>( room_id_.toStdString(), m.txn_id, toRoomMessage<msg::Text>(m), @@ -749,7 +749,7 @@ TimelineView::sendNextPendingMessage() break; } case mtx::events::MessageType::Emote: { - http::v2::client()->send_room_message<msg::Emote, EventType::RoomMessage>( + http::client()->send_room_message<msg::Emote, EventType::RoomMessage>( room_id_.toStdString(), m.txn_id, toRoomMessage<msg::Emote>(m), @@ -855,16 +855,16 @@ TimelineView::readLastEvent() const const auto eventId = getLastEventId(); if (!eventId.isEmpty()) - http::v2::client()->read_event(room_id_.toStdString(), - eventId.toStdString(), - [this, eventId](mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn( - "failed to read event ({}, {})", - room_id_.toStdString(), - eventId.toStdString()); - } - }); + http::client()->read_event(room_id_.toStdString(), + eventId.toStdString(), + [this, eventId](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn( + "failed to read event ({}, {})", + room_id_.toStdString(), + eventId.toStdString()); + } + }); } QString @@ -1186,18 +1186,17 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg) // Check if we have already an outbound megolm session then we can use. if (cache::client()->outboundMegolmSessionExists(room_id)) { auto data = olm::encrypt_group_message( - room_id, http::v2::client()->device_id(), doc.dump()); - - http::v2::client() - ->send_room_message<msg::Encrypted, EventType::RoomEncrypted>( - room_id, - msg.txn_id, - data, - std::bind(&TimelineView::sendRoomMessageHandler, - this, - msg.txn_id, - std::placeholders::_1, - std::placeholders::_2)); + room_id, http::client()->device_id(), doc.dump()); + + http::client()->send_room_message<msg::Encrypted, EventType::RoomEncrypted>( + room_id, + msg.txn_id, + data, + std::bind(&TimelineView::sendRoomMessageHandler, + this, + msg.txn_id, + std::placeholders::_1, + std::placeholders::_2)); return; } @@ -1230,9 +1229,9 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg) [megolm_payload, room_id, doc, txn_id = msg.txn_id, this]() { try { auto data = olm::encrypt_group_message( - room_id, http::v2::client()->device_id(), doc.dump()); + room_id, http::client()->device_id(), doc.dump()); - http::v2::client() + http::client() ->send_room_message<msg::Encrypted, EventType::RoomEncrypted>( room_id, txn_id, @@ -1253,7 +1252,7 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg) for (const auto &member : members) req.device_keys[member] = {}; - http::v2::client()->query_keys( + http::client()->query_keys( req, [keeper = std::move(keeper), megolm_payload, this]( const mtx::responses::QueryKeys &res, mtx::http::RequestErr err) { @@ -1340,7 +1339,7 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg) user.first, valid_devices.size()); - http::v2::client()->claim_keys( + http::client()->claim_keys( user.first, valid_devices, std::bind(&TimelineView::handleClaimedKeys, @@ -1440,7 +1439,7 @@ TimelineView::handleClaimedKeys(std::shared_ptr<StateKeeper> keeper, nhlog::net()->info("send_to_device: {}", user_id); - http::v2::client()->send_to_device( + http::client()->send_to_device( "m.room.encrypted", body, [keeper](mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to send " diff --git a/src/timeline/widgets/AudioItem.cc b/src/timeline/widgets/AudioItem.cc index 7cbbed28..2ed4f4c0 100644 --- a/src/timeline/widgets/AudioItem.cc +++ b/src/timeline/widgets/AudioItem.cc @@ -120,7 +120,7 @@ AudioItem::mousePressEvent(QMouseEvent *event) if (filenameToSave_.isEmpty()) return; - http::v2::client()->download( + http::client()->download( url_.toString().toStdString(), [this](const std::string &data, const std::string &, diff --git a/src/timeline/widgets/FileItem.cc b/src/timeline/widgets/FileItem.cc index 4ce4d256..7c2be9f2 100644 --- a/src/timeline/widgets/FileItem.cc +++ b/src/timeline/widgets/FileItem.cc @@ -83,8 +83,8 @@ FileItem::openUrl() auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString()); auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4") - .arg(QString::fromStdString(http::v2::client()->server())) - .arg(http::v2::client()->port()) + .arg(QString::fromStdString(http::client()->server())) + .arg(http::client()->port()) .arg(QString::fromStdString(mxc_parts.server)) .arg(QString::fromStdString(mxc_parts.media_id)); @@ -114,7 +114,7 @@ FileItem::mousePressEvent(QMouseEvent *event) if (filenameToSave_.isEmpty()) return; - http::v2::client()->download( + http::client()->download( url_.toString().toStdString(), [this](const std::string &data, const std::string &, diff --git a/src/timeline/widgets/ImageItem.cc b/src/timeline/widgets/ImageItem.cc index bf1c05d6..8c8f50a1 100644 --- a/src/timeline/widgets/ImageItem.cc +++ b/src/timeline/widgets/ImageItem.cc @@ -33,24 +33,24 @@ void ImageItem::downloadMedia(const QUrl &url) { - http::v2::client()->download(url.toString().toStdString(), - [this, url](const std::string &data, - const std::string &, - const std::string &, - mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn( - "failed to retrieve image {}: {} {}", - url.toString().toStdString(), - err->matrix_error.error, - static_cast<int>(err->status_code)); - return; - } - - QPixmap img; - img.loadFromData(QByteArray(data.data(), data.size())); - emit imageDownloaded(img); - }); + http::client()->download(url.toString().toStdString(), + [this, url](const std::string &data, + const std::string &, + const std::string &, + mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn( + "failed to retrieve image {}: {} {}", + url.toString().toStdString(), + err->matrix_error.error, + static_cast<int>(err->status_code)); + return; + } + + QPixmap img; + img.loadFromData(QByteArray(data.data(), data.size())); + emit imageDownloaded(img); + }); } void @@ -108,8 +108,8 @@ ImageItem::openUrl() auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString()); auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4") - .arg(QString::fromStdString(http::v2::client()->server())) - .arg(http::v2::client()->port()) + .arg(QString::fromStdString(http::client()->server())) + .arg(http::client()->port()) .arg(QString::fromStdString(mxc_parts.server)) .arg(QString::fromStdString(mxc_parts.media_id)); @@ -244,7 +244,7 @@ ImageItem::saveAs() const auto url = url_.toString().toStdString(); - http::v2::client()->download( + http::client()->download( url, [this, filename, url](const std::string &data, const std::string &, |