Only call /sync when retrying initial sync (#422)

This commit is contained in:
Konstantinos Sideris 2018-08-30 13:39:09 +03:00
parent 183975be1a
commit ee2ba93ec4
3 changed files with 24 additions and 18 deletions

View file

@ -626,6 +626,8 @@ ChatPage::logout()
void void
ChatPage::dropToLoginPage(const QString &msg) ChatPage::dropToLoginPage(const QString &msg)
{ {
nhlog::ui()->info("dropping to the login page: {}", msg.toStdString());
deleteConfigs(); deleteConfigs();
resetUI(); resetUI();
@ -987,18 +989,23 @@ ChatPage::tryInitialSync()
nhlog::net()->info( nhlog::net()->info(
"uploaded {} {} one-time keys", entry.second, entry.first); "uploaded {} {} one-time keys", entry.second, entry.first);
nhlog::net()->info("trying initial sync"); startInitialSync();
mtx::http::SyncOpts opts;
opts.timeout = 0;
http::client()->sync(opts,
std::bind(&ChatPage::initialSyncHandler,
this,
std::placeholders::_1,
std::placeholders::_2));
}); });
} }
void
ChatPage::startInitialSync()
{
nhlog::net()->info("trying initial sync");
mtx::http::SyncOpts opts;
opts.timeout = 0;
http::client()->sync(
opts,
std::bind(
&ChatPage::initialSyncHandler, this, std::placeholders::_1, std::placeholders::_2));
}
void void
ChatPage::trySync() ChatPage::trySync()
{ {
@ -1022,8 +1029,6 @@ ChatPage::trySync()
const auto err_code = mtx::errors::to_string(err->matrix_error.errcode); const auto err_code = mtx::errors::to_string(err->matrix_error.errcode);
const int status_code = static_cast<int>(err->status_code); const int status_code = static_cast<int>(err->status_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::is_logged_in()) if (!http::is_logged_in())
return; return;
@ -1032,6 +1037,8 @@ ChatPage::trySync()
return; return;
} }
nhlog::net()->error("sync error: {} {}", status_code, err_code);
switch (status_code) { switch (status_code) {
case 502: case 502:
case 504: case 504:
@ -1166,13 +1173,13 @@ ChatPage::initialSyncHandler(const mtx::responses::Sync &res, mtx::http::Request
const auto err_code = mtx::errors::to_string(err->matrix_error.errcode); const auto err_code = mtx::errors::to_string(err->matrix_error.errcode);
const int status_code = static_cast<int>(err->status_code); const int status_code = static_cast<int>(err->status_code);
nhlog::net()->error("sync error: {} {}", status_code, err_code); nhlog::net()->error("initial sync error: {} {}", status_code, err_code);
switch (status_code) { switch (status_code) {
case 502: case 502:
case 504: case 504:
case 524: { case 524: {
emit tryInitialSyncCb(); startInitialSync();
return; return;
} }
default: { default: {
@ -1192,8 +1199,8 @@ ChatPage::initialSyncHandler(const mtx::responses::Sync &res, mtx::http::Request
emit initializeViews(std::move(res.rooms)); emit initializeViews(std::move(res.rooms));
emit initializeRoomList(cache::client()->roomInfo()); emit initializeRoomList(cache::client()->roomInfo());
} catch (const lmdb::error &e) { } catch (const lmdb::error &e) {
nhlog::db()->error("{}", e.what()); nhlog::db()->error("failed to save state after initial sync: {}", e.what());
emit tryInitialSyncCb(); startInitialSync();
return; return;
} }

View file

@ -163,6 +163,7 @@ private:
//! Handler callback for initial sync. It doesn't run on the main thread so all //! Handler callback for initial sync. It doesn't run on the main thread so all
//! communication with the GUI should be done through signals. //! communication with the GUI should be done through signals.
void initialSyncHandler(const mtx::responses::Sync &res, mtx::http::RequestErr err); void initialSyncHandler(const mtx::responses::Sync &res, mtx::http::RequestErr err);
void startInitialSync();
void tryInitialSync(); void tryInitialSync();
void trySync(); void trySync();
void ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts); void ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts);

View file

@ -124,8 +124,6 @@ utils::getMessageDescription(const TimelineEvent &event,
info.datetime = ts; info.datetime = ts;
return info; return info;
} else {
std::cout << "type not found: " << serialize_event(event).dump(2) << '\n';
} }
return DescInfo{}; return DescInfo{};
@ -277,4 +275,4 @@ utils::humanReadableFingerprint(const QString &ed25519)
fingerprintList << ed25519.mid(i, 4); fingerprintList << ed25519.mid(i, 4);
} }
return fingerprintList.join(" "); return fingerprintList.join(" ");
} }