From 3dbf38a1faec26e5eaddb43ee4d79392e6006e27 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Fri, 20 Nov 2020 18:30:33 +0100 Subject: [PATCH] Start implementing 'New Chat' functionality --- harbour-fernschreiber.pro | 1 + qml/pages/NewChatPage.qml | 92 +++++++++++++++++++++ qml/pages/OverviewPage.qml | 7 +- src/tdlibwrapper.cpp | 36 +++++++- src/tdlibwrapper.h | 4 + translations/harbour-fernschreiber-de.ts | 15 ++++ translations/harbour-fernschreiber-en.ts | 15 ++++ translations/harbour-fernschreiber-es.ts | 15 ++++ translations/harbour-fernschreiber-fi.ts | 15 ++++ translations/harbour-fernschreiber-hu.ts | 15 ++++ translations/harbour-fernschreiber-it.ts | 15 ++++ translations/harbour-fernschreiber-pl.ts | 15 ++++ translations/harbour-fernschreiber-ru.ts | 15 ++++ translations/harbour-fernschreiber-sv.ts | 15 ++++ translations/harbour-fernschreiber-zh_CN.ts | 15 ++++ translations/harbour-fernschreiber.ts | 19 ++++- 16 files changed, 303 insertions(+), 6 deletions(-) create mode 100644 qml/pages/NewChatPage.qml diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 31887de..c1f6b12 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -70,6 +70,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \ qml/pages/ChatSelectionPage.qml \ qml/pages/CoverPage.qml \ qml/pages/InitializationPage.qml \ + qml/pages/NewChatPage.qml \ qml/pages/OverviewPage.qml \ qml/pages/AboutPage.qml \ qml/pages/PollCreationPage.qml \ diff --git a/qml/pages/NewChatPage.qml b/qml/pages/NewChatPage.qml new file mode 100644 index 0000000..288d5b6 --- /dev/null +++ b/qml/pages/NewChatPage.qml @@ -0,0 +1,92 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ +import QtQuick 2.6 +import Sailfish.Silica 1.0 +import "../components" +import "../js/twemoji.js" as Emoji +import "../js/functions.js" as Functions + +Page { + id: newChatPage + allowedOrientations: Orientation.All + + property var contacts; + property bool isLoading: true; + + SilicaFlickable { + id: newChatContainer + contentHeight: newChatPage.height + anchors.fill: parent + + Column { + id: newChatPageColumn + width: newChatPage.width + height: newChatPage.height + + PageHeader { + id: newChatPageHeader + title: qsTr("Your Contacts") + } + + SilicaListView { + id: contactsListView + model: newChatPage.contacts + clip: true + height: newChatPageColumn.height - newChatPageHeader.height + width: newChatPageColumn.width + opacity: newChatPage.isLoading ? 0 : 1 + Behavior on opacity { FadeAnimation {} } + + ViewPlaceholder { + y: Theme.paddingLarge + enabled: contactsListView.count === 0 + text: qsTr("You don't have any contacts.") + } + + delegate: PhotoTextsListItem { + pictureThumbnail { + photoData: (typeof modelData.profile_photo !== "undefined") ? modelData.profile_photo.small : "" + } + width: parent.width + + primaryText.text: Emoji.emojify(Functions.getUserName(modelData), primaryText.font.pixelSize, "../js/emoji/") + prologSecondaryText.text: "@" + ( modelData.username !== "" ? modelData.username : modelData.id ) +// secondaryText { +// horizontalAlignment: Text.AlignRight +// property string statusText: Functions.getChatMemberStatusText(model.status["@type"]) +// property string customText: model.status.custom_title ? Emoji.emojify(model.status.custom_title, secondaryText.font.pixelSize, "../js/emoji/") : "" +// text: (statusText !== "" && customText !== "") ? statusText + ", " + customText : statusText + customText +// } + tertiaryText { + maximumLineCount: 1 + text: Functions.getChatPartnerStatusText(modelData.status["@type"], modelData.status.was_online); + elide: Text.ElideRight + } + + onClicked: { + tdLibWrapper.createPrivateChat(user_id); + } + } + + VerticalScrollDecorator {} + } + } + + } +} diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index ee55c1f..8050f69 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -46,7 +46,7 @@ Page { onPleaseOpenMessage: { console.log("[OverviewPage] Opening chat from external call...") if (chatListCreated) { - pageStack.pop(overviewPage, PageStackAction.Immediate) + pageStack.pop(overviewPage, PageStackAction.Immediate); pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : tdLibWrapper.getChat(chatId) }, PageStackAction.Immediate) } } @@ -96,6 +96,7 @@ Page { tdLibWrapper.getChats(); tdLibWrapper.getRecentStickers(); tdLibWrapper.getInstalledStickerSets(); + tdLibWrapper.getContacts(); } function initializePage() { @@ -184,6 +185,10 @@ Page { text: qsTr("Settings") onClicked: pageStack.push(Qt.resolvedUrl("../pages/SettingsPage.qml")) } + MenuItem { + text: qsTr("New Chat") + onClicked: pageStack.push(Qt.resolvedUrl("../pages/NewChatPage.qml")) + } } AppNotification { diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 293dbfa..69cb54c 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -47,7 +47,7 @@ namespace { const QString _EXTRA("@extra"); } -TDLibWrapper::TDLibWrapper(AppSettings *appSettings, QObject *parent) : QObject(parent), joinChatRequested(false) +TDLibWrapper::TDLibWrapper(AppSettings *appSettings, QObject *parent) : QObject(parent), joinChatRequested(false), contactsRequested(false) { LOG("Initializing TD Lib..."); this->appSettings = appSettings; @@ -113,7 +113,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, QObject *parent) : QObject( connect(this->tdLibReceiver, SIGNAL(chatPhotoUpdated(qlonglong, QVariantMap)), this, SIGNAL(chatPhotoUpdated(qlonglong, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatTitleUpdated(QString, QString)), this, SIGNAL(chatTitleUpdated(QString, QString))); connect(this->tdLibReceiver, SIGNAL(chatPinnedMessageUpdated(qlonglong, qlonglong)), this, SIGNAL(chatPinnedMessageUpdated(qlonglong, qlonglong))); - connect(this->tdLibReceiver, SIGNAL(usersReceived(QString, QVariantList, int)), this, SIGNAL(usersReceived(QString, QVariantList, int))); + connect(this->tdLibReceiver, SIGNAL(usersReceived(QString, QVariantList, int)), this, SLOT(handleUsersReceived(QString, QVariantList, int))); connect(this->tdLibReceiver, SIGNAL(errorReceived(int, QString)), this, SIGNAL(errorReceived(int, QString))); connect(&emojiSearchWorker, SIGNAL(searchCompleted(QString, QVariantList)), this, SLOT(handleEmojiSearchCompleted(QString, QVariantList))); @@ -605,7 +605,7 @@ void TDLibWrapper::getGroupFullInfo(const QString &groupId, bool isSuperGroup) void TDLibWrapper::getUserFullInfo(const QString &userId) { - LOG("Retrieving UserFullInfo"); + LOG("Retrieving UserFullInfo" << userId); QVariantMap requestObject; requestObject.insert(_TYPE, "getUserFullInfo"); requestObject.insert(_EXTRA, userId); @@ -792,6 +792,15 @@ void TDLibWrapper::getDeepLinkInfo(const QString &link) this->sendRequest(requestObject); } +void TDLibWrapper::getContacts() +{ + LOG("Retrieving contacts"); + this->contactsRequested = true; + QVariantMap requestObject; + requestObject.insert(_TYPE, "getContacts"); + this->sendRequest(requestObject); +} + void TDLibWrapper::searchEmoji(const QString &queryString) { LOG("Searching emoji" << queryString); @@ -813,6 +822,11 @@ QVariantMap TDLibWrapper::getUserInformation(const QString &userId) return this->allUsers.value(userId).toMap(); } +bool TDLibWrapper::hasUserInformation(const QString &userId) +{ + return this->allUsers.contains(userId); +} + QVariantMap TDLibWrapper::getUserInformationByName(const QString &userName) { return this->allUserNames.value(userName).toMap(); @@ -1133,6 +1147,22 @@ void TDLibWrapper::handleOpenWithChanged() } } +void TDLibWrapper::handleUsersReceived(const QString &extra, const QVariantList &userIds, int totalUsers) +{ + if (this->contactsRequested) { + LOG("Received contacts list..."); + this->contactsRequested = false; + QListIterator userIdIterator(userIds); + while (userIdIterator.hasNext()) { + QString nextUserId = userIdIterator.next().toString(); + if (!this->hasUserInformation(nextUserId)) { + this->getUserFullInfo(nextUserId); + } + } + } + emit usersReceived(extra, userIds, totalUsers); +} + void TDLibWrapper::setInitialParameters() { LOG("Sending initial parameters to TD Lib"); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 0f02595..897ea65 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -93,6 +93,7 @@ public: Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState(); Q_INVOKABLE QVariantMap getUserInformation(); Q_INVOKABLE QVariantMap getUserInformation(const QString &userId); + Q_INVOKABLE bool hasUserInformation(const QString &userId); Q_INVOKABLE QVariantMap getUserInformationByName(const QString &userName); Q_INVOKABLE QVariantMap getUnreadMessageInformation(); Q_INVOKABLE QVariantMap getUnreadChatInformation(); @@ -160,6 +161,7 @@ public: Q_INVOKABLE void searchPublicChat(const QString &userName); Q_INVOKABLE void joinChatByInviteLink(const QString &inviteLink); Q_INVOKABLE void getDeepLinkInfo(const QString &link); + Q_INVOKABLE void getContacts(); // Others (candidates for extraction ;)) Q_INVOKABLE void searchEmoji(const QString &queryString); @@ -241,6 +243,7 @@ public slots: void handleStickerSets(const QVariantList &stickerSets); void handleEmojiSearchCompleted(const QString &queryString, const QVariantList &resultList); void handleOpenWithChanged(); + void handleUsersReceived(const QString &extra, const QVariantList &userIds, int totalUsers); private: void setInitialParameters(); @@ -270,6 +273,7 @@ private: QString activeChatSearchName; bool joinChatRequested; + bool contactsRequested; }; diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 6aae9f2..ccc7c22 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -890,6 +890,17 @@ Diese Nachricht wurde weitergeleitet. Ursprünglicher Autor: %1 + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -942,6 +953,10 @@ You don't have any chats yet. Sie haben noch keine Chats. + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index c5d0035..345c7dc 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -890,6 +890,17 @@ + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -942,6 +953,10 @@ You don't have any chats yet. You don't have any chats yet. + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index 3ecd8ae..2d506d9 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -880,6 +880,17 @@ Este mensaje fue reenviado. Autor original: %1 + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -931,6 +942,10 @@ You don't have any chats yet. No hay todavía ninguna charla. + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index 7fb55f6..859707e 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -891,6 +891,17 @@ + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -943,6 +954,10 @@ You don't have any chats yet. Sinulla ei ole vielä keskusteluja. + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index fce5b95..e2d74a5 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -880,6 +880,17 @@ + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -931,6 +942,10 @@ You don't have any chats yet. + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index c04d265..6fa01c0 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -890,6 +890,17 @@ + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -942,6 +953,10 @@ Loading chat list... Carica lista chat... + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index 0cf5934..b2a67fd 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -900,6 +900,17 @@ + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -953,6 +964,10 @@ You don't have any chats yet. Nie masz jeszcze żadnych czatów. + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 289d794..8683689 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -900,6 +900,17 @@ + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -953,6 +964,10 @@ You don't have any chats yet. Тут пока ничего нет + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index e558854..b3f2436 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -890,6 +890,17 @@ Detta meddelande är vidarebefordrat. Ursprunglig avsändare: %1 + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -942,6 +953,10 @@ You don't have any chats yet. Du har inga chattar än. + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 5ffa019..2480d2f 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -880,6 +880,17 @@ 此消息为转发消息,原作者: %1 + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -931,6 +942,10 @@ You don't have any chats yet. 你还没有任何对话。 + + New Chat + + PinnedMessageItem diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 073eadb..345c7dc 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -883,13 +883,24 @@ MessageOverlayFlickable You - + You This message was forwarded. Original author: %1 + + NewChatPage + + Your Contacts + + + + You don't have any contacts. + + + NotificationManager @@ -942,12 +953,16 @@ You don't have any chats yet. You don't have any chats yet. + + New Chat + + PinnedMessageItem You - + You Pinned Message