Merge pull request #42 from jgibbon/feature/userRegistration

handle user registration
This commit is contained in:
Sebastian Wolf 2020-10-04 13:30:48 +02:00 committed by GitHub
commit b712e647ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 545 additions and 227 deletions

View file

@ -34,7 +34,7 @@ const char TDLIB_API_HASH[] = "1234567890abcdef1234567890abcdef";
You get the Telegram API ID and hash as soon as you've registered your own application on [https://my.telegram.org](https://my.telegram.org). You get the Telegram API ID and hash as soon as you've registered your own application on [https://my.telegram.org](https://my.telegram.org).
Moreover, you need to have a compiled version of [TDLib](https://github.com/tdlib/td) in the sub-directory `tdlib`. This sub-directory must contain another sub-directory that fits to the target device architecture (e.g. armv7hl, i486). Within this directory, there needs to be a folder called `lib` that contains at least `libtdjson.so`. For armv7hl the relative path would consequently be `tdlib/armv7hl/lib`. Before compiling the project, be sure to set the target architecture in the project file `harbour-fernschreiber.pro` correctly using the variable `TARGET_ARCHITECTURE`. This can most certainly be automated. Pull requests welcome! ;) Moreover, you need to have a compiled version of [TDLib](https://github.com/tdlib/td) in the sub-directory `tdlib`. This sub-directory must contain another sub-directory that fits to the target device architecture (e.g. armv7hl, i486). Within this directory, there needs to be a folder called `lib` that contains at least `libtdjson.so`. For armv7hl the relative path would consequently be `tdlib/armv7hl/lib`.
## Credits ## Credits
This project uses This project uses

View file

@ -58,8 +58,11 @@ TRANSLATIONS += translations/harbour-fernschreiber-de.ts \
translations/harbour-fernschreiber-pl.ts \ translations/harbour-fernschreiber-pl.ts \
translations/harbour-fernschreiber-zh_CN.ts translations/harbour-fernschreiber-zh_CN.ts
# Use armv7hl for most devices and i486 for emulator and Jolla Tablet. Can most certainly be automated... ;) contains(QT_ARCH, arm) {
TARGET_ARCHITECTURE = armv7hl TARGET_ARCHITECTURE = armv7hl
} else {
TARGET_ARCHITECTURE = i486
}
INCLUDEPATH += $$PWD/tdlib/include INCLUDEPATH += $$PWD/tdlib/include
DEPENDPATH += $$PWD/tdlib/include DEPENDPATH += $$PWD/tdlib/include

View file

@ -65,7 +65,7 @@ CoverBackground {
Component.onCompleted: { Component.onCompleted: {
coverPage.authenticated = (tdLibWrapper.getAuthorizationState() === TelegramAPI.AuthorizationReady); coverPage.authenticated = (tdLibWrapper.getAuthorizationState() === TelegramAPI.AuthorizationReady);
coverPage.connectionState = tdLibWrapper.getConnectionState(); coverPage.connectionState = tdLibWrapper.getConnectionState();
coverPage.unreadMessages = tdLibWrapper.getUnreadMessageInformation().unread_count; coverPage.unreadMessages = tdLibWrapper.getUnreadMessageInformation().unread_count || 0;
coverPage.unreadChats = tdLibWrapper.getUnreadChatInformation().unread_count; coverPage.unreadChats = tdLibWrapper.getUnreadChatInformation().unread_count;
setUnreadInfoText(); setUnreadInfoText();
} }

View file

@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>. along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/ */
import QtQuick 2.2 import QtQuick 2.6
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import WerkWolf.Fernschreiber 1.0 import WerkWolf.Fernschreiber 1.0
@ -27,6 +27,7 @@ Page {
property bool loading: true property bool loading: true
property int authorizationState: TelegramAPI.Closed property int authorizationState: TelegramAPI.Closed
property var authorizationStateData: null
BusyLabel { BusyLabel {
text: qsTr("Loading...") text: qsTr("Loading...")
@ -35,16 +36,33 @@ Page {
Component.onCompleted: { Component.onCompleted: {
initializationPage.authorizationState = tdLibWrapper.getAuthorizationState(); initializationPage.authorizationState = tdLibWrapper.getAuthorizationState();
initializationPage.authorizationStateData = tdLibWrapper.getAuthorizationStateData();
initializationPage.loading = false; initializationPage.loading = false;
if (initializationPage.authorizationState === TelegramAPI.WaitCode) {
welcomeFlickable.visible = false; switch (authorizationState) {
case TelegramAPI.WaitCode:
initializationPage.loading = false;
welcomeColumn.visible = false;
enterPinColumn.visible = true; enterPinColumn.visible = true;
enterPasswordColumn.visible = false; enterPasswordColumn.visible = false;
} waitRegistrationColumn.visible = false;
if (initializationPage.authorizationState === TelegramAPI.WaitPassword) { break;
welcomeFlickable.visible = false; case TelegramAPI.WaitPassword:
initializationPage.loading = false;
welcomeColumn.visible = false;
enterPinColumn.visible = false; enterPinColumn.visible = false;
enterPasswordColumn.visible = true; enterPasswordColumn.visible = true;
waitRegistrationColumn.visible = false;
break;
case TelegramAPI.WaitRegistration:
initializationPage.loading = false;
welcomeColumn.visible = false;
enterPinColumn.visible = false;
enterPasswordColumn.visible = false;
waitRegistrationColumn.visible = true;
break;
default:
// Nothing ;)
} }
} }
@ -56,11 +74,19 @@ Page {
initializationPage.loading = false; initializationPage.loading = false;
enterPinColumn.visible = true; enterPinColumn.visible = true;
enterPasswordColumn.visible = false; enterPasswordColumn.visible = false;
waitRegistrationColumn.visible = false;
break; break;
case TelegramAPI.WaitPassword: case TelegramAPI.WaitPassword:
initializationPage.loading = false; initializationPage.loading = false;
enterPinColumn.visible = false; enterPinColumn.visible = false;
enterPasswordColumn.visible = true; enterPasswordColumn.visible = true;
waitRegistrationColumn.visible = false;
break;
case TelegramAPI.WaitRegistration:
initializationPage.loading = false;
enterPinColumn.visible = false;
enterPasswordColumn.visible = false;
waitRegistrationColumn.visible = true;
break; break;
case TelegramAPI.AuthorizationReady: case TelegramAPI.AuthorizationReady:
initializationPage.loading = false; initializationPage.loading = false;
@ -70,214 +96,16 @@ Page {
default: default:
// Nothing ;) // Nothing ;)
} }
initializationPage.authorizationStateData = authorizationStateData;
} }
} }
Column {
y: ( parent.height - ( errorInfoLabel.height + fernschreiberErrorImage.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
id: pinErrorColumn
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1 : 0
visible: false
Image {
id: fernschreiberErrorImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: errorInfoLabel
font.pixelSize: Theme.fontSizeLarge
text: ""
}
Button {
id: errorOkButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
pinErrorColumn.visible = false;
welcomeFlickable.visible = true;
}
}
}
Column {
y: ( parent.height - ( fernschreiberPasswordImage.height + enterPasswordLabel.height + enterPasswordField.height + enterPasswordButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
id: enterPasswordColumn
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? true : false
visible: false
Image {
id: fernschreiberPasswordImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: enterPasswordLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Please enter your password:")
}
PasswordField {
id: enterPasswordField
anchors {
horizontalCenter: parent.horizontalCenter
}
font.pixelSize: Theme.fontSizeLarge
width: parent.width - 2 * Theme.horizontalPageMargin
horizontalAlignment: TextInput.AlignHCenter
}
Button {
id: enterPasswordButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
initializationPage.loading = true;
enterPasswordColumn.visible = false;
tdLibWrapper.setAuthenticationPassword(enterPasswordField.text);
}
}
}
Column {
y: ( parent.height - ( fernschreiberPinImage.height + enterPinLabel.height + enterPinField.height + enterPinButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
id: enterPinColumn
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? true : false
visible: false
Image {
id: fernschreiberPinImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: enterPinLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Please enter the code that you received:")
}
TextField {
id: enterPinField
anchors {
horizontalCenter: parent.horizontalCenter
}
inputMethodHints: Qt.ImhDigitsOnly
font.pixelSize: Theme.fontSizeExtraLarge
width: parent.width - 4 * Theme.paddingLarge
horizontalAlignment: TextInput.AlignHCenter
}
Button {
id: enterPinButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
initializationPage.loading = true;
enterPinColumn.visible = false;
tdLibWrapper.setAuthenticationCode(enterPinField.text);
}
}
}
Column {
y: ( parent.height - ( fernschreiberLinkingErrorImage.height + linkingErrorInfoLabel.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
id: linkingErrorColumn
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? true : false
visible: false
Image {
id: fernschreiberLinkingErrorImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: linkingErrorInfoLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Unable to authenticate you with the entered code.")
}
Button {
id: enterPinAgainButton
text: qsTr("Enter code again")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
linkingErrorColumn.visible = false;
enterPinColumn.visible = true;
}
}
Button {
id: restartAuthenticationButton
text: qsTr("Restart authentication")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
linkingErrorColumn.visible = false;
welcomeFlickable.visible = true;
}
}
}
SilicaFlickable { SilicaFlickable {
id: welcomeFlickable id: welcomeFlickable
contentHeight: welcomeColumn.height contentHeight: contentItem.childrenRect.height
Behavior on opacity { NumberAnimation {} } Behavior on contentHeight { NumberAnimation {} }
anchors.fill: parent anchors.fill: parent
opacity: visible ? 1 : 0
Column { Column {
id: welcomeColumn id: welcomeColumn
@ -330,12 +158,340 @@ Page {
enabled: phoneNumberTextField.text.match(/\+[1-9][0-9]{4,}/g) enabled: phoneNumberTextField.text.match(/\+[1-9][0-9]{4,}/g)
onClicked: { onClicked: {
initializationPage.loading = true; initializationPage.loading = true;
welcomeFlickable.visible = false; welcomeColumn.visible = false;
tdLibWrapper.setAuthenticationPhoneNumber(phoneNumberTextField.text); tdLibWrapper.setAuthenticationPhoneNumber(phoneNumberTextField.text);
} }
} }
} }
Column {
id: pinErrorColumn
// y: ( parent.height - ( errorInfoLabel.height + fernschreiberErrorImage.height + errorOkButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1 : 0
visible: false
Image {
id: fernschreiberErrorImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: errorInfoLabel
font.pixelSize: Theme.fontSizeLarge
text: ""
}
Button {
id: errorOkButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
pinErrorColumn.visible = false;
welcomeColumn.visible = true;
}
}
}
Column {
id: enterPasswordColumn
// y: ( parent.height - ( fernschreiberPasswordImage.height + enterPasswordLabel.height + enterPasswordField.height + enterPasswordButton.height + ( 3 * Theme.paddingSmall ) ) ) / 2
width: parent.width
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1.0 : 0.0
visible: false
Image {
id: fernschreiberPasswordImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: enterPasswordLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Please enter your password:")
}
PasswordField {
id: enterPasswordField
anchors {
horizontalCenter: parent.horizontalCenter
}
font.pixelSize: Theme.fontSizeLarge
width: parent.width - 2 * Theme.horizontalPageMargin
horizontalAlignment: TextInput.AlignHCenter
}
Button {
id: enterPasswordButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
initializationPage.loading = true;
enterPasswordColumn.visible = false;
tdLibWrapper.setAuthenticationPassword(enterPasswordField.text);
}
}
}
Column {
id: enterPinColumn
topPadding: Theme.paddingLarge
bottomPadding: Theme.paddingLarge
width: parent.width
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1.0 : 0.0
visible: false
Image {
id: fernschreiberPinImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: enterPinLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Please enter the code that you received:")
}
TextField {
id: enterPinField
anchors {
horizontalCenter: parent.horizontalCenter
}
inputMethodHints: Qt.ImhDigitsOnly
font.pixelSize: Theme.fontSizeExtraLarge
width: parent.width - 4 * Theme.paddingLarge
horizontalAlignment: TextInput.AlignHCenter
}
Button {
id: enterPinButton
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
initializationPage.loading = true;
enterPinColumn.visible = false;
tdLibWrapper.setAuthenticationCode(enterPinField.text);
}
}
}
Column {
id: linkingErrorColumn
topPadding: Theme.paddingLarge
bottomPadding: Theme.paddingLarge
width: parent.width
spacing: Theme.paddingSmall
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1.0 : 0.0
visible: false
Image {
id: fernschreiberLinkingErrorImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * parent.width
}
InfoLabel {
id: linkingErrorInfoLabel
font.pixelSize: Theme.fontSizeLarge
text: qsTr("Unable to authenticate you with the entered code.")
}
Button {
id: enterPinAgainButton
text: qsTr("Enter code again")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
linkingErrorColumn.visible = false;
enterPinColumn.visible = true;
}
}
Button {
id: restartAuthenticationButton
text: qsTr("Restart authentication")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
linkingErrorColumn.visible = false;
welcomeColumn.visible = true;
}
}
}
Column {
id: waitRegistrationColumn
topPadding: Theme.paddingLarge
bottomPadding: Theme.paddingLarge
width: parent.width
spacing: Theme.paddingLarge
Behavior on opacity { NumberAnimation {} }
opacity: visible ? 1.0 : 0.0
visible: false
PageHeader {
title: qsTr("User Registration")
}
Image {
id: waitRegistrationImage
source: "../../images/fernschreiber.png"
anchors {
horizontalCenter: parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
asynchronous: true
width: 1/2 * Screen.width
}
InfoLabel {
id: waitRegistrationInfoLabel
property bool acknowledged
font.pixelSize: Theme.fontSizeExtraSmall
textFormat: Text.StyledText
horizontalAlignment: Text.AlignLeft
linkColor: Theme.primaryColor
property var stateText: initializationPage.authorizationStateData.authorization_state && initializationPage.authorizationStateData.authorization_state.terms_of_service ?
initializationPage.authorizationStateData.authorization_state.terms_of_service.text :
null
visible: !!stateText && !acknowledged
text: {
if(!stateText) {
return '';
}
var entities = stateText.entities;
if(entities && entities.length > 0 && entities[0]["type"]["@type"] === "textEntityTypeTextUrl") { //we just use the first entity for now.
var offset = entities[0].offset;
var length = entities[0].length;
return (stateText.text.slice(0,entities[0].offset)
+ "<a href=\""+entities[0]["type"]["url"]+"\">"
+ stateText.text.slice(entities[0].offset, entities[0].offset + entities[0].length)
+ '</a>'
+ stateText.text.slice(entities[0].offset + entities[0].length)).replace(/\n/gm, "<br>");
}
return stateText.text.replace(/\n/gm, "<br>");
}
//JSON.stringify(initializationPage.authorizationStateData, null, 2)//qsTr("Unable to authenticate you with the entered code.")
}
Button {
id: acknowledgeTOCButton
visible: waitRegistrationInfoLabel.visible
text: qsTr("OK")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
waitRegistrationInfoLabel.acknowledged = true;
userFirstNameTextField.focus = true
}
}
RegExpValidator {
id: filledValidator
regExp: /.+/
}
TextField {
id: userFirstNameTextField
visible: !waitRegistrationInfoLabel.visible
opacity: visible ? 1.0 : 0.0
Behavior on opacity { NumberAnimation {} }
placeholderText: qsTr("Enter your First Name")
labelVisible: false
width: parent.width
EnterKey.iconSource: !!text ? "image://theme/icon-m-enter-next" : "image://theme/icon-m-text-input"
EnterKey.onClicked: {
validator = filledValidator
if(acceptableInput) userLastNameTextField.focus = true;
}
}
TextField {
id: userLastNameTextField
visible: !waitRegistrationInfoLabel.visible
opacity: visible ? 1.0 : 0.0
Behavior on opacity { NumberAnimation {} }
placeholderText: qsTr("Enter your Last Name")
labelVisible: false
width: parent.width
EnterKey.iconSource: !!text ? "image://theme/icon-m-enter-accept" : "image://theme/icon-m-text-input"
EnterKey.onClicked: {
validator = filledValidator
if(acceptableInput) registerUserButton.onClicked(null);
}
}
Button {
id: registerUserButton
visible: !waitRegistrationInfoLabel.visible
opacity: visible ? 1.0 : 0.0
Behavior on opacity { NumberAnimation {} }
text: qsTr("Register User")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
userFirstNameTextField.validator = filledValidator
userLastNameTextField.validator = filledValidator
if(userFirstNameTextField.acceptableInput && userLastNameTextField.acceptableInput) {
tdLibWrapper.registerUser(userFirstNameTextField.text, userLastNameTextField.text);
} else if(!userFirstNameTextField.acceptableInput) {
userFirstNameTextField.focus = true;
} else {
userLastNameTextField.focus = true;
}
}
}
}
} }
} }

