mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Remove the v2 namespace from the http client
This commit is contained in:
parent
e6b45263bc
commit
33490eddab
19 changed files with 171 additions and 179 deletions
|
@ -18,13 +18,11 @@ Q_DECLARE_METATYPE(std::vector<std::string>)
|
|||
Q_DECLARE_METATYPE(std::vector<QString>)
|
||||
|
||||
namespace http {
|
||||
namespace v2 {
|
||||
mtx::http::Client *
|
||||
client();
|
||||
|
||||
bool
|
||||
is_logged_in();
|
||||
}
|
||||
|
||||
//! Initialize the http module
|
||||
void
|
||||
|
|
|
@ -343,7 +343,7 @@ TimelineView::addUserMessage(const QString &url,
|
|||
|
||||
PendingMessage message;
|
||||
message.ty = MsgType;
|
||||
message.txn_id = http::v2::client()->generate_txn_id();
|
||||
message.txn_id = http::client()->generate_txn_id();
|
||||
message.body = url;
|
||||
message.filename = trimmed;
|
||||
message.mime = mime;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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: {} {}",
|
||||
|
|
|
@ -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: {} - ({} {})",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
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 loginOk(res);
|
||||
});
|
||||
|
||||
emit loggingIn();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
33
src/Olm.cpp
33
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 "
|
||||
|
|
|
@ -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](
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
room_id, http::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));
|
||||
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 "
|
||||
|
|
|
@ -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 &,
|
||||
|
|
|
@ -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 &,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
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);
|
||||
});
|
||||
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 &,
|
||||
|
|
Loading…
Reference in a new issue