Handle invalid access token
This commit is contained in:
parent
23accc50d6
commit
7f69c71814
@ -81,6 +81,7 @@ public:
|
|||||||
|
|
||||||
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
QSharedPointer<UserSettings> userSettings() { return userSettings_; }
|
||||||
QSharedPointer<Cache> cache() { return cache_; }
|
QSharedPointer<Cache> cache() { return cache_; }
|
||||||
|
void deleteConfigs();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void contentLoaded();
|
void contentLoaded();
|
||||||
@ -126,7 +127,6 @@ private:
|
|||||||
void updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids);
|
void updateTypingUsers(const QString &roomid, const std::vector<std::string> &user_ids);
|
||||||
|
|
||||||
void loadStateFromCache();
|
void loadStateFromCache();
|
||||||
void deleteConfigs();
|
|
||||||
void resetUI();
|
void resetUI();
|
||||||
//! Decides whether or not to hide the group's sidebar.
|
//! Decides whether or not to hide the group's sidebar.
|
||||||
void setGroupViewState(bool isEnabled);
|
void setGroupViewState(bool isEnabled);
|
||||||
|
@ -175,6 +175,8 @@ signals:
|
|||||||
|
|
||||||
void redactionFailed(const QString &error);
|
void redactionFailed(const QString &error);
|
||||||
void redactionCompleted(const QString &room_id, const QString &event_id);
|
void redactionCompleted(const QString &room_id, const QString &event_id);
|
||||||
|
void invalidToken();
|
||||||
|
void syncError(const QString &error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkReply *makeUploadRequest(QSharedPointer<QIODevice> iodev);
|
QNetworkReply *makeUploadRequest(QSharedPointer<QIODevice> iodev);
|
||||||
|
@ -131,6 +131,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
SIGNAL(registerSuccess(QString, QString, QString)),
|
SIGNAL(registerSuccess(QString, QString, QString)),
|
||||||
this,
|
this,
|
||||||
SLOT(showChatPage(QString, QString, QString)));
|
SLOT(showChatPage(QString, QString, QString)));
|
||||||
|
connect(client_.data(), &MatrixClient::invalidToken, this, [this]() {
|
||||||
|
chat_page_->deleteConfigs();
|
||||||
|
showLoginPage();
|
||||||
|
login_page_->loginError("Invalid token detected. Please try to login again.");
|
||||||
|
});
|
||||||
|
|
||||||
QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this);
|
QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this);
|
||||||
connect(quitShortcut, &QShortcut::activated, this, QApplication::quit);
|
connect(quitShortcut, &QShortcut::activated, this, QApplication::quit);
|
||||||
|
@ -309,13 +309,24 @@ MatrixClient::sync() noexcept
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
auto data = reply->readAll();
|
||||||
|
|
||||||
if (status == 0 || status >= 400) {
|
if (status == 0 || status >= 400) {
|
||||||
qDebug() << reply->errorString();
|
try {
|
||||||
|
mtx::errors::Error res = nlohmann::json::parse(data);
|
||||||
|
|
||||||
|
if (res.errcode == mtx::errors::ErrorCode::M_UNKNOWN_TOKEN) {
|
||||||
|
emit invalidToken();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = reply->readAll();
|
emit syncError(QString::fromStdString(res.error));
|
||||||
|
|
||||||
|
return;
|
||||||
|
} catch (const nlohmann::json::exception &e) {
|
||||||
|
qWarning() << e.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mtx::responses::Sync response = nlohmann::json::parse(data);
|
mtx::responses::Sync response = nlohmann::json::parse(data);
|
||||||
|
Loading…
Reference in New Issue
Block a user