View file

@ -106,14 +106,9 @@ Page {
function handleAuthorizationState() { function handleAuthorizationState() {
switch (overviewPage.authorizationState) { switch (overviewPage.authorizationState) {
case TelegramAPI.WaitPhoneNumber: case TelegramAPI.WaitPhoneNumber:
overviewPage.loading = false;
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break;
case TelegramAPI.WaitCode: case TelegramAPI.WaitCode:
overviewPage.loading = false;
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break;
case TelegramAPI.WaitPassword: case TelegramAPI.WaitPassword:
case TelegramAPI.WaitRegistration:
overviewPage.loading = false; overviewPage.loading = false;
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml")); pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
break; break;
@ -152,6 +147,12 @@ Page {
chatListCreatedTimer.start(); chatListCreatedTimer.start();
} }
} }
onChatsReceived: {
if(chats && chats.chat_ids && chats.chat_ids.length === 0) {
chatListCreatedTimer.stop();
chatListCreatedTimer.start();
}
}
} }
Component.onCompleted: { Component.onCompleted: {
@ -215,7 +216,6 @@ Page {
anchors.fill: parent anchors.fill: parent
clip: true clip: true
visible: count > 0
opacity: overviewPage.chatListCreated ? 1 : 0 opacity: overviewPage.chatListCreated ? 1 : 0
Behavior on opacity { NumberAnimation {} } Behavior on opacity { NumberAnimation {} }
@ -389,6 +389,11 @@ Page {
} }
ViewPlaceholder {
enabled: chatListView.count === 0
text: qsTr("You don't have any chats yet.")
}
VerticalScrollDecorator {} VerticalScrollDecorator {}
} }

