Start implementing 'New Chat' functionality

This commit is contained in:
Sebastian Wolf 2020-11-20 18:30:33 +01:00
parent 4c1f3f7dfc
commit 3dbf38a1fa
16 changed files with 303 additions and 6 deletions

View file

@ -70,6 +70,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/pages/ChatSelectionPage.qml \ qml/pages/ChatSelectionPage.qml \
qml/pages/CoverPage.qml \ qml/pages/CoverPage.qml \
qml/pages/InitializationPage.qml \ qml/pages/InitializationPage.qml \
qml/pages/NewChatPage.qml \
qml/pages/OverviewPage.qml \ qml/pages/OverviewPage.qml \
qml/pages/AboutPage.qml \ qml/pages/AboutPage.qml \
qml/pages/PollCreationPage.qml \ qml/pages/PollCreationPage.qml \

92
qml/pages/NewChatPage.qml Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 {}
}
}
}
}

View file

@ -46,7 +46,7 @@ Page {
onPleaseOpenMessage: { onPleaseOpenMessage: {
console.log("[OverviewPage] Opening chat from external call...") console.log("[OverviewPage] Opening chat from external call...")
if (chatListCreated) { 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) pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : tdLibWrapper.getChat(chatId) }, PageStackAction.Immediate)
} }
} }
@ -96,6 +96,7 @@ Page {
tdLibWrapper.getChats(); tdLibWrapper.getChats();
tdLibWrapper.getRecentStickers(); tdLibWrapper.getRecentStickers();
tdLibWrapper.getInstalledStickerSets(); tdLibWrapper.getInstalledStickerSets();
tdLibWrapper.getContacts();
} }
function initializePage() { function initializePage() {
@ -184,6 +185,10 @@ Page {
text: qsTr("Settings") text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("../pages/SettingsPage.qml")) onClicked: pageStack.push(Qt.resolvedUrl("../pages/SettingsPage.qml"))
} }
MenuItem {
text: qsTr("New Chat")
onClicked: pageStack.push(Qt.resolvedUrl("../pages/NewChatPage.qml"))
}
} }
AppNotification { AppNotification {

View file

@ -47,7 +47,7 @@ namespace {
const QString _EXTRA("@extra"); 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..."); LOG("Initializing TD Lib...");
this->appSettings = appSettings; 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(chatPhotoUpdated(qlonglong, QVariantMap)), this, SIGNAL(chatPhotoUpdated(qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(chatTitleUpdated(QString, QString)), this, SIGNAL(chatTitleUpdated(QString, QString))); 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(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(this->tdLibReceiver, SIGNAL(errorReceived(int, QString)), this, SIGNAL(errorReceived(int, QString)));
connect(&emojiSearchWorker, SIGNAL(searchCompleted(QString, QVariantList)), this, SLOT(handleEmojiSearchCompleted(QString, QVariantList))); 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) void TDLibWrapper::getUserFullInfo(const QString &userId)
{ {
LOG("Retrieving UserFullInfo"); LOG("Retrieving UserFullInfo" << userId);
QVariantMap requestObject; QVariantMap requestObject;
requestObject.insert(_TYPE, "getUserFullInfo"); requestObject.insert(_TYPE, "getUserFullInfo");
requestObject.insert(_EXTRA, userId); requestObject.insert(_EXTRA, userId);
@ -792,6 +792,15 @@ void TDLibWrapper::getDeepLinkInfo(const QString &link)
this->sendRequest(requestObject); 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) void TDLibWrapper::searchEmoji(const QString &queryString)
{ {
LOG("Searching emoji" << queryString); LOG("Searching emoji" << queryString);
@ -813,6 +822,11 @@ QVariantMap TDLibWrapper::getUserInformation(const QString &userId)
return this->allUsers.value(userId).toMap(); return this->allUsers.value(userId).toMap();
} }
bool TDLibWrapper::hasUserInformation(const QString &userId)
{
return this->allUsers.contains(userId);
}
QVariantMap TDLibWrapper::getUserInformationByName(const QString &userName) QVariantMap TDLibWrapper::getUserInformationByName(const QString &userName)
{ {
return this->allUserNames.value(userName).toMap(); 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<QVariant> 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() void TDLibWrapper::setInitialParameters()
{ {
LOG("Sending initial parameters to TD Lib"); LOG("Sending initial parameters to TD Lib");

View file

@ -93,6 +93,7 @@ public:
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);
Q_INVOKABLE bool hasUserInformation(const QString &userId);
Q_INVOKABLE QVariantMap getUserInformationByName(const QString &userName); Q_INVOKABLE QVariantMap getUserInformationByName(const QString &userName);
Q_INVOKABLE QVariantMap getUnreadMessageInformation(); Q_INVOKABLE QVariantMap getUnreadMessageInformation();
Q_INVOKABLE QVariantMap getUnreadChatInformation(); Q_INVOKABLE QVariantMap getUnreadChatInformation();
@ -160,6 +161,7 @@ public:
Q_INVOKABLE void searchPublicChat(const QString &userName); Q_INVOKABLE void searchPublicChat(const QString &userName);
Q_INVOKABLE void joinChatByInviteLink(const QString &inviteLink); Q_INVOKABLE void joinChatByInviteLink(const QString &inviteLink);
Q_INVOKABLE void getDeepLinkInfo(const QString &link); Q_INVOKABLE void getDeepLinkInfo(const QString &link);
Q_INVOKABLE void getContacts();
// Others (candidates for extraction ;)) // Others (candidates for extraction ;))
Q_INVOKABLE void searchEmoji(const QString &queryString); Q_INVOKABLE void searchEmoji(const QString &queryString);
@ -241,6 +243,7 @@ public slots:
void handleStickerSets(const QVariantList &stickerSets); void handleStickerSets(const QVariantList &stickerSets);
void handleEmojiSearchCompleted(const QString &queryString, const QVariantList &resultList); void handleEmojiSearchCompleted(const QString &queryString, const QVariantList &resultList);
void handleOpenWithChanged(); void handleOpenWithChanged();
void handleUsersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
private: private:
void setInitialParameters(); void setInitialParameters();
@ -270,6 +273,7 @@ private:
QString activeChatSearchName; QString activeChatSearchName;
bool joinChatRequested; bool joinChatRequested;
bool contactsRequested;
}; };

View file

@ -890,6 +890,17 @@
<translation>Diese Nachricht wurde weitergeleitet. Ursprünglicher Autor: %1</translation> <translation>Diese Nachricht wurde weitergeleitet. Ursprünglicher Autor: %1</translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -942,6 +953,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>Sie haben noch keine Chats.</translation> <translation>Sie haben noch keine Chats.</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -890,6 +890,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -942,6 +953,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>You don&apos;t have any chats yet.</translation> <translation>You don&apos;t have any chats yet.</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -880,6 +880,17 @@
<translation>Este mensaje fue reenviado. Autor original: %1</translation> <translation>Este mensaje fue reenviado. Autor original: %1</translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -931,6 +942,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>No hay todavía ninguna charla.</translation> <translation>No hay todavía ninguna charla.</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -891,6 +891,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -943,6 +954,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>Sinulla ei ole vielä keskusteluja.</translation> <translation>Sinulla ei ole vielä keskusteluja.</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -880,6 +880,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -931,6 +942,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -890,6 +890,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -942,6 +953,10 @@
<source>Loading chat list...</source> <source>Loading chat list...</source>
<translation>Carica lista chat...</translation> <translation>Carica lista chat...</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -900,6 +900,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -953,6 +964,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>Nie masz jeszcze żadnych czatów.</translation> <translation>Nie masz jeszcze żadnych czatów.</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -900,6 +900,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -953,6 +964,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>Тут пока ничего нет</translation> <translation>Тут пока ничего нет</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -890,6 +890,17 @@
<translation>Detta meddelande är vidarebefordrat. Ursprunglig avsändare: %1</translation> <translation>Detta meddelande är vidarebefordrat. Ursprunglig avsändare: %1</translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -942,6 +953,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>Du har inga chattar än.</translation> <translation>Du har inga chattar än.</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -880,6 +880,17 @@
<translation>: %1</translation> <translation>: %1</translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -931,6 +942,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -883,13 +883,24 @@
<name>MessageOverlayFlickable</name> <name>MessageOverlayFlickable</name>
<message> <message>
<source>You</source> <source>You</source>
<translation type="unfinished"></translation> <translation type="unfinished">You</translation>
</message> </message>
<message> <message>
<source>This message was forwarded. Original author: %1</source> <source>This message was forwarded. Original author: %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewChatPage</name>
<message>
<source>Your Contacts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You don&apos;t have any contacts.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>NotificationManager</name> <name>NotificationManager</name>
<message numerus="yes"> <message numerus="yes">
@ -942,12 +953,16 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation>You don&apos;t have any chats yet.</translation> <translation>You don&apos;t have any chats yet.</translation>
</message> </message>
<message>
<source>New Chat</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>
<message> <message>
<source>You</source> <source>You</source>
<translation type="unfinished"></translation> <translation type="unfinished">You</translation>
</message> </message>
<message> <message>
<source>Pinned Message</source> <source>Pinned Message</source>