Remove the v2 namespace from the http client

This commit is contained in:
Konstantinos Sideris 2018-07-15 19:09:08 +03:00
parent e6b45263bc
commit 33490eddab
19 changed files with 171 additions and 179 deletions

View file

@ -18,13 +18,11 @@ Q_DECLARE_METATYPE(std::vector<std::string>)
Q_DECLARE_METATYPE(std::vector<QString>) Q_DECLARE_METATYPE(std::vector<QString>)
namespace http { namespace http {
namespace v2 {
mtx::http::Client * mtx::http::Client *
client(); client();
bool bool
is_logged_in(); is_logged_in();
}
//! Initialize the http module //! Initialize the http module
void void

View file

@ -343,7 +343,7 @@ TimelineView::addUserMessage(const QString &url,
PendingMessage message; PendingMessage message;
message.ty = MsgType; message.ty = MsgType;
message.txn_id = http::v2::client()->generate_txn_id(); message.txn_id = http::client()->generate_txn_id();
message.body = url; message.body = url;
message.filename = trimmed; message.filename = trimmed;
message.mime = mime; message.mime = mime;

View file

@ -52,7 +52,7 @@ resolve(const QString &room_id, const QString &user_id, QObject *receiver, Avata
mtx::http::ThumbOpts opts; mtx::http::ThumbOpts opts;
opts.mxc_url = avatarUrl.toStdString(); opts.mxc_url = avatarUrl.toStdString();
http::v2::client()->get_thumbnail( http::client()->get_thumbnail(
opts, opts,
[opts, proxy = std::move(proxy)](const std::string &res, mtx::http::RequestErr err) { [opts, proxy = std::move(proxy)](const std::string &res, mtx::http::RequestErr err) {
if (err) { if (err) {

View file

@ -133,7 +133,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(this, &ChatPage::connectionLost, this, [this]() { connect(this, &ChatPage::connectionLost, this, [this]() {
nhlog::net()->info("connectivity lost"); nhlog::net()->info("connectivity lost");
isConnected_ = false; isConnected_ = false;
http::v2::client()->shutdown(); http::client()->shutdown();
text_input_->disableInput(); text_input_->disableInput();
}); });
connect(this, &ChatPage::connectionRestored, this, [this]() { connect(this, &ChatPage::connectionRestored, this, [this]() {
@ -142,18 +142,18 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
isConnected_ = true; isConnected_ = true;
// Drop all pending connections. // Drop all pending connections.
http::v2::client()->shutdown(); http::client()->shutdown();
trySync(); trySync();
}); });
connectivityTimer_.setInterval(CHECK_CONNECTIVITY_INTERVAL); connectivityTimer_.setInterval(CHECK_CONNECTIVITY_INTERVAL);
connect(&connectivityTimer_, &QTimer::timeout, this, [=]() { connect(&connectivityTimer_, &QTimer::timeout, this, [=]() {
if (http::v2::client()->access_token().empty()) { if (http::client()->access_token().empty()) {
connectivityTimer_.stop(); connectivityTimer_.stop();
return; return;
} }
http::v2::client()->versions( http::client()->versions(
[this](const mtx::responses::Versions &, mtx::http::RequestErr err) { [this](const mtx::responses::Versions &, mtx::http::RequestErr err) {
if (err) { if (err) {
emit connectionLost(); emit connectionLost();
@ -167,7 +167,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(this, &ChatPage::loggedOut, this, &ChatPage::logout); connect(this, &ChatPage::loggedOut, this, &ChatPage::logout);
connect(user_info_widget_, &UserInfoWidget::logout, this, [this]() { connect(user_info_widget_, &UserInfoWidget::logout, this, [this]() {
http::v2::client()->logout( http::client()->logout(
[this](const mtx::responses::Logout &, mtx::http::RequestErr err) { [this](const mtx::responses::Logout &, mtx::http::RequestErr err) {
if (err) { if (err) {
// TODO: handle special errors // 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]() { QTimer::singleShot(ii * 500, this, [this, room_id, ii, users]() {
const auto user = users.at(ii); const auto user = users.at(ii);
http::v2::client()->invite_user( http::client()->invite_user(
room_id, room_id,
user.toStdString(), user.toStdString(),
[this, user](const mtx::responses::RoomInvite &, [this, user](const mtx::responses::RoomInvite &,
@ -254,7 +254,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
if (current_room_.isEmpty()) if (current_room_.isEmpty())
return; return;
http::v2::client()->stop_typing( http::client()->stop_typing(
current_room_.toStdString(), [](mtx::http::RequestErr err) { current_room_.toStdString(), [](mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn("failed to stop typing notifications: {}", 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 payload = std::string(bin.data(), bin.size());
auto dimensions = QImageReader(dev.data()).size(); auto dimensions = QImageReader(dev.data()).size();
http::v2::client()->upload( http::client()->upload(
payload, payload,
mime.name().toStdString(), mime.name().toStdString(),
QFileInfo(fn).fileName().toStdString(), QFileInfo(fn).fileName().toStdString(),
@ -348,7 +348,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
auto bin = dev->readAll(); auto bin = dev->readAll();
auto payload = std::string(bin.data(), bin.size()); auto payload = std::string(bin.data(), bin.size());
http::v2::client()->upload( http::client()->upload(
payload, payload,
mime.name().toStdString(), mime.name().toStdString(),
QFileInfo(fn).fileName().toStdString(), QFileInfo(fn).fileName().toStdString(),
@ -391,7 +391,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
auto bin = dev->readAll(); auto bin = dev->readAll();
auto payload = std::string(bin.data(), bin.size()); auto payload = std::string(bin.data(), bin.size());
http::v2::client()->upload( http::client()->upload(
payload, payload,
mime.name().toStdString(), mime.name().toStdString(),
QFileInfo(fn).fileName().toStdString(), QFileInfo(fn).fileName().toStdString(),
@ -433,7 +433,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
auto bin = dev->readAll(); auto bin = dev->readAll();
auto payload = std::string(bin.data(), bin.size()); auto payload = std::string(bin.data(), bin.size());
http::v2::client()->upload( http::client()->upload(
payload, payload,
mime.name().toStdString(), mime.name().toStdString(),
QFileInfo(fn).fileName().toStdString(), QFileInfo(fn).fileName().toStdString(),
@ -567,7 +567,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
} }
if (hasNotifications) if (hasNotifications)
http::v2::client()->notifications( http::client()->notifications(
5, 5,
[this](const mtx::responses::Notifications &res, [this](const mtx::responses::Notifications &res,
mtx::http::RequestErr err) { mtx::http::RequestErr err) {
@ -627,7 +627,7 @@ ChatPage::dropToLoginPage(const QString &msg)
deleteConfigs(); deleteConfigs();
resetUI(); resetUI();
http::v2::client()->shutdown(); http::client()->shutdown();
connectivityTimer_.stop(); connectivityTimer_.stop();
emit showLoginPage(msg); emit showLoginPage(msg);
@ -659,7 +659,7 @@ ChatPage::deleteConfigs()
settings.endGroup(); settings.endGroup();
cache::client()->deleteData(); cache::client()->deleteData();
http::v2::client()->clear(); http::client()->clear();
} }
void void
@ -668,19 +668,19 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
using namespace mtx::identifiers; using namespace mtx::identifiers;
try { try {
http::v2::client()->set_user(parse<User>(userid.toStdString())); http::client()->set_user(parse<User>(userid.toStdString()));
} catch (const std::invalid_argument &e) { } catch (const std::invalid_argument &e) {
nhlog::ui()->critical("bootstrapped with invalid user_id: {}", nhlog::ui()->critical("bootstrapped with invalid user_id: {}",
userid.toStdString()); userid.toStdString());
} }
http::v2::client()->set_server(homeserver.toStdString()); http::client()->set_server(homeserver.toStdString());
http::v2::client()->set_access_token(token.toStdString()); http::client()->set_access_token(token.toStdString());
// The Olm client needs the user_id & device_id that will be included // The Olm client needs the user_id & device_id that will be included
// in the generated payloads & keys. // in the generated payloads & keys.
olm::client()->set_user_id(http::v2::client()->user_id().to_string()); olm::client()->set_user_id(http::client()->user_id().to_string());
olm::client()->set_device_id(http::v2::client()->device_id()); olm::client()->set_device_id(http::client()->device_id());
try { try {
cache::init(userid); cache::init(userid);
@ -998,7 +998,7 @@ ChatPage::tryInitialSync()
nhlog::crypto()->info("generating one time keys"); nhlog::crypto()->info("generating one time keys");
olm::client()->generate_one_time_keys(MAX_ONETIME_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(), olm::client()->create_upload_keys_request(),
[this](const mtx::responses::UploadKeys &res, mtx::http::RequestErr err) { [this](const mtx::responses::UploadKeys &res, mtx::http::RequestErr err) {
if (err) { if (err) {
@ -1021,11 +1021,11 @@ ChatPage::tryInitialSync()
mtx::http::SyncOpts opts; mtx::http::SyncOpts opts;
opts.timeout = 0; opts.timeout = 0;
http::v2::client()->sync(opts, http::client()->sync(opts,
std::bind(&ChatPage::initialSyncHandler, std::bind(&ChatPage::initialSyncHandler,
this, this,
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2)); std::placeholders::_2));
}); });
} }
@ -1044,7 +1044,7 @@ ChatPage::trySync()
return; return;
} }
http::v2::client()->sync( http::client()->sync(
opts, [this](const mtx::responses::Sync &res, mtx::http::RequestErr err) { opts, [this](const mtx::responses::Sync &res, mtx::http::RequestErr err) {
if (err) { if (err) {
const auto error = QString::fromStdString(err->matrix_error.error); const auto error = QString::fromStdString(err->matrix_error.error);
@ -1055,7 +1055,7 @@ ChatPage::trySync()
nhlog::net()->error("sync error: {} {}", status_code, err_code); nhlog::net()->error("sync error: {} {}", status_code, err_code);
if (status_code <= 0 || status_code >= 600) { if (status_code <= 0 || status_code >= 600) {
if (!http::v2::is_logged_in()) if (!http::is_logged_in())
return; return;
emit tryDelayedSyncCb(); emit tryDelayedSyncCb();
@ -1070,7 +1070,7 @@ ChatPage::trySync()
return; return;
} }
default: { default: {
if (!http::v2::is_logged_in()) if (!http::is_logged_in())
return; return;
if (err->matrix_error.errcode == if (err->matrix_error.errcode ==
@ -1113,7 +1113,7 @@ ChatPage::joinRoom(const QString &room)
{ {
const auto room_id = room.toStdString(); 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) { room_id, [this, room_id](const nlohmann::json &, mtx::http::RequestErr err) {
if (err) { if (err) {
emit showNotification( emit showNotification(
@ -1137,7 +1137,7 @@ ChatPage::joinRoom(const QString &room)
void void
ChatPage::createRoom(const mtx::requests::CreateRoom &req) 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) { req, [this](const mtx::responses::CreateRoom &res, mtx::http::RequestErr err) {
if (err) { if (err) {
emit showNotification( emit showNotification(
@ -1154,7 +1154,7 @@ ChatPage::createRoom(const mtx::requests::CreateRoom &req)
void void
ChatPage::leaveRoom(const QString &room_id) 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) { room_id.toStdString(), [this, room_id](const json &, mtx::http::RequestErr err) {
if (err) { if (err) {
emit showNotification( emit showNotification(
@ -1173,7 +1173,7 @@ ChatPage::sendTypingNotifications()
if (!userSettings_->isTypingNotificationsEnabled()) if (!userSettings_->isTypingNotificationsEnabled())
return; return;
http::v2::client()->start_typing( http::client()->start_typing(
current_room_.toStdString(), 10'000, [](mtx::http::RequestErr err) { current_room_.toStdString(), 10'000, [](mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn("failed to send typing notification: {}", 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); nhlog::crypto()->info("uploading {} {} keys", nkeys, entry.first);
olm::client()->generate_one_time_keys(nkeys); olm::client()->generate_one_time_keys(nkeys);
http::v2::client()->upload_keys( http::client()->upload_keys(
olm::client()->create_upload_keys_request(), olm::client()->create_upload_keys_request(),
[](const mtx::responses::UploadKeys &, mtx::http::RequestErr err) { [](const mtx::responses::UploadKeys &, mtx::http::RequestErr err) {
if (err) { if (err) {
@ -1259,7 +1259,7 @@ ChatPage::getProfileInfo()
QSettings settings; QSettings settings;
const auto userid = settings.value("auth/user_id").toString().toStdString(); 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) { userid, [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn("failed to retrieve own profile info"); nhlog::net()->warn("failed to retrieve own profile info");
@ -1279,7 +1279,7 @@ ChatPage::getProfileInfo()
if (res.avatar_url.empty()) if (res.avatar_url.empty())
return; return;
http::v2::client()->download( http::client()->download(
res.avatar_url, res.avatar_url,
[this, res](const std::string &data, [this, res](const std::string &data,
const std::string &, 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) { [this](const mtx::responses::JoinedGroups &res, mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->critical("failed to retrieve joined groups: {} {}", nhlog::net()->critical("failed to retrieve joined groups: {} {}",

View file

@ -1,5 +1,5 @@
#include "CommunitiesList.h"
#include "Cache.h" #include "Cache.h"
#include "CommunitiesList.h"
#include "Logging.hpp" #include "Logging.hpp"
#include "MatrixClient.h" #include "MatrixClient.h"
@ -94,7 +94,7 @@ CommunitiesList::addCommunity(const std::string &group_id)
this, this,
&CommunitiesList::highlightSelectedCommunity); &CommunitiesList::highlightSelectedCommunity);
http::v2::client()->group_profile( http::client()->group_profile(
group_id, [id, this](const mtx::responses::GroupProfile &res, mtx::http::RequestErr err) { group_id, [id, this](const mtx::responses::GroupProfile &res, mtx::http::RequestErr err) {
if (err) { if (err) {
return; return;
@ -103,7 +103,7 @@ CommunitiesList::addCommunity(const std::string &group_id)
emit groupProfileRetrieved(id, res); 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) { group_id, [id, this](const nlohmann::json &res, mtx::http::RequestErr err) {
if (err) { if (err) {
return; return;
@ -164,7 +164,7 @@ CommunitiesList::fetchCommunityAvatar(const QString &id, const QString &avatarUr
mtx::http::ThumbOpts opts; mtx::http::ThumbOpts opts;
opts.mxc_url = avatarUrl.toStdString(); 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) { opts, [this, opts, id](const std::string &res, mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn("failed to download avatar: {} - ({} {})", nhlog::net()->warn("failed to download avatar: {} - ({} {})",

View file

@ -181,7 +181,7 @@ LoginPage::onMatrixIdEntered()
inferredServerAddress_ = homeServer; inferredServerAddress_ = homeServer;
serverInput_->setText(homeServer); serverInput_->setText(homeServer);
http::v2::client()->set_server(user.hostname()); http::client()->set_server(user.hostname());
checkHomeserverVersion(); checkHomeserverVersion();
} }
} }
@ -189,7 +189,7 @@ LoginPage::onMatrixIdEntered()
void void
LoginPage::checkHomeserverVersion() LoginPage::checkHomeserverVersion()
{ {
http::v2::client()->versions( http::client()->versions(
[this](const mtx::responses::Versions &, mtx::http::RequestErr err) { [this](const mtx::responses::Versions &, mtx::http::RequestErr err) {
if (err) { if (err) {
using namespace boost::beast::http; using namespace boost::beast::http;
@ -219,7 +219,7 @@ void
LoginPage::onServerAddressEntered() LoginPage::onServerAddressEntered()
{ {
error_label_->setText(""); error_label_->setText("");
http::v2::client()->set_server(serverInput_->text().toStdString()); http::client()->set_server(serverInput_->text().toStdString());
checkHomeserverVersion(); checkHomeserverVersion();
serverLayout_->removeWidget(errorIcon_); serverLayout_->removeWidget(errorIcon_);
@ -268,20 +268,20 @@ LoginPage::onLoginButtonClicked()
if (password_input_->text().isEmpty()) if (password_input_->text().isEmpty())
return loginError(tr("Empty password")); return loginError(tr("Empty password"));
http::v2::client()->set_server(serverInput_->text().toStdString()); http::client()->set_server(serverInput_->text().toStdString());
http::v2::client()->login( http::client()->login(user.localpart(),
user.localpart(), password_input_->text().toStdString(),
password_input_->text().toStdString(), initialDeviceName(),
initialDeviceName(), [this](const mtx::responses::Login &res, mtx::http::RequestErr err) {
[this](const mtx::responses::Login &res, mtx::http::RequestErr err) { if (err) {
if (err) { emit loginError(
emit loginError(QString::fromStdString(err->matrix_error.error)); QString::fromStdString(err->matrix_error.error));
emit errorOccurred(); emit errorOccurred();
return; return;
} }
emit loginOk(res); emit loginOk(res);
}); });
emit loggingIn(); emit loggingIn();
} }

View file

@ -122,7 +122,7 @@ MainWindow::MainWindow(QWidget *parent)
chat_page_, &ChatPage::showUserSettingsPage, this, &MainWindow::showUserSettingsPage); chat_page_, &ChatPage::showUserSettingsPage, this, &MainWindow::showUserSettingsPage);
connect(login_page_, &LoginPage::loginOk, this, [this](const mtx::responses::Login &res) { 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(); showChatPage();
}); });
@ -147,13 +147,13 @@ MainWindow::MainWindow(QWidget *parent)
QString user_id = settings.value("auth/user_id").toString(); QString user_id = settings.value("auth/user_id").toString();
QString device_id = settings.value("auth/device_id").toString(); QString device_id = settings.value("auth/device_id").toString();
http::v2::client()->set_access_token(token.toStdString()); http::client()->set_access_token(token.toStdString());
http::v2::client()->set_server(home_server.toStdString()); http::client()->set_server(home_server.toStdString());
http::v2::client()->set_device_id(device_id.toStdString()); http::client()->set_device_id(device_id.toStdString());
try { try {
using namespace mtx::identifiers; 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) { } catch (const std::invalid_argument &e) {
nhlog::ui()->critical("bootstrapped with invalid user_id: {}", nhlog::ui()->critical("bootstrapped with invalid user_id: {}",
user_id.toStdString()); user_id.toStdString());
@ -248,11 +248,11 @@ MainWindow::removeOverlayProgressBar()
void void
MainWindow::showChatPage() MainWindow::showChatPage()
{ {
auto userid = QString::fromStdString(http::v2::client()->user_id().to_string()); auto userid = QString::fromStdString(http::client()->user_id().to_string());
auto device_id = QString::fromStdString(http::v2::client()->device_id()); auto device_id = QString::fromStdString(http::client()->device_id());
auto homeserver = QString::fromStdString(http::v2::client()->server() + ":" + auto homeserver = QString::fromStdString(http::client()->server() + ":" +
std::to_string(http::v2::client()->port())); std::to_string(http::client()->port()));
auto token = QString::fromStdString(http::v2::client()->access_token()); auto token = QString::fromStdString(http::client()->access_token());
QSettings settings; QSettings settings;
settings.setValue("auth/access_token", token); settings.setValue("auth/access_token", token);

View file

@ -3,26 +3,23 @@
#include <memory> #include <memory>
namespace { namespace {
auto v2_client_ = std::make_shared<mtx::http::Client>(); auto client_ = std::make_shared<mtx::http::Client>();
} }
namespace http { namespace http {
namespace v2 {
mtx::http::Client * mtx::http::Client *
client() client()
{ {
return v2_client_.get(); return client_.get();
} }
bool bool
is_logged_in() is_logged_in()
{ {
return !v2_client_->access_token().empty(); return !client_->access_token().empty();
} }
} // namespace v2
void void
init() init()
{ {

View file

@ -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); nhlog::crypto()->info("requesting keys for event {} at {}", event_id, room_id);
http::v2::client()->get_event( http::client()->get_event(
room_id, room_id,
event_id, event_id,
[event_id, room_id](const mtx::events::collections::TimelineEvents &res, [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)); nhlog::crypto()->debug("sending key request: {}", json(e).dump(2));
auto payload = json{{"action", "request"}, auto payload = json{{"action", "request"},
{"request_id", http::v2::client()->generate_txn_id()}, {"request_id", http::client()->generate_txn_id()},
{"requesting_device_id", http::v2::client()->device_id()}, {"requesting_device_id", http::client()->device_id()},
{"body", {"body",
{{"algorithm", MEGOLM_ALGO}, {{"algorithm", MEGOLM_ALGO},
{"room_id", room_id}, {"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)); nhlog::crypto()->debug("m.room_key_request: {}", body.dump(2));
http::v2::client()->send_to_device( http::client()->send_to_device("m.room_key_request", body, [e](mtx::http::RequestErr err) {
"m.room_key_request", body, [e](mtx::http::RequestErr err) { if (err) {
if (err) { nhlog::net()->warn("failed to send "
nhlog::net()->warn("failed to send " "send_to_device "
"send_to_device " "message: {}",
"message: {}", err->matrix_error.error);
err->matrix_error.error); }
}
nhlog::net()->info( nhlog::net()->info(
"m.room_key_request sent to {}:{}", e.sender, e.content.device_id); "m.room_key_request sent to {}:{}", e.sender, e.content.device_id);
}); });
} }
void void
@ -389,7 +388,7 @@ send_megolm_key_to_device(const std::string &user_id,
mtx::requests::QueryKeys req; mtx::requests::QueryKeys req;
req.device_keys[user_id] = {device_id}; req.device_keys[user_id] = {device_id};
http::v2::client()->query_keys( http::client()->query_keys(
req, req,
[payload, user_id, device_id](const mtx::responses::QueryKeys &res, [payload, user_id, device_id](const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err) { 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) ->create_room_key_event(UserId(user_id), pks.ed25519, payload)
.dump(); .dump();
http::v2::client()->claim_keys( http::client()->claim_keys(
user_id, user_id,
{device_id}, {device_id},
[room_key, user_id, device_id, pks](const mtx::responses::ClaimKeys &res, [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( nhlog::net()->info(
"sending m.room_key event to {}:{}", user_id, device_id); "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) { "m.room.encrypted", body, [user_id](mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn("failed to send " nhlog::net()->warn("failed to send "

View file

@ -145,7 +145,7 @@ RegisterPage::RegisterPage(QWidget *parent)
captchaDialog_->close(); captchaDialog_->close();
emit registering(); emit registering();
http::v2::client()->flow_response( http::client()->flow_response(
user, user,
pass, pass,
session, session,
@ -162,9 +162,8 @@ RegisterPage::RegisterPage(QWidget *parent)
return; return;
} }
http::v2::client()->set_user(res.user_id); http::client()->set_user(res.user_id);
http::v2::client()->set_access_token( http::client()->set_access_token(res.access_token);
res.access_token);
emit registerOk(); emit registerOk();
}); });
@ -208,15 +207,15 @@ RegisterPage::onRegisterButtonClicked()
auto password = password_input_->text().toStdString(); auto password = password_input_->text().toStdString();
auto server = server_input_->text().toStdString(); auto server = server_input_->text().toStdString();
http::v2::client()->set_server(server); http::client()->set_server(server);
http::v2::client()->registration( http::client()->registration(
username, username,
password, password,
[this, username, password](const mtx::responses::Register &res, [this, username, password](const mtx::responses::Register &res,
mtx::http::RequestErr err) { mtx::http::RequestErr err) {
if (!err) { if (!err) {
http::v2::client()->set_user(res.user_id); http::client()->set_user(res.user_id);
http::v2::client()->set_access_token(res.access_token); http::client()->set_access_token(res.access_token);
emit registerOk(); emit registerOk();
return; return;
@ -224,7 +223,7 @@ RegisterPage::onRegisterButtonClicked()
// The server requires registration flows. // The server requires registration flows.
if (err->status_code == boost::beast::http::status::unauthorized) { if (err->status_code == boost::beast::http::status::unauthorized) {
http::v2::client()->flow_register( http::client()->flow_register(
username, username,
password, password,
[this, username, password]( [this, username, password](

View file

@ -93,7 +93,7 @@ RoomList::updateAvatar(const QString &room_id, const QString &url)
if (savedImgData.isEmpty()) { if (savedImgData.isEmpty()) {
mtx::http::ThumbOpts opts; mtx::http::ThumbOpts opts;
opts.mxc_url = url.toStdString(); 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) { opts, [room_id, opts, this](const std::string &res, mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn( nhlog::net()->warn(

View file

@ -55,8 +55,8 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
connect(openCaptchaBtn_, &QPushButton::clicked, [session]() { connect(openCaptchaBtn_, &QPushButton::clicked, [session]() {
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/" const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/"
"fallback/web?session=%3") "fallback/web?session=%3")
.arg(QString::fromStdString(http::v2::client()->server())) .arg(QString::fromStdString(http::client()->server()))
.arg(http::v2::client()->port()) .arg(http::client()->port())
.arg(session); .arg(session);
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);

View file

@ -103,7 +103,7 @@ EditModal::EditModal(const QString &roomId, QWidget *parent)
state::Name body; state::Name body;
body.name = newName.toStdString(); 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(), roomId_.toStdString(),
body, body,
[this, newName](const mtx::responses::EventId &, [this, newName](const mtx::responses::EventId &,
@ -122,7 +122,7 @@ EditModal::EditModal(const QString &roomId, QWidget *parent)
state::Topic body; state::Topic body;
body.topic = newTopic.toStdString(); 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(), roomId_.toStdString(),
body, body,
[this](const mtx::responses::EventId &, mtx::http::RequestErr err) { [this](const mtx::responses::EventId &, mtx::http::RequestErr err) {
@ -412,7 +412,7 @@ void
RoomSettings::enableEncryption() RoomSettings::enableEncryption()
{ {
const auto room_id = room_id_.toStdString(); 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) { room_id, [room_id, this](const mtx::responses::EventId &, mtx::http::RequestErr err) {
if (err) { if (err) {
int status_code = static_cast<int>(err->status_code); int status_code = static_cast<int>(err->status_code);

View file

@ -200,9 +200,9 @@ main(int argc, char *argv[])
QObject::connect(&app, &QApplication::aboutToQuit, &w, [&w]() { QObject::connect(&app, &QApplication::aboutToQuit, &w, [&w]() {
w.saveCurrentWindowSize(); w.saveCurrentWindowSize();
if (http::v2::client() != nullptr) { if (http::client() != nullptr) {
nhlog::net()->debug("shutting down all I/O threads & open connections"); nhlog::net()->debug("shutting down all I/O threads & open connections");
http::v2::client()->close(true); http::client()->close(true);
nhlog::net()->debug("bye"); nhlog::net()->debug("bye");
} }
}); });

View file

@ -152,7 +152,7 @@ TimelineItem::init()
}); });
connect(redactMsg_, &QAction::triggered, this, [this]() { connect(redactMsg_, &QAction::triggered, this, [this]() {
if (!event_id_.isEmpty()) if (!event_id_.isEmpty())
http::v2::client()->redact_event( http::client()->redact_event(
room_id_.toStdString(), room_id_.toStdString(),
event_id_.toStdString(), event_id_.toStdString(),
[this](const mtx::responses::EventId &, mtx::http::RequestErr err) { [this](const mtx::responses::EventId &, mtx::http::RequestErr err) {
@ -721,14 +721,14 @@ void
TimelineItem::sendReadReceipt() const TimelineItem::sendReadReceipt() const
{ {
if (!event_id_.isEmpty()) if (!event_id_.isEmpty())
http::v2::client()->read_event(room_id_.toStdString(), http::client()->read_event(room_id_.toStdString(),
event_id_.toStdString(), event_id_.toStdString(),
[this](mtx::http::RequestErr err) { [this](mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn( nhlog::net()->warn(
"failed to read_event ({}, {})", "failed to read_event ({}, {})",
room_id_.toStdString(), room_id_.toStdString(),
event_id_.toStdString()); event_id_.toStdString());
} }
}); });
} }

View file

@ -510,7 +510,7 @@ TimelineView::getMessages()
opts.room_id = room_id_.toStdString(); opts.room_id = room_id_.toStdString();
opts.from = prev_batch_token_.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) { opts, [this, opts](const mtx::responses::Messages &res, mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->error("failed to call /messages ({}): {} - {}", nhlog::net()->error("failed to call /messages ({}): {} - {}",
@ -630,7 +630,7 @@ TimelineView::addUserMessage(mtx::events::MessageType ty, const QString &body)
PendingMessage message; PendingMessage message;
message.ty = ty; message.ty = ty;
message.txn_id = http::v2::client()->generate_txn_id(); message.txn_id = http::client()->generate_txn_id();
message.body = body; message.body = body;
message.widget = view_item; message.widget = view_item;
@ -684,7 +684,7 @@ TimelineView::sendNextPendingMessage()
switch (m.ty) { switch (m.ty) {
case mtx::events::MessageType::Audio: { 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(), room_id_.toStdString(),
m.txn_id, m.txn_id,
toRoomMessage<msg::Audio>(m), toRoomMessage<msg::Audio>(m),
@ -697,7 +697,7 @@ TimelineView::sendNextPendingMessage()
break; break;
} }
case mtx::events::MessageType::Image: { 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(), room_id_.toStdString(),
m.txn_id, m.txn_id,
toRoomMessage<msg::Image>(m), toRoomMessage<msg::Image>(m),
@ -710,7 +710,7 @@ TimelineView::sendNextPendingMessage()
break; break;
} }
case mtx::events::MessageType::Video: { 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(), room_id_.toStdString(),
m.txn_id, m.txn_id,
toRoomMessage<msg::Video>(m), toRoomMessage<msg::Video>(m),
@ -723,7 +723,7 @@ TimelineView::sendNextPendingMessage()
break; break;
} }
case mtx::events::MessageType::File: { 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(), room_id_.toStdString(),
m.txn_id, m.txn_id,
toRoomMessage<msg::File>(m), toRoomMessage<msg::File>(m),
@ -736,7 +736,7 @@ TimelineView::sendNextPendingMessage()
break; break;
} }
case mtx::events::MessageType::Text: { 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(), room_id_.toStdString(),
m.txn_id, m.txn_id,
toRoomMessage<msg::Text>(m), toRoomMessage<msg::Text>(m),
@ -749,7 +749,7 @@ TimelineView::sendNextPendingMessage()
break; break;
} }
case mtx::events::MessageType::Emote: { 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(), room_id_.toStdString(),
m.txn_id, m.txn_id,
toRoomMessage<msg::Emote>(m), toRoomMessage<msg::Emote>(m),
@ -855,16 +855,16 @@ TimelineView::readLastEvent() const
const auto eventId = getLastEventId(); const auto eventId = getLastEventId();
if (!eventId.isEmpty()) if (!eventId.isEmpty())
http::v2::client()->read_event(room_id_.toStdString(), http::client()->read_event(room_id_.toStdString(),
eventId.toStdString(), eventId.toStdString(),
[this, eventId](mtx::http::RequestErr err) { [this, eventId](mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn( nhlog::net()->warn(
"failed to read event ({}, {})", "failed to read event ({}, {})",
room_id_.toStdString(), room_id_.toStdString(),
eventId.toStdString()); eventId.toStdString());
} }
}); });
} }
QString QString
@ -1186,18 +1186,17 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg)
// Check if we have already an outbound megolm session then we can use. // Check if we have already an outbound megolm session then we can use.
if (cache::client()->outboundMegolmSessionExists(room_id)) { if (cache::client()->outboundMegolmSessionExists(room_id)) {
auto data = olm::encrypt_group_message( 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>(
->send_room_message<msg::Encrypted, EventType::RoomEncrypted>( room_id,
room_id, msg.txn_id,
msg.txn_id, data,
data, std::bind(&TimelineView::sendRoomMessageHandler,
std::bind(&TimelineView::sendRoomMessageHandler, this,
this, msg.txn_id,
msg.txn_id, std::placeholders::_1,
std::placeholders::_1, std::placeholders::_2));
std::placeholders::_2));
return; return;
} }
@ -1230,9 +1229,9 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg)
[megolm_payload, room_id, doc, txn_id = msg.txn_id, this]() { [megolm_payload, room_id, doc, txn_id = msg.txn_id, this]() {
try { try {
auto data = olm::encrypt_group_message( 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>( ->send_room_message<msg::Encrypted, EventType::RoomEncrypted>(
room_id, room_id,
txn_id, txn_id,
@ -1253,7 +1252,7 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg)
for (const auto &member : members) for (const auto &member : members)
req.device_keys[member] = {}; req.device_keys[member] = {};
http::v2::client()->query_keys( http::client()->query_keys(
req, req,
[keeper = std::move(keeper), megolm_payload, this]( [keeper = std::move(keeper), megolm_payload, this](
const mtx::responses::QueryKeys &res, mtx::http::RequestErr err) { const mtx::responses::QueryKeys &res, mtx::http::RequestErr err) {
@ -1340,7 +1339,7 @@ TimelineView::prepareEncryptedMessage(const PendingMessage &msg)
user.first, user.first,
valid_devices.size()); valid_devices.size());
http::v2::client()->claim_keys( http::client()->claim_keys(
user.first, user.first,
valid_devices, valid_devices,
std::bind(&TimelineView::handleClaimedKeys, std::bind(&TimelineView::handleClaimedKeys,
@ -1440,7 +1439,7 @@ TimelineView::handleClaimedKeys(std::shared_ptr<StateKeeper> keeper,
nhlog::net()->info("send_to_device: {}", user_id); 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) { "m.room.encrypted", body, [keeper](mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn("failed to send " nhlog::net()->warn("failed to send "

View file

@ -120,7 +120,7 @@ AudioItem::mousePressEvent(QMouseEvent *event)
if (filenameToSave_.isEmpty()) if (filenameToSave_.isEmpty())
return; return;
http::v2::client()->download( http::client()->download(
url_.toString().toStdString(), url_.toString().toStdString(),
[this](const std::string &data, [this](const std::string &data,
const std::string &, const std::string &,

View file

@ -83,8 +83,8 @@ FileItem::openUrl()
auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString()); auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString());
auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4") auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4")
.arg(QString::fromStdString(http::v2::client()->server())) .arg(QString::fromStdString(http::client()->server()))
.arg(http::v2::client()->port()) .arg(http::client()->port())
.arg(QString::fromStdString(mxc_parts.server)) .arg(QString::fromStdString(mxc_parts.server))
.arg(QString::fromStdString(mxc_parts.media_id)); .arg(QString::fromStdString(mxc_parts.media_id));
@ -114,7 +114,7 @@ FileItem::mousePressEvent(QMouseEvent *event)
if (filenameToSave_.isEmpty()) if (filenameToSave_.isEmpty())
return; return;
http::v2::client()->download( http::client()->download(
url_.toString().toStdString(), url_.toString().toStdString(),
[this](const std::string &data, [this](const std::string &data,
const std::string &, const std::string &,

View file

@ -33,24 +33,24 @@
void void
ImageItem::downloadMedia(const QUrl &url) ImageItem::downloadMedia(const QUrl &url)
{ {
http::v2::client()->download(url.toString().toStdString(), http::client()->download(url.toString().toStdString(),
[this, url](const std::string &data, [this, url](const std::string &data,
const std::string &, const std::string &,
const std::string &, const std::string &,
mtx::http::RequestErr err) { mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->warn( nhlog::net()->warn(
"failed to retrieve image {}: {} {}", "failed to retrieve image {}: {} {}",
url.toString().toStdString(), url.toString().toStdString(),
err->matrix_error.error, err->matrix_error.error,
static_cast<int>(err->status_code)); static_cast<int>(err->status_code));
return; return;
} }
QPixmap img; QPixmap img;
img.loadFromData(QByteArray(data.data(), data.size())); img.loadFromData(QByteArray(data.data(), data.size()));
emit imageDownloaded(img); emit imageDownloaded(img);
}); });
} }
void void
@ -108,8 +108,8 @@ ImageItem::openUrl()
auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString()); auto mxc_parts = mtx::client::utils::parse_mxc_url(url_.toString().toStdString());
auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4") auto urlToOpen = QString("https://%1:%2/_matrix/media/r0/download/%3/%4")
.arg(QString::fromStdString(http::v2::client()->server())) .arg(QString::fromStdString(http::client()->server()))
.arg(http::v2::client()->port()) .arg(http::client()->port())
.arg(QString::fromStdString(mxc_parts.server)) .arg(QString::fromStdString(mxc_parts.server))
.arg(QString::fromStdString(mxc_parts.media_id)); .arg(QString::fromStdString(mxc_parts.media_id));
@ -244,7 +244,7 @@ ImageItem::saveAs()
const auto url = url_.toString().toStdString(); const auto url = url_.toString().toStdString();
http::v2::client()->download( http::client()->download(
url, url,
[this, filename, url](const std::string &data, [this, filename, url](const std::string &data,
const std::string &, const std::string &,