View file

@ -90,6 +90,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
handlers.insert("updateChatNotificationSettings", &TDLibReceiver::processUpdateChatNotificationSettings); handlers.insert("updateChatNotificationSettings", &TDLibReceiver::processUpdateChatNotificationSettings);
handlers.insert("updateMessageContent", &TDLibReceiver::processUpdateMessageContent); handlers.insert("updateMessageContent", &TDLibReceiver::processUpdateMessageContent);
handlers.insert("updateDeleteMessages", &TDLibReceiver::processUpdateDeleteMessages); handlers.insert("updateDeleteMessages", &TDLibReceiver::processUpdateDeleteMessages);
handlers.insert("chats", &TDLibReceiver::processChats);
} }
void TDLibReceiver::setActive(const bool &active) void TDLibReceiver::setActive(const bool &active)
@ -148,7 +149,7 @@ void TDLibReceiver::processUpdateAuthorizationState(const QVariantMap &receivedI
{ {
QString authorizationState = receivedInformation.value("authorization_state").toMap().value("@type").toString(); QString authorizationState = receivedInformation.value("authorization_state").toMap().value("@type").toString();
LOG("Authorization state changed: " << authorizationState); LOG("Authorization state changed: " << authorizationState);
emit authorizationStateChanged(authorizationState); emit authorizationStateChanged(authorizationState, receivedInformation);
} }
void TDLibReceiver::processUpdateConnectionState(const QVariantMap &receivedInformation) void TDLibReceiver::processUpdateConnectionState(const QVariantMap &receivedInformation)
@ -353,3 +354,8 @@ void TDLibReceiver::processUpdateDeleteMessages(const QVariantMap &receivedInfor
LOG("Some messages were deleted " << chatId); LOG("Some messages were deleted " << chatId);
emit messagesDeleted(chatId, messageIds); emit messagesDeleted(chatId, messageIds);
} }
void TDLibReceiver::processChats(const QVariantMap &receivedInformation)
{
emit chats(receivedInformation);
}

