Skip to content
Snippets Groups Projects
Commit 192ccd81 authored by Konstantinos Sideris's avatar Konstantinos Sideris
Browse files

Add field to store the next batch token

parent 05fe996d
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,17 @@ using namespace mtx::events;
using ErrType = experimental::optional<mtx::client::errors::ClientError>;
using TimelineEvent = mtx::events::collections::TimelineEvents;
void
print_errors(ErrType err)
{
if (err->status_code != boost::beast::http::status::unknown)
cout << err->status_code << "\n";
if (!err->matrix_error.error.empty())
cout << err->matrix_error.error << "\n";
if (err->error_code)
cout << err->error_code.message() << "\n";
}
// Check if the given event has a textual representation.
bool
is_room_message(const TimelineEvent &event)
......@@ -75,9 +86,15 @@ sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res, ErrType
{
if (err) {
cout << "sync error:\n";
cout << err->status_code << "\n";
cout << err->matrix_error.error << "\n";
cout << err->error_code << "\n";
print_errors(err);
client->sync(
"",
client->next_batch_token(),
false,
30000,
std::bind(&sync_handler, client, std::placeholders::_1, std::placeholders::_2));
return;
}
......@@ -86,9 +103,11 @@ sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res, ErrType
print_message(msg);
}
client->set_next_batch_token(res.next_batch);
client->sync(
"",
res.next_batch,
client->next_batch_token(),
false,
30000,
std::bind(&sync_handler, client, std::placeholders::_1, std::placeholders::_2));
......@@ -100,14 +119,9 @@ initial_sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res,
{
if (err) {
cout << "error during initial sync:\n";
if (err->status_code != boost::beast::http::status::unknown)
cout << err->status_code << "\n";
if (!err->matrix_error.error.empty())
cout << err->matrix_error.error << "\n";
if (err->error_code)
cout << err->error_code.message() << "\n";
if (err->status_code == boost::beast::http::status::gateway_timeout) {
print_errors(err);
if (err->status_code != boost::beast::http::status::ok) {
cout << "retrying initial sync ...\n";
client->sync("",
"",
......@@ -122,9 +136,11 @@ initial_sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res,
return;
}
client->set_next_batch_token(res.next_batch);
client->sync(
"",
res.next_batch,
client->next_batch_token(),
false,
30000,
std::bind(&sync_handler, client, std::placeholders::_1, std::placeholders::_2));
......
......@@ -36,6 +36,10 @@ public:
int active_sessions() const { return active_sessions_.size(); }
//! Add an access token.
void set_access_token(const std::string &token) { access_token_ = token; }
//! Update the next batch token.
void set_next_batch_token(const std::string &token) { next_batch_token_ = token; }
//! Retrieve the current next batch token.
std::string next_batch_token() const { return next_batch_token_; }
using RequestErr = std::experimental::optional<mtx::client::errors::ClientError>;
......@@ -130,6 +134,8 @@ private:
std::string server_;
//! The access token that would be used for authentication.
std::string access_token_;
//! The token that will be used as the 'since' parameter on the next sync request.
std::string next_batch_token_;
};
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment