diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index 87af291..70fbcce 100644 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -25,6 +25,7 @@ Page { id: aboutPage allowedOrientations: Orientation.All + property bool isLoggedIn : false property var userInformation : tdLibWrapper.getUserInformation(); SilicaFlickable { @@ -156,7 +157,8 @@ Page { } Loader { - active: !!aboutPage.userInformation.phone_number + id: userInformationLoader + active: isLoggedIn width: parent.width sourceComponent: Component { Column { @@ -196,6 +198,33 @@ Page { horizontalCenter: parent.horizontalCenter } } + BackgroundItem { + width: parent.width + + BackgroundItem { + id: logOutItem + width: parent.width + function showRemorseItem() { + remorse.execute(logOutItem, qsTr("Logged out"), function() { + tdLibWrapper.logout(); + pageStack.pop(); + }); + } + RemorseItem { + id: remorse + } + Button { + id: logOutButton + text: qsTr("Log Out") + anchors { + horizontalCenter: parent.horizontalCenter + } + onClicked: { + logOutItem.showRemorseItem(); + } + } + } + } } } } diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index b58dbc0..40a9bc1 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -31,13 +31,14 @@ Page { property bool initializationCompleted: false; property bool loading: true; + property bool logoutLoading: false; property int authorizationState: TelegramAPI.Closed property int connectionState: TelegramAPI.WaitingForNetwork property int ownUserId; property bool chatListCreated: false; onStatusChanged: { - if (status === PageStatus.Active && initializationCompleted && !chatListCreated) { + if (status === PageStatus.Active && initializationCompleted && !chatListCreated && !logoutLoading) { updateContent(); } } @@ -151,7 +152,9 @@ Page { case TelegramAPI.WaitCode: case TelegramAPI.WaitPassword: case TelegramAPI.WaitRegistration: + case TelegramAPI.AuthorizationStateClosed: overviewPage.loading = false; + overviewPage.logoutLoading = false; if(isOnInitialization) { // pageStack isn't ready on Component.onCompleted openInitializationPageTimer.start() } else { @@ -159,10 +162,25 @@ Page { } break; case TelegramAPI.AuthorizationReady: + loadingBusyIndicator.text = qsTr("Loading chat list..."); overviewPage.loading = false; overviewPage.initializationCompleted = true; overviewPage.updateContent(); break; + case TelegramAPI.AuthorizationStateLoggingOut: + if (logoutLoading) { + Debug.log("Resources cleared already"); + return; + } + Debug.log("Logging out") + overviewPage.initializationCompleted = false; + overviewPage.loading = false; + chatListCreatedTimer.stop(); + updateSecondaryContentTimer.stop(); + loadingBusyIndicator.text = qsTr("Logging out") + overviewPage.logoutLoading = true; + chatListModel.reset(); + break; default: // Nothing ;) } @@ -254,7 +272,7 @@ Page { } MenuItem { text: qsTr("About Fernschreiber") - onClicked: pageStack.push(Qt.resolvedUrl("../pages/AboutPage.qml")) + onClicked: pageStack.push(Qt.resolvedUrl("../pages/AboutPage.qml"), {isLoggedIn : (overviewPage.authorizationState == TelegramAPI.AuthorizationReady)}) } MenuItem { text: qsTr("Settings") @@ -331,7 +349,7 @@ Page { right: parent.right } clip: true - opacity: overviewPage.chatListCreated ? 1 : 0 + opacity: (overviewPage.chatListCreated && !overviewPage.logoutLoading) ? 1 : 0 Behavior on opacity { FadeAnimation {} } model: chatListModel delegate: ChatListViewItem { @@ -359,20 +377,13 @@ Page { spacing: Theme.paddingMedium anchors.verticalCenter: chatListView.verticalCenter - opacity: overviewPage.chatListCreated ? 0 : 1 + opacity: overviewPage.chatListCreated && !overviewPage.logoutLoading ? 0 : 1 Behavior on opacity { FadeAnimation {} } - visible: !overviewPage.chatListCreated + visible: !overviewPage.chatListCreated || overviewPage.logoutLoading - InfoLabel { - id: loadingLabel - text: qsTr("Loading chat list...") - } - - BusyIndicator { - id: loadingBusyIndicator - anchors.horizontalCenter: parent.horizontalCenter - running: !overviewPage.chatListCreated - size: BusyIndicatorSize.Large + BusyLabel { + id: loadingBusyIndicator + running: true } } } diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index f6de2be..1a796be 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -390,6 +390,12 @@ ChatListModel::~ChatListModel() qDeleteAll(hiddenChats.values()); } +void ChatListModel::reset() +{ + chatList.clear(); + hiddenChats.clear(); +} + QHash ChatListModel::roleNames() const { QHash roles; diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 91fd8a0..8c17d75 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -64,6 +64,8 @@ public: Q_INVOKABLE void redrawModel(); Q_INVOKABLE QVariantMap get(int row); Q_INVOKABLE QVariantMap getById(qlonglong chatId); + Q_INVOKABLE void reset(); + Q_INVOKABLE void calculateUnreadState(); bool showAllChats() const; diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 6731805..f8cdcb8 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -60,7 +60,9 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, this->mceInterface = mceInterface; this->tdLibClient = td_json_client_create(); this->authorizationState = AuthorizationState::Closed; - this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); + this->isLoggingOut = false; + + initializeTDLibReciever(); QString tdLibDatabaseDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib"; QDir tdLibDatabaseDirectory(tdLibDatabaseDirectoryPath); @@ -75,6 +77,29 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, this->removeOpenWith(); } + connect(&emojiSearchWorker, SIGNAL(searchCompleted(QString, QVariantList)), this, SLOT(handleEmojiSearchCompleted(QString, QVariantList))); + + connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged())); + connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged())); + + this->setLogVerbosityLevel(); + this->setOptionInteger("notification_group_count_max", 5); +} + +TDLibWrapper::~TDLibWrapper() +{ + LOG("Destroying TD Lib..."); + this->tdLibReceiver->setActive(false); + while (this->tdLibReceiver->isRunning()) { + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + } + qDeleteAll(basicGroups.values()); + qDeleteAll(superGroups.values()); + td_json_client_destroy(this->tdLibClient); +} + +void TDLibWrapper::initializeTDLibReciever() { + this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString))); connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString, QVariantMap)), this, SLOT(handleAuthorizationStateChanged(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant))); @@ -134,31 +159,15 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, connect(this->tdLibReceiver, SIGNAL(inlineQueryResults(QString, QString, QVariantList, QString, QString, QString)), this, SIGNAL(inlineQueryResults(QString, QString, QVariantList, QString, QString, QString))); connect(this->tdLibReceiver, SIGNAL(callbackQueryAnswer(QString, bool, QString)), this, SIGNAL(callbackQueryAnswer(QString, bool, QString))); - connect(&emojiSearchWorker, SIGNAL(searchCompleted(QString, QVariantList)), this, SLOT(handleEmojiSearchCompleted(QString, QVariantList))); - - connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged())); - connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged())); - this->tdLibReceiver->start(); - - this->setLogVerbosityLevel(); - this->setOptionInteger("notification_group_count_max", 5); -} - -TDLibWrapper::~TDLibWrapper() -{ - LOG("Destroying TD Lib..."); - this->tdLibReceiver->setActive(false); - while (this->tdLibReceiver->isRunning()) { - QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); - } - qDeleteAll(basicGroups.values()); - qDeleteAll(superGroups.values()); - td_json_client_destroy(this->tdLibClient); } void TDLibWrapper::sendRequest(const QVariantMap &requestObject) { + if (this->isLoggingOut) { + LOG("Sending request to TD Lib skipped as logging out is in progress, object type name:" << requestObject.value(_TYPE).toString()); + return; + } LOG("Sending request to TD Lib, object type name:" << requestObject.value(_TYPE).toString()); QJsonDocument requestDocument = QJsonDocument::fromVariant(requestObject); VERBOSE(requestDocument.toJson().constData()); @@ -226,6 +235,16 @@ void TDLibWrapper::registerUser(const QString &firstName, const QString &lastNam this->sendRequest(requestObject); } +void TDLibWrapper::logout() +{ + LOG("Logging out"); + QVariantMap requestObject; + requestObject.insert("@type", "logOut"); + this->sendRequest(requestObject); + this->isLoggingOut = true; + +} + void TDLibWrapper::getChats() { LOG("Getting chats"); @@ -1318,6 +1337,28 @@ void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationS this->setInitialParameters(); this->authorizationState = AuthorizationState::WaitTdlibParameters; } + if (authorizationState == "authorizationStateLoggingOut") { + this->authorizationState = AuthorizationState::AuthorizationStateLoggingOut; + } + if (authorizationState == "authorizationStateClosed") { + this->authorizationState = AuthorizationState::AuthorizationStateClosed; + LOG("Reloading TD Lib..."); + this->basicGroups.clear(); + this->superGroups.clear(); + this->allUsers.clear(); + this->allUserNames.clear(); + this->tdLibReceiver->setActive(false); + while (this->tdLibReceiver->isRunning()) { + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + } + td_json_client_destroy(this->tdLibClient); + this->tdLibReceiver->terminate(); + QDir appPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + appPath.removeRecursively(); + this->tdLibClient = td_json_client_create(); + initializeTDLibReciever(); + this->isLoggingOut = false; + } this->authorizationStateData = authorizationStateData; emit authorizationStateChanged(this->authorizationState, this->authorizationStateData); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index a6c25f5..914ccf6 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -46,7 +46,9 @@ public: WaitPassword, WaitPhoneNumber, WaitRegistration, - WaitTdlibParameters + WaitTdlibParameters, + AuthorizationStateClosed, + AuthorizationStateLoggingOut }; Q_ENUM(AuthorizationState) @@ -125,6 +127,7 @@ public: Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); Q_INVOKABLE void setAuthenticationPassword(const QString &authenticationPassword); Q_INVOKABLE void registerUser(const QString &firstName, const QString &lastName); + Q_INVOKABLE void logout(); Q_INVOKABLE void getChats(); Q_INVOKABLE void downloadFile(int fileId); Q_INVOKABLE void openChat(const QString &chatId); @@ -295,6 +298,7 @@ private: void setEncryptionKey(); void setLogVerbosityLevel(); const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash *groups); + void initializeTDLibReciever(); private: void *tdLibClient; @@ -320,6 +324,7 @@ private: QString activeChatSearchName; bool joinChatRequested; + bool isLoggingOut; }; diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 1e481d7..2d6978c 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub rlottie auf GitHub öffnen + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1159,6 +1167,10 @@ You can search public chats or create a new chat via the pull-down menu. Sie können über das Pull-Down-Menü öffentliche Chats finden oder einen Neuen erstellen. + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index 93be06c..1db9d16 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Open rlottie on GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1159,6 +1167,10 @@ You can search public chats or create a new chat via the pull-down menu. You can search public chats or create a new chat via the pull-down menu. + + Logging out + Logging out + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index 651fe9f..7dee1a2 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Librería rlottie + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1144,6 +1152,10 @@ You can search public chats or create a new chat via the pull-down menu. Puede buscar charlas públicas o crear un nueva charla a través de la polea de opciones. + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index afc69ed..99e7130 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Avaa rlottie GitHubissa + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1160,6 +1168,10 @@ You can search public chats or create a new chat via the pull-down menu. Voit etsiä julkisia keskusteluja tai luoda uuden keskustelun alasvetovalikosta. + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index 16941a4..b03007c 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1144,6 +1152,10 @@ You can search public chats or create a new chat via the pull-down menu. + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index 404fd0b..1a7c553 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Apri rlottie su GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1159,6 +1167,10 @@ You can search public chats or create a new chat via the pull-down menu. Puoi creare una nuova chat o cercare chat pubbliche dal menu a trascinamento. + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index 7b7fda5..51d5db4 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Otwórz rlottie na GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1174,6 +1182,10 @@ You can search public chats or create a new chat via the pull-down menu. Możesz przeszukiwać czaty publiczne lub utworzyć nowy czat za pomocą menu rozwijanego z góry. + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 515ee02..08f3600 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Открыть rlottie на GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1174,6 +1182,10 @@ You can search public chats or create a new chat via the pull-down menu. Вы можете искать публичные чаты или создать новый чат с помощью выпадающего меню + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index 6d7cd90..6bd2e8e 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Öppna rlottie på GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1159,6 +1167,10 @@ You can search public chats or create a new chat via the pull-down menu. Du kan söka efter allmänna chattar eller skapa en ny chatt via toppmenyn. + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 3cd5cfd..39f507f 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub 在 Github 打开 rlottie + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1144,6 +1152,10 @@ You can search public chats or create a new chat via the pull-down menu. 你可以搜索公共对话或通过下拉菜单创建新对话。 + + Logging out + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index b723da0..9dd1765 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -83,6 +83,14 @@ Open rlottie on GitHub Open rlottie on GitHub + + Log Out + + + + Logged out + + BackgroundProgressIndicator @@ -1159,6 +1167,10 @@ You can search public chats or create a new chat via the pull-down menu. + + Logging out + + PinnedMessageItem