View file

@ -37,7 +37,7 @@ public:
signals: signals:
void versionDetected(const QString &version); void versionDetected(const QString &version);
void authorizationStateChanged(const QString &authorizationState); void authorizationStateChanged(const QString &authorizationState, const QVariantMap &authorizationStateData);
void optionUpdated(const QString &optionName, const QVariant &optionValue); void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const QString &connectionState); void connectionStateChanged(const QString &connectionState);
void userUpdated(const QVariantMap &userInformation); void userUpdated(const QVariantMap &userInformation);
@ -63,6 +63,7 @@ signals:
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap updatedChatNotificationSettings); void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap updatedChatNotificationSettings);
void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent); void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
void messagesDeleted(const QString &chatId, const QVariantList &messageIds); void messagesDeleted(const QString &chatId, const QVariantList &messageIds);
void chats(const QVariantMap &chats);
private: private:
typedef void (TDLibReceiver::*Handler)(const QVariantMap &); typedef void (TDLibReceiver::*Handler)(const QVariantMap &);
@ -101,6 +102,7 @@ private:
void processUpdateChatNotificationSettings(const QVariantMap &receivedInformation); void processUpdateChatNotificationSettings(const QVariantMap &receivedInformation);
void processUpdateMessageContent(const QVariantMap &receivedInformation); void processUpdateMessageContent(const QVariantMap &receivedInformation);
void processUpdateDeleteMessages(const QVariantMap &receivedInformation); void processUpdateDeleteMessages(const QVariantMap &receivedInformation);
void processChats(const QVariantMap &receivedInformation);
}; };
#endif // TDLIBRECEIVER_H #endif // TDLIBRECEIVER_H

