Small UI fixes, error handling for joining chats

This commit is contained in:
Sebastian Wolf 2020-11-09 23:22:24 +01:00
parent b4ae9cf0f3
commit 5d3805759a
18 changed files with 125 additions and 13 deletions

View file

@ -312,8 +312,13 @@ function enhanceMessageText(formattedText) {
function handleLink(link) { function handleLink(link) {
var tMePrefix = tdLibWrapper.getOptionString("t_me_url"); var tMePrefix = tdLibWrapper.getOptionString("t_me_url");
if (link.indexOf("user://") === 0) { if (link.indexOf("user://") === 0) {
var userInformation = tdLibWrapper.getUserInformationByName(link.substring(8)); var userName = link.substring(8);
tdLibWrapper.createPrivateChat(userInformation.id); 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) { } else if (link.indexOf("userId://") === 0) {
tdLibWrapper.createPrivateChat(link.substring(9)); tdLibWrapper.createPrivateChat(link.substring(9));
} else if (link.indexOf("tg://") === 0) { } else if (link.indexOf("tg://") === 0) {

View file

@ -320,7 +320,7 @@ Page {
Connections { Connections {
target: chatListModel target: chatListModel
onChatJoined: { 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 { AppNotification {
id: chatPageNotification id: appNotification
} }
BackgroundItem { BackgroundItem {
@ -469,13 +469,6 @@ Page {
width: parent.width width: parent.width
maximumLineCount: 1 maximumLineCount: 1
horizontalAlignment: Text.AlignRight 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(/\<img [^>]+\/\>/g, "");
}
}
} }
Text { Text {
id: chatStatusText id: chatStatusText

View file

@ -159,6 +159,11 @@ Page {
pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : tdLibWrapper.getChat(chat.id) }); 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: { Component.onCompleted: {
@ -184,7 +189,7 @@ Page {
} }
AppNotification { AppNotification {
id: overviewPageNotification id: appNotification
} }
Column { Column {

View file

@ -405,7 +405,10 @@ void ChatListModel::addVisibleChat(ChatData *chat)
chatIndexMap.insert(chatList.at(i)->chatId, i); chatIndexMap.insert(chatList.at(i)->chatId, i);
} }
endInsertRows(); 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) void ChatListModel::updateChatVisibility(const TDLibWrapper::Group *group)

View file

@ -117,6 +117,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
handlers.insert("updateChatPermissions", &TDLibReceiver::processUpdateChatPermissions); handlers.insert("updateChatPermissions", &TDLibReceiver::processUpdateChatPermissions);
handlers.insert("updateChatTitle", &TDLibReceiver::processUpdateChatTitle); handlers.insert("updateChatTitle", &TDLibReceiver::processUpdateChatTitle);
handlers.insert("users", &TDLibReceiver::processUsers); handlers.insert("users", &TDLibReceiver::processUsers);
handlers.insert("error", &TDLibReceiver::processError);
} }
void TDLibReceiver::setActive(bool active) void TDLibReceiver::setActive(bool active)
@ -501,3 +502,9 @@ void TDLibReceiver::processUsers(const QVariantMap &receivedInformation)
LOG("Received Users"); LOG("Received Users");
emit usersReceived(receivedInformation.value(EXTRA).toString(), receivedInformation.value("user_ids").toList(), receivedInformation.value("total_count").toInt()); 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());
}

View file

@ -81,6 +81,7 @@ signals:
void chatPermissionsUpdated(const QString &chatId, const QVariantMap &chatPermissions); void chatPermissionsUpdated(const QString &chatId, const QVariantMap &chatPermissions);
void chatTitleUpdated(const QString &chatId, const QString &title); void chatTitleUpdated(const QString &chatId, const QString &title);
void usersReceived(const QString &extra, const QVariantList &userIds, int totalUsers); void usersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
void errorReceived(const int code, const QString &message);
private: private:
typedef void (TDLibReceiver::*Handler)(const QVariantMap &); typedef void (TDLibReceiver::*Handler)(const QVariantMap &);
@ -136,6 +137,7 @@ private:
void processUpdateChatPermissions(const QVariantMap &receivedInformation); void processUpdateChatPermissions(const QVariantMap &receivedInformation);
void processUpdateChatTitle(const QVariantMap &receivedInformation); void processUpdateChatTitle(const QVariantMap &receivedInformation);
void processUsers(const QVariantMap &receivedInformation); void processUsers(const QVariantMap &receivedInformation);
void processError(const QVariantMap &receivedInformation);
}; };
#endif // TDLIBRECEIVER_H #endif // TDLIBRECEIVER_H

View file

@ -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(chatPermissionsUpdated(QString, QVariantMap)), this, SIGNAL(chatPermissionsUpdated(QString, 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(usersReceived(QString, QVariantList, int)), this, SIGNAL(usersReceived(QString, QVariantList, int))); 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))); connect(&emojiSearchWorker, SIGNAL(searchCompleted(QString, QVariantList)), this, SLOT(handleEmojiSearchCompleted(QString, QVariantList)));
@ -250,6 +251,7 @@ void TDLibWrapper::joinChat(const QString &chatId)
QVariantMap requestObject; QVariantMap requestObject;
requestObject.insert(_TYPE, "joinChat"); requestObject.insert(_TYPE, "joinChat");
requestObject.insert("chat_id", chatId); requestObject.insert("chat_id", chatId);
this->joinChatRequested = true;
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
@ -741,6 +743,7 @@ void TDLibWrapper::joinChatByInviteLink(const QString &inviteLink)
QVariantMap requestObject; QVariantMap requestObject;
requestObject.insert(_TYPE, "joinChatByInviteLink"); requestObject.insert(_TYPE, "joinChatByInviteLink");
requestObject.insert("invite_link", inviteLink); requestObject.insert("invite_link", inviteLink);
this->joinChatRequested = true;
this->sendRequest(requestObject); 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() DBusAdaptor *TDLibWrapper::getDBusAdaptor()
{ {
return this->dbusInterface->getDBusAdaptor(); return this->dbusInterface->getDBusAdaptor();

View file

@ -103,6 +103,8 @@ public:
Q_INVOKABLE void copyFileToDownloads(const QString &filePath); Q_INVOKABLE void copyFileToDownloads(const QString &filePath);
Q_INVOKABLE void openFileOnDevice(const QString &filePath); Q_INVOKABLE void openFileOnDevice(const QString &filePath);
Q_INVOKABLE void controlScreenSaver(bool enabled); Q_INVOKABLE void controlScreenSaver(bool enabled);
Q_INVOKABLE bool getJoinChatRequested();
Q_INVOKABLE void registerJoinChat();
DBusAdaptor *getDBusAdaptor(); DBusAdaptor *getDBusAdaptor();
@ -215,6 +217,7 @@ signals:
void chatPermissionsUpdated(const QString &chatId, const QVariantMap &permissions); void chatPermissionsUpdated(const QString &chatId, const QVariantMap &permissions);
void chatTitleUpdated(const QString &chatId, const QString &title); void chatTitleUpdated(const QString &chatId, const QString &title);
void usersReceived(const QString &extra, const QVariantList &userIds, int totalUsers); void usersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
void errorReceived(const int code, const QString &message);
public slots: public slots:
void handleVersionDetected(const QString &version); void handleVersionDetected(const QString &version);
@ -261,6 +264,7 @@ private:
EmojiSearchWorker emojiSearchWorker; EmojiSearchWorker emojiSearchWorker;
QString activeChatSearchName; QString activeChatSearchName;
bool joinChatRequested;
}; };

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation>Sie sind bereits Mitglied dieses Chats.</translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1448,5 +1452,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation>hat ein selbstzerstörendes Bild gesendet, das abgelaufen ist</translation> <translation>hat ein selbstzerstörendes Bild gesendet, das abgelaufen ist</translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation>Konnte Benutzer %1 nicht finden</translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1442,5 +1446,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation>envió un vídeo autodestructivo que está caducado</translation> <translation>envió un vídeo autodestructivo que está caducado</translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -840,6 +840,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1449,5 +1453,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1442,5 +1446,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1448,5 +1452,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation>ha inviato un video effimero già scaduto</translation> <translation>ha inviato un video effimero già scaduto</translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,10 @@
<source>You don&apos;t have any chats yet.</source> <source>You don&apos;t have any chats yet.</source>
<translation type="unfinished">Nie masz jeszcze żadnych czatów.</translation> <translation type="unfinished">Nie masz jeszcze żadnych czatów.</translation>
</message> </message>
<message>
<source>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1454,5 +1458,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1454,5 +1458,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1448,5 +1452,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1442,5 +1446,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>

View file

@ -839,6 +839,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>You are already a member of this chat.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PollCreationPage</name> <name>PollCreationPage</name>
@ -1442,5 +1446,9 @@
<source>sent a self-destructing video that is expired</source> <source>sent a self-destructing video that is expired</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Unable to find user %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
</TS> </TS>