Added option to logout and login

This commit is contained in:
Santhosh Manikandan S 2021-01-11 23:35:55 +05:30
parent 1e4455482c
commit 62a17f722f
17 changed files with 317 additions and 72 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();
}
}
@ -143,7 +144,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 {
@ -155,6 +158,19 @@ Page {
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();
overviewPage.logoutLoading = true;
chatListModel.reset();
break;
default:
// Nothing ;)
}
@ -236,7 +252,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")
@ -328,7 +344,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 {
@ -357,7 +373,7 @@ Page {
opacity: overviewPage.chatListCreated ? 0 : 1
Behavior on opacity { FadeAnimation {} }
visible: !overviewPage.chatListCreated
visible: !overviewPage.chatListCreated && !overviewPage.logoutLoading
InfoLabel {
id: loadingLabel
@ -371,5 +387,20 @@ Page {
size: BusyIndicatorSize.Large
}
}
Column {
width: parent.width
spacing: Theme.paddingMedium
anchors.verticalCenter: chatListView.verticalCenter
opacity: overviewPage.logoutLoading ? 1 : 0
Behavior on opacity { FadeAnimation {} }
visible: overviewPage.logoutLoading
BusyLabel {
text: qsTr("Logging out")
running: true
}
}
}
}

View file

@ -380,6 +380,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

@ -62,6 +62,8 @@ public:
Q_INVOKABLE void redrawModel();
Q_INVOKABLE QVariantMap get(int row);
Q_INVOKABLE QVariantMap getById(qlonglong chatId);
Q_INVOKABLE void reset();
bool showAllChats() const;
void setShowAllChats(bool showAll);

View file

@ -58,7 +58,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);
@ -73,6 +75,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)));
@ -128,32 +153,15 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface,
connect(this->tdLibReceiver, SIGNAL(messageEditedUpdated(qlonglong, qlonglong, QVariantMap)), this, SIGNAL(messageEditedUpdated(qlonglong, qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(chatIsMarkedAsUnreadUpdated(qlonglong, bool)), this, SIGNAL(chatIsMarkedAsUnreadUpdated(qlonglong, bool)));
connect(this->tdLibReceiver, SIGNAL(chatDraftMessageUpdated(qlonglong, QVariantMap, QString)), this, SIGNAL(chatDraftMessageUpdated(qlonglong, QVariantMap, 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());
@ -221,6 +229,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");
@ -1199,6 +1217,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::HomeLocation) + "/.local/share/harbour-fernschreiber");
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);
@ -286,6 +289,7 @@ private:
void setEncryptionKey();
void setLogVerbosityLevel();
const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash<qlonglong,Group*> *groups);
void initializeTDLibReciever();
private:
void *tdLibClient;
@ -311,6 +315,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>
@ -1036,10 +1044,6 @@
<source>Waiting for network...</source>
<translation>Warte auf Netzwerk...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Verbinde zum Netzwerk...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Verbinde zum Proxy...</translation>
@ -1080,6 +1084,14 @@
<source>Download failed.</source>
<translation>Download fehlgeschlagen.</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Verbinde zum Netzwerk...</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>
@ -1036,10 +1044,6 @@
<source>Waiting for network...</source>
<translation>Waiting for network...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Connecting to network...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Connecting to proxy...</translation>
@ -1080,6 +1084,14 @@
<source>Download failed.</source>
<translation>Download failed.</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Connecting to network...</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>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>
@ -1025,10 +1033,6 @@
<source>Waiting for network...</source>
<translation>Esperando conexión...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Conectando al servidor...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Conectando a proxy...</translation>
@ -1069,6 +1073,14 @@
<source>Download failed.</source>
<translation type="unfinished">Error al bajar</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Conectando al servidor...</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>
@ -1037,10 +1045,6 @@
<source>Waiting for network...</source>
<translation>Odotetaan verkkoa...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Yhdistetään verkkoon...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Yhdistetään välityspalvelimeen...</translation>
@ -1081,6 +1085,14 @@
<source>Download failed.</source>
<translation type="unfinished">Lataus epäonnistui.</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Yhdistetään verkkoon...</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>
@ -1025,10 +1033,6 @@
<source>Waiting for network...</source>
<translation>Hálózatra várakozás...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Csatlakozás a hálózathoz...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Csatlakozás a proxy-hoz...</translation>
@ -1069,6 +1073,14 @@
<source>Download failed.</source>
<translation type="unfinished">A letöltés nem sikerült.</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Csatlakozás a hálózathoz...</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>
@ -1044,10 +1052,6 @@
<source>Waiting for network...</source>
<translation>Attendo la rete...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Connetto alla rete...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Connetto al proxy...</translation>
@ -1080,6 +1084,14 @@
<source>Download failed.</source>
<translation type="unfinished">Download non riuscito.</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Connetto alla rete...</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>
@ -1047,10 +1055,6 @@
<source>Waiting for network...</source>
<translation>Czekanie na sieć</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Łączenie z siecią...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Łączenie z proxy</translation>
@ -1091,6 +1095,14 @@
<source>Download failed.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Łączenie z siecią...</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>
@ -1047,10 +1055,6 @@
<source>Waiting for network...</source>
<translation>Ожидание сети...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Подключение к сети...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Подключение к прокси...</translation>
@ -1091,6 +1095,14 @@
<source>Download failed.</source>
<translation type="unfinished">Ошибка скачивания.</translation>
</message>
<message>
<source>Connecting to network...</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>Ö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>
@ -1036,10 +1044,6 @@
<source>Waiting for network...</source>
<translation>Väntar nätverk...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Ansluter till nätverket...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Ansluter till proxy...</translation>
@ -1080,6 +1084,14 @@
<source>Download failed.</source>
<translation>Nerladdning misslyckades.</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Ansluter till nätverket...</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>
@ -1025,10 +1033,6 @@
<source>Waiting for network...</source>
<translation></translation>
</message>
<message>
<source>Connecting to network...</source>
<translation></translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation></translation>
@ -1069,6 +1073,14 @@
<source>Download failed.</source>
<translation></translation>
</message>
<message>
<source>Connecting to network...</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>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>
@ -1036,10 +1044,6 @@
<source>Waiting for network...</source>
<translation>Waiting for network...</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation>Connecting to network...</translation>
</message>
<message>
<source>Connecting to proxy...</source>
<translation>Connecting to proxy...</translation>
@ -1080,6 +1084,14 @@
<source>Download failed.</source>
<translation type="unfinished">Download failed.</translation>
</message>
<message>
<source>Connecting to network...</source>
<translation type="unfinished">Connecting to network...</translation>
</message>
<message>
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>