View file

@ -46,7 +46,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent), settings("harbour
this->initializeOpenWith(); this->initializeOpenWith();
connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString))); connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString)));
connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString)), this, SLOT(handleAuthorizationStateChanged(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))); connect(this->tdLibReceiver, SIGNAL(optionUpdated(QString, QVariant)), this, SLOT(handleOptionUpdated(QString, QVariant)));
connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString))); connect(this->tdLibReceiver, SIGNAL(connectionStateChanged(QString)), this, SLOT(handleConnectionStateChanged(QString)));
connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap))); connect(this->tdLibReceiver, SIGNAL(userUpdated(QVariantMap)), this, SLOT(handleUserUpdated(QVariantMap)));
@ -72,6 +72,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent), settings("harbour
connect(this->tdLibReceiver, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageContentUpdated(QString, QString, QVariantMap)), this, SLOT(handleMessageContentUpdated(QString, QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(messageContentUpdated(QString, QString, QVariantMap)), this, SLOT(handleMessageContentUpdated(QString, QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messagesDeleted(QString, QVariantList)), this, SLOT(handleMessagesDeleted(QString, QVariantList))); connect(this->tdLibReceiver, SIGNAL(messagesDeleted(QString, QVariantList)), this, SLOT(handleMessagesDeleted(QString, QVariantList)));
connect(this->tdLibReceiver, SIGNAL(chats(QVariantMap)), this, SLOT(handleChats(QVariantMap)));
this->tdLibReceiver->start(); this->tdLibReceiver->start();
@ -107,6 +108,11 @@ TDLibWrapper::AuthorizationState TDLibWrapper::getAuthorizationState()
return this->authorizationState; return this->authorizationState;
} }
QVariantMap TDLibWrapper::getAuthorizationStateData()
{
return this->authorizationStateData;
}
TDLibWrapper::ConnectionState TDLibWrapper::getConnectionState() TDLibWrapper::ConnectionState TDLibWrapper::getConnectionState()
{ {
return this->connectionState; return this->connectionState;
@ -143,6 +149,16 @@ void TDLibWrapper::setAuthenticationPassword(const QString &authenticationPasswo
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::registerUser(const QString &firstName, const QString &lastName)
{
qDebug() << "[TDLibWrapper] Register User " << firstName << lastName;
QVariantMap requestObject;
requestObject.insert("@type", "registerUser");
requestObject.insert("first_name", firstName);
requestObject.insert("last_name", lastName);
this->sendRequest(requestObject);
}
void TDLibWrapper::getChats() void TDLibWrapper::getChats()
{ {
qDebug() << "[TDLibWrapper] Getting chats"; qDebug() << "[TDLibWrapper] Getting chats";
@ -487,7 +503,7 @@ void TDLibWrapper::handleVersionDetected(const QString &version)
emit versionDetected(version); emit versionDetected(version);
} }
void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationState) void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationState, const QVariantMap authorizationStateData)
{ {
if (authorizationState == "authorizationStateClosed") { if (authorizationState == "authorizationStateClosed") {
this->authorizationState = AuthorizationState::Closed; this->authorizationState = AuthorizationState::Closed;
@ -534,8 +550,8 @@ void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationS
this->setInitialParameters(); this->setInitialParameters();
this->authorizationState = AuthorizationState::WaitTdlibParameters; this->authorizationState = AuthorizationState::WaitTdlibParameters;
} }
this->authorizationStateData = authorizationStateData;
emit authorizationStateChanged(this->authorizationState); emit authorizationStateChanged(this->authorizationState, this->authorizationStateData);
} }
@ -709,6 +725,11 @@ void TDLibWrapper::handleMessagesDeleted(const QString &chatId, const QVariantLi
emit messagesDeleted(chatId, messageIds); emit messagesDeleted(chatId, messageIds);
} }
void TDLibWrapper::handleChats(const QVariantMap &chats)
{
emit this->chatsReceived(chats);
}
void TDLibWrapper::setInitialParameters() void TDLibWrapper::setInitialParameters()
{ {
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib"; qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";

View file

@ -63,6 +63,7 @@ public:
Q_INVOKABLE QString getVersion(); Q_INVOKABLE QString getVersion();
Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState(); Q_INVOKABLE TDLibWrapper::AuthorizationState getAuthorizationState();
Q_INVOKABLE QVariantMap getAuthorizationStateData();
Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState(); Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState();
Q_INVOKABLE QVariantMap getUserInformation(); Q_INVOKABLE QVariantMap getUserInformation();
Q_INVOKABLE QVariantMap getUserInformation(const QString &userId); Q_INVOKABLE QVariantMap getUserInformation(const QString &userId);
@ -84,6 +85,7 @@ public:
Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber); Q_INVOKABLE void setAuthenticationPhoneNumber(const QString &phoneNumber);
Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode);
Q_INVOKABLE void setAuthenticationPassword(const QString &authenticationPassword); Q_INVOKABLE void setAuthenticationPassword(const QString &authenticationPassword);
Q_INVOKABLE void registerUser(const QString &firstName, const QString &lastName);
Q_INVOKABLE void getChats(); Q_INVOKABLE void getChats();
Q_INVOKABLE void downloadFile(const QString &fileId); Q_INVOKABLE void downloadFile(const QString &fileId);
Q_INVOKABLE void openChat(const QString &chatId); Q_INVOKABLE void openChat(const QString &chatId);
@ -104,7 +106,7 @@ public:
signals: signals:
void versionDetected(const QString &version); void versionDetected(const QString &version);
void ownUserIdFound(const QString &ownUserId); void ownUserIdFound(const QString &ownUserId);
void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState); void authorizationStateChanged(const TDLibWrapper::AuthorizationState &authorizationState, const QVariantMap &authorizationStateData);
void optionUpdated(const QString &optionName, const QVariant &optionValue); void optionUpdated(const QString &optionName, const QVariant &optionValue);
void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState); void connectionStateChanged(const TDLibWrapper::ConnectionState &connectionState);
void fileUpdated(const int fileId, const QVariantMap &fileInformation); void fileUpdated(const int fileId, const QVariantMap &fileInformation);
@ -131,10 +133,11 @@ signals:
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings); void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings);
void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent); void messageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
void messagesDeleted(const QString &chatId, const QVariantList &messageIds); void messagesDeleted(const QString &chatId, const QVariantList &messageIds);
void chatsReceived(const QVariantMap &chats);
public slots: public slots:
void handleVersionDetected(const QString &version); void handleVersionDetected(const QString &version);
void handleAuthorizationStateChanged(const QString &authorizationState); void handleAuthorizationStateChanged(const QString &authorizationState, const QVariantMap authorizationStateData);
void handleOptionUpdated(const QString &optionName, const QVariant &optionValue); void handleOptionUpdated(const QString &optionName, const QVariant &optionValue);
void handleConnectionStateChanged(const QString &connectionState); void handleConnectionStateChanged(const QString &connectionState);
void handleUserUpdated(const QVariantMap &userInformation); void handleUserUpdated(const QVariantMap &userInformation);
@ -160,6 +163,7 @@ public slots:
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings); void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent); void handleMessageContentUpdated(const QString &chatId, const QString &messageId, const QVariantMap &newContent);
void handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds); void handleMessagesDeleted(const QString &chatId, const QVariantList &messageIds);
void handleChats(const QVariantMap &chats);
private: private:
void *tdLibClient; void *tdLibClient;
@ -167,6 +171,7 @@ private:
DBusInterface *dbusInterface; DBusInterface *dbusInterface;
QString version; QString version;
TDLibWrapper::AuthorizationState authorizationState; TDLibWrapper::AuthorizationState authorizationState;
QVariantMap authorizationStateData;
TDLibWrapper::ConnectionState connectionState; TDLibWrapper::ConnectionState connectionState;
QVariantMap options; QVariantMap options;
QVariantMap userInformation; QVariantMap userInformation;

