Merge pull request #311 from santhoshmanikandan/logout

Log out and log in as a different user
This commit is contained in:
Sebastian Wolf 2021-01-15 22:29:01 +01:00 committed by GitHub
commit 94b33d1d92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 264 additions and 38 deletions

View file

@ -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();
}
}
}
}
}
}
}

View file

@ -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 {
BusyLabel {
id: loadingBusyIndicator
anchors.horizontalCenter: parent.horizontalCenter
running: !overviewPage.chatListCreated
size: BusyIndicatorSize.Large
running: true
}
}
}

View file

@ -390,6 +390,12 @@ ChatListModel::~ChatListModel()
qDeleteAll(hiddenChats.values());
}
void ChatListModel::reset()
{
chatList.clear();
hiddenChats.clear();
}
QHash<int,QByteArray> ChatListModel::roleNames() const
{
QHash<int,QByteArray> roles;

View file

@ -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;

View file

@ -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);

View file

@ -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<qlonglong,Group*> *groups);
void initializeTDLibReciever();
private:
void *tdLibClient;
@ -320,6 +324,7 @@ private:
QString activeChatSearchName;
bool joinChatRequested;
bool isLoggingOut;
};

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>rlottie auf GitHub öffnen</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1159,6 +1167,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>Sie können über das Pull-Down-Menü öffentliche Chats finden oder einen Neuen erstellen.</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Open rlottie on GitHub</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1159,6 +1167,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>You can search public chats or create a new chat via the pull-down menu.</translation>
</message>
<message>
<source>Logging out</source>
<translation>Logging out</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Librería rlottie</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1144,6 +1152,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>Puede buscar charlas públicas o crear un nueva charla a través de la polea de opciones.</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Avaa rlottie GitHubissa</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1160,6 +1168,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>Voit etsiä julkisia keskusteluja tai luoda uuden keskustelun alasvetovalikosta.</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1144,6 +1152,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Apri rlottie su GitHub</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1159,6 +1167,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>Puoi creare una nuova chat o cercare chat pubbliche dal menu a trascinamento.</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Otwórz rlottie na GitHub</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1174,6 +1182,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>Możesz przeszukiwać czaty publiczne lub utworzyć nowy czat za pomocą menu rozwijanego z góry.</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Открыть rlottie на GitHub</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1174,6 +1182,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>Вы можете искать публичные чаты или создать новый чат с помощью выпадающего меню</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Öppna rlottie GitHub</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1159,6 +1167,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation>Du kan söka efter allmänna chattar eller skapa en ny chatt via toppmenyn.</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation> Github rlottie</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1144,6 +1152,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation></translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -83,6 +83,14 @@
<source>Open rlottie on GitHub</source>
<translation>Open rlottie on GitHub</translation>
</message>
<message>
<source>Log Out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>
@ -1159,6 +1167,10 @@
<source>You can search public chats or create a new chat via the pull-down menu.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>