From 5d3805759a7b8964abba6ca9ec7f38c80bea5e61 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Mon, 9 Nov 2020 23:22:24 +0100 Subject: [PATCH] Small UI fixes, error handling for joining chats --- qml/js/functions.js | 9 +++++++-- qml/pages/ChatPage.qml | 11 ++--------- qml/pages/OverviewPage.qml | 7 ++++++- src/chatlistmodel.cpp | 5 ++++- src/tdlibreceiver.cpp | 7 +++++++ src/tdlibreceiver.h | 2 ++ src/tdlibwrapper.cpp | 13 +++++++++++++ src/tdlibwrapper.h | 4 ++++ translations/harbour-fernschreiber-de.ts | 8 ++++++++ translations/harbour-fernschreiber-es.ts | 8 ++++++++ translations/harbour-fernschreiber-fi.ts | 8 ++++++++ translations/harbour-fernschreiber-hu.ts | 8 ++++++++ translations/harbour-fernschreiber-it.ts | 8 ++++++++ translations/harbour-fernschreiber-pl.ts | 8 ++++++++ translations/harbour-fernschreiber-ru.ts | 8 ++++++++ translations/harbour-fernschreiber-sv.ts | 8 ++++++++ translations/harbour-fernschreiber-zh_CN.ts | 8 ++++++++ translations/harbour-fernschreiber.ts | 8 ++++++++ 18 files changed, 125 insertions(+), 13 deletions(-) diff --git a/qml/js/functions.js b/qml/js/functions.js index 77bebd6..c2ce688 100644 --- a/qml/js/functions.js +++ b/qml/js/functions.js @@ -312,8 +312,13 @@ function enhanceMessageText(formattedText) { function handleLink(link) { var tMePrefix = tdLibWrapper.getOptionString("t_me_url"); if (link.indexOf("user://") === 0) { - var userInformation = tdLibWrapper.getUserInformationByName(link.substring(8)); - tdLibWrapper.createPrivateChat(userInformation.id); + var userName = link.substring(8); + var userInformation = tdLibWrapper.getUserInformationByName(userName); + if (typeof userInformation.id === "undefined") { + appNotification.show(qsTr("Unable to find user %1").arg(userName)); + } else { + tdLibWrapper.createPrivateChat(userInformation.id); + } } else if (link.indexOf("userId://") === 0) { tdLibWrapper.createPrivateChat(link.substring(9)); } else if (link.indexOf("tg://") === 0) { diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index deb8145..174ec2b 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -320,7 +320,7 @@ Page { Connections { target: chatListModel onChatJoined: { - chatPageNotification.show(qsTr("You joined the chat %1").arg(chatTitle)); + appNotification.show(qsTr("You joined the chat %1").arg(chatTitle)); } } @@ -419,7 +419,7 @@ Page { } AppNotification { - id: chatPageNotification + id: appNotification } BackgroundItem { @@ -469,13 +469,6 @@ Page { width: parent.width maximumLineCount: 1 horizontalAlignment: Text.AlignRight - onTruncatedChanged: { - // There is obviously a bug in QML in truncating text with images. - // We simply remove Emojis then... - if (truncated) { - text = text.replace(/\]+\/\>/g, ""); - } - } } Text { id: chatStatusText diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index 4bfeab8..b47d0f8 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -159,6 +159,11 @@ Page { pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : tdLibWrapper.getChat(chat.id) }); } } + onErrorReceived: { + if (message === "USER_ALREADY_PARTICIPANT") { + appNotification.show(qsTr("You are already a member of this chat.")); + } + } } Component.onCompleted: { @@ -184,7 +189,7 @@ Page { } AppNotification { - id: overviewPageNotification + id: appNotification } Column { diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index 99ba7d6..c9fe08d 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -405,7 +405,10 @@ void ChatListModel::addVisibleChat(ChatData *chat) chatIndexMap.insert(chatList.at(i)->chatId, i); } endInsertRows(); - emit chatJoined(chat->chatId, chat->chatData.value("title").toString()); + if (this->tdLibWrapper->getJoinChatRequested()) { + this->tdLibWrapper->registerJoinChat(); + emit chatJoined(chat->chatId, chat->chatData.value("title").toString()); + } } void ChatListModel::updateChatVisibility(const TDLibWrapper::Group *group) diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index 383108a..dd0fb6e 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -117,6 +117,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren handlers.insert("updateChatPermissions", &TDLibReceiver::processUpdateChatPermissions); handlers.insert("updateChatTitle", &TDLibReceiver::processUpdateChatTitle); handlers.insert("users", &TDLibReceiver::processUsers); + handlers.insert("error", &TDLibReceiver::processError); } void TDLibReceiver::setActive(bool active) @@ -501,3 +502,9 @@ void TDLibReceiver::processUsers(const QVariantMap &receivedInformation) LOG("Received Users"); emit usersReceived(receivedInformation.value(EXTRA).toString(), receivedInformation.value("user_ids").toList(), receivedInformation.value("total_count").toInt()); } + +void TDLibReceiver::processError(const QVariantMap &receivedInformation) +{ + LOG("Received an error"); + emit errorReceived(receivedInformation.value("code").toInt(), receivedInformation.value("message").toString()); +} diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index 36f4fc5..9225970 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -81,6 +81,7 @@ signals: void chatPermissionsUpdated(const QString &chatId, const QVariantMap &chatPermissions); void chatTitleUpdated(const QString &chatId, const QString &title); void usersReceived(const QString &extra, const QVariantList &userIds, int totalUsers); + void errorReceived(const int code, const QString &message); private: typedef void (TDLibReceiver::*Handler)(const QVariantMap &); @@ -136,6 +137,7 @@ private: void processUpdateChatPermissions(const QVariantMap &receivedInformation); void processUpdateChatTitle(const QVariantMap &receivedInformation); void processUsers(const QVariantMap &receivedInformation); + void processError(const QVariantMap &receivedInformation); }; #endif // TDLIBRECEIVER_H diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index f1445ef..cdf3b9c 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -112,6 +112,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, QObject *parent) : QObject( connect(this->tdLibReceiver, SIGNAL(chatPermissionsUpdated(QString, QVariantMap)), this, SIGNAL(chatPermissionsUpdated(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatTitleUpdated(QString, QString)), this, SIGNAL(chatTitleUpdated(QString, QString))); connect(this->tdLibReceiver, SIGNAL(usersReceived(QString, QVariantList, int)), this, SIGNAL(usersReceived(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))); @@ -250,6 +251,7 @@ void TDLibWrapper::joinChat(const QString &chatId) QVariantMap requestObject; requestObject.insert(_TYPE, "joinChat"); requestObject.insert("chat_id", chatId); + this->joinChatRequested = true; this->sendRequest(requestObject); } @@ -741,6 +743,7 @@ void TDLibWrapper::joinChatByInviteLink(const QString &inviteLink) QVariantMap requestObject; requestObject.insert(_TYPE, "joinChatByInviteLink"); requestObject.insert("invite_link", inviteLink); + this->joinChatRequested = true; this->sendRequest(requestObject); } @@ -872,6 +875,16 @@ void TDLibWrapper::controlScreenSaver(bool enabled) } } +bool TDLibWrapper::getJoinChatRequested() +{ + return this->joinChatRequested; +} + +void TDLibWrapper::registerJoinChat() +{ + this->joinChatRequested = false; +} + DBusAdaptor *TDLibWrapper::getDBusAdaptor() { return this->dbusInterface->getDBusAdaptor(); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 20f34d1..a03e837 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -103,6 +103,8 @@ public: Q_INVOKABLE void copyFileToDownloads(const QString &filePath); Q_INVOKABLE void openFileOnDevice(const QString &filePath); Q_INVOKABLE void controlScreenSaver(bool enabled); + Q_INVOKABLE bool getJoinChatRequested(); + Q_INVOKABLE void registerJoinChat(); DBusAdaptor *getDBusAdaptor(); @@ -215,6 +217,7 @@ signals: void chatPermissionsUpdated(const QString &chatId, const QVariantMap &permissions); void chatTitleUpdated(const QString &chatId, const QString &title); void usersReceived(const QString &extra, const QVariantList &userIds, int totalUsers); + void errorReceived(const int code, const QString &message); public slots: void handleVersionDetected(const QString &version); @@ -261,6 +264,7 @@ private: EmojiSearchWorker emojiSearchWorker; QString activeChatSearchName; + bool joinChatRequested; }; diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 0afb9f2..0ddabe3 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -839,6 +839,10 @@ You don't have any chats yet. Sie haben noch keine Chats. + + You are already a member of this chat. + Sie sind bereits Mitglied dieses Chats. + PollCreationPage @@ -1448,5 +1452,9 @@ sent a self-destructing video that is expired hat ein selbstzerstörendes Bild gesendet, das abgelaufen ist + + Unable to find user %1 + Konnte Benutzer %1 nicht finden + diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index e824740..52b6271 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -839,6 +839,10 @@ You don't have any chats yet. No hay todavía ninguna charla. + + You are already a member of this chat. + + PollCreationPage @@ -1442,5 +1446,9 @@ sent a self-destructing video that is expired envió un vídeo autodestructivo que está caducado + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index e04bb8e..6db1b2a 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -840,6 +840,10 @@ You don't have any chats yet. Sinulla ei ole vielä keskusteluja. + + You are already a member of this chat. + + PollCreationPage @@ -1449,5 +1453,9 @@ sent a self-destructing video that is expired + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index d0dc370..24595d1 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -839,6 +839,10 @@ You don't have any chats yet. + + You are already a member of this chat. + + PollCreationPage @@ -1442,5 +1446,9 @@ sent a self-destructing video that is expired + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index 3c922cb..2702d15 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -839,6 +839,10 @@ Loading chat list... Carica lista chat... + + You are already a member of this chat. + + PollCreationPage @@ -1448,5 +1452,9 @@ sent a self-destructing video that is expired ha inviato un video effimero già scaduto + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index b4dba21..3461f14 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -839,6 +839,10 @@ You don't have any chats yet. Nie masz jeszcze żadnych czatów. + + You are already a member of this chat. + + PollCreationPage @@ -1454,5 +1458,9 @@ sent a self-destructing video that is expired + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index f3a170b..fde9eef 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -839,6 +839,10 @@ You don't have any chats yet. Тут пока ничего нет + + You are already a member of this chat. + + PollCreationPage @@ -1454,5 +1458,9 @@ sent a self-destructing video that is expired + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index f6cce56..849fbad 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -839,6 +839,10 @@ You don't have any chats yet. Du har inga chattar än. + + You are already a member of this chat. + + PollCreationPage @@ -1448,5 +1452,9 @@ sent a self-destructing video that is expired + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 5e61dd4..a9c31a9 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -839,6 +839,10 @@ You don't have any chats yet. 你尚无任何对话。 + + You are already a member of this chat. + + PollCreationPage @@ -1442,5 +1446,9 @@ sent a self-destructing video that is expired + + Unable to find user %1 + + diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 7abeed8..3b529ef 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -839,6 +839,10 @@ You don't have any chats yet. + + You are already a member of this chat. + + PollCreationPage @@ -1442,5 +1446,9 @@ sent a self-destructing video that is expired + + Unable to find user %1 + +