View file

@ -402,6 +402,22 @@
<source>Please enter your password:</source> <source>Please enter your password:</source>
<translation>Bitte geben Sie Ihr Passwort ein:</translation> <translation>Bitte geben Sie Ihr Passwort ein:</translation>
</message> </message>
<message>
<source>Register User</source>
<translation>Registriere Benutzer</translation>
</message>
<message>
<source>Enter your First Name</source>
<translation>Bitte geben Sie ihren Vornamen ein</translation>
</message>
<message>
<source>Enter your Last Name</source>
<translation>Bitte geben Sie ihren Vornamen ein</translation>
</message>
<message>
<source>User Registration</source>
<translation>Benutzerregistrierung</translation>
</message>
</context> </context>
<context> <context>
<name>LocationPreview</name> <name>LocationPreview</name>
@ -467,6 +483,10 @@
<source>Settings</source> <source>Settings</source>
<translation>Einstellungen</translation> <translation>Einstellungen</translation>
</message> </message>
<message>
<source>You don&apos;t have any chats yet.</source>
<translation>Sie haben noch keine Chats.</translation>
</message>
</context> </context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>

View file

@ -402,6 +402,22 @@
<source>Please enter your password:</source> <source>Please enter your password:</source>
<translation>Por favor, introducir el código:</translation> <translation>Por favor, introducir el código:</translation>
</message> </message>
<message>
<source>Register User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your First Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your Last Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>User Registration</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>LocationPreview</name> <name>LocationPreview</name>
@ -467,6 +483,10 @@
<source>Settings</source> <source>Settings</source>
<translation>Ajustes</translation> <translation>Ajustes</translation>
</message> </message>
<message>
<source>You don&apos;t have any chats yet.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>

View file

@ -402,6 +402,22 @@
<source>Please enter your password:</source> <source>Please enter your password:</source>
<translation>Kérlek add meg a jelszavad:</translation> <translation>Kérlek add meg a jelszavad:</translation>
</message> </message>
<message>
<source>Register User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your First Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your Last Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>User Registration</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>LocationPreview</name> <name>LocationPreview</name>
@ -467,6 +483,10 @@
<source>Settings</source> <source>Settings</source>
<translation>Beállítások</translation> <translation>Beállítások</translation>
</message> </message>
<message>
<source>You don&apos;t have any chats yet.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>

View file

@ -402,6 +402,22 @@
<source>Please enter your password:</source> <source>Please enter your password:</source>
<translation>Wprowadź hasło:</translation> <translation>Wprowadź hasło:</translation>
</message> </message>
<message>
<source>Register User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your First Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your Last Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>User Registration</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>LocationPreview</name> <name>LocationPreview</name>
@ -467,6 +483,10 @@
<source>Settings</source> <source>Settings</source>
<translation>Ustawienia</translation> <translation>Ustawienia</translation>
</message> </message>
<message>
<source>You don&apos;t have any chats yet.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>

View file

@ -402,6 +402,22 @@
<source>Please enter your password:</source> <source>Please enter your password:</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Register User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your First Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your Last Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>User Registration</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>LocationPreview</name> <name>LocationPreview</name>
@ -467,6 +483,10 @@
<source>Settings</source> <source>Settings</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>You don&apos;t have any chats yet.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>

View file

@ -337,6 +337,22 @@
<source>sent a venue</source> <source>sent a venue</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Register User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your First Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter your Last Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>User Registration</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ImagePage</name> <name>ImagePage</name>
@ -467,6 +483,10 @@
<source>Settings</source> <source>Settings</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>You don&apos;t have any chats yet.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>