Handle many direct message links properly, fixes #312

This commit is contained in:
Sebastian Wolf 2021-12-11 18:29:31 +01:00
parent 37518d06a6
commit b8e5fb189c
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
21 changed files with 141 additions and 19 deletions

View file

@ -70,7 +70,6 @@ Column {
}
if (advertisesBot) {
tdLibWrapper.createPrivateChat(tdLibWrapper.getUserInformationByName(sponsoredMessageData.link.bot_username).id, "openAndSendStartToBot:" + sponsoredMessageData.link.start_parameter);
//tdLibWrapper.sendBotStartMessage(tdLibWrapper.getUserInformationByName(sponsoredMessageData.link.bot_username).id, sponsoredMessageData.sponsor_chat_id, sponsoredMessageData.link.start_parameter, "");
}
}
}

View file

@ -393,6 +393,19 @@ function handleTMeLink(link, usedPrefix) {
function handleLink(link) {
var tMePrefix = tdLibWrapper.getOptionString("t_me_url");
var tMePrefixHttp = tMePrefix.replace('https', 'http');
// Checking if we have a direct message link...
Debug.log("URL open requested: " + link);
if ( (link.indexOf(tMePrefix) === 0 && link.substring(tMePrefix.length).indexOf("/") > 0) ||
(link.indexOf(tMePrefixHttp) === 0 && link.substring(tMePrefixHttp.length).indexOf("/") > 0) ||
link.indexOf("tg://privatepost") === 0 ||
link.indexOf("tg://resolve") === 0 ) {
Debug.log("Using message link info for: " + link);
tdLibWrapper.getMessageLinkInfo(link, "openDirectly");
return;
}
Debug.log("Trying to parse link ourselves: " + link);
if (link.indexOf("user://") === 0) {
var userName = link.substring(8);
var userInformation = tdLibWrapper.getUserInformationByName(userName);

View file

@ -52,6 +52,8 @@ Page {
property int chatOnlineMemberCount: 0;
property var emojiProposals;
property bool iterativeInitialization: false;
property var messageToShow;
property string messageIdToShow;
readonly property bool userIsMember: ((isPrivateChat || isSecretChat) && chatInformation["@type"]) || // should be optimized
(isBasicGroup || isSuperGroup) && (
(chatGroupInformation.status["@type"] === "chatMemberStatusMember")
@ -530,6 +532,11 @@ Page {
if (chatInformation.draft_message && messageId === chatInformation.draft_message.reply_to_message_id) {
newMessageInReplyToRow.inReplyToMessage = message;
}
Debug.log("Received message ID: " + messageId + ", message ID to show: " + chatPage.messageIdToShow)
if (chatPage.messageIdToShow && chatPage.messageIdToShow === String(messageId)) {
messageOverlayLoader.overlayMessage = message;
messageOverlayLoader.active = true;
}
}
onSecretChatReceived: {
if (secretChatId === chatInformation.type.secret_chat_id) {
@ -1115,6 +1122,13 @@ Page {
if (chatPage.isChannel) {
tdLibWrapper.getChatSponsoredMessages(chatInformation.id);
}
if (typeof chatPage.messageToShow !== "undefined" && chatPage.messageToShow !== {}) {
messageOverlayLoader.overlayMessage = chatPage.messageToShow;
messageOverlayLoader.active = true;
}
if (typeof chatPage.messageIdToShow !== "undefined") {
tdLibWrapper.getMessage(chatPage.chatInformation.id, chatPage.messageIdToShow);
}
}
}
}

View file

@ -49,8 +49,10 @@ Page {
Connections {
target: dBusAdaptor
onPleaseOpenMessage: {
Debug.log("[OverviewPage] Opening chat from external requested: ", chatId);
openMessage(chatId, messageId);
Debug.log("[OverviewPage] Opening chat from external requested: ", chatId, messageId);
// We open the chat only for now - as it's automatically positioned at the last read message
// it's probably better as if the message itself is displayed in the overlay
openChat(chatId);
}
onPleaseOpenUrl: {
Debug.log("[OverviewPage] Opening URL requested: ", url);
@ -74,8 +76,6 @@ Page {
titleInteractionHint.opacity = 1.0;
appSettings.remainingInteractionHints = remainingInteractionHints - 1;
}
openUrl();
openMessage();
}
}
@ -110,14 +110,35 @@ Page {
filterText: chatSearchField.text
}
function openMessage(chatId, messageId) {
function openChat(chatId) {
if(chatListCreated && chatId) {
Debug.log("[OverviewPage] Opening Chat: ", chatId);
pageStack.pop(overviewPage, PageStackAction.Immediate);
pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : tdLibWrapper.getChat(chatId) }, PageStackAction.Immediate);
chatToOpen = null;
}
}
function openChatWithMessageId(chatId, messageId) {
if(chatId && messageId) {
chatToOpen = [chatId, messageId];
}
if(chatListCreated && chatToOpen && chatToOpen.length === 2) { // messageId not handled (yet)
Debug.log("[OverviewPage] Opening Chat: ", chatToOpen[0]);
if(chatListCreated && chatToOpen && chatToOpen.length === 2) {
Debug.log("[OverviewPage] Opening Chat: ", chatToOpen[0], "message ID: " + chatToOpen[1]);
pageStack.pop(overviewPage, PageStackAction.Immediate);
pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : chatListModel.getById(chatToOpen[0]) }, PageStackAction.Immediate);
pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : tdLibWrapper.getChat(chatToOpen[0]), "messageIdToShow" : chatToOpen[1] }, PageStackAction.Immediate);
chatToOpen = null;
}
}
function openChatWithMessage(chatId, message) {
if(chatId && message) {
chatToOpen = [chatId, message];
}
if(chatListCreated && chatToOpen && chatToOpen.length === 2) {
Debug.log("[OverviewPage] Opening Chat (with provided message): ", chatToOpen[0]);
pageStack.pop(overviewPage, PageStackAction.Immediate);
pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : tdLibWrapper.getChat(chatToOpen[0]), "messageToShow" : chatToOpen[1] }, PageStackAction.Immediate);
chatToOpen = null;
}
}
@ -272,6 +293,15 @@ Page {
onCopyToDownloadsError: {
appNotification.show(qsTr("Download failed."));
}
onMessageLinkInfoReceived: {
if (extra === "openDirectly") {
if (messageLinkInfo.chat_id === 0) {
appNotification.show(qsTr("Unable to open link."));
} else {
openChatWithMessage(messageLinkInfo.chat_id, messageLinkInfo.message);
}
}
}
}
Component.onCompleted: {

View file

@ -383,9 +383,18 @@ void TDLibReceiver::processMessage(const QVariantMap &receivedInformation)
void TDLibReceiver::processMessageLinkInfo(const QVariantMap &receivedInformation)
{
const QString url = receivedInformation.value(EXTRA).toString();
LOG("Received message link info " << url);
emit messageLinkInfoReceived(url, receivedInformation);
const QString oldExtra = receivedInformation.value(EXTRA).toString();
QString url = "";
QString extra = "";
LOG("Received message link info " << oldExtra);
if (oldExtra.contains("|")) {
const int midIndex = oldExtra.indexOf("|");
url = oldExtra.left(midIndex);
extra = oldExtra.mid(midIndex + 1);
} else {
url = oldExtra;
}
emit messageLinkInfoReceived(url, receivedInformation, extra);
}
void TDLibReceiver::processMessageSendSucceeded(const QVariantMap &receivedInformation)

View file

@ -56,7 +56,7 @@ signals:
void superGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation);
void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount);
void messagesReceived(const QVariantList &messages, int totalCount);
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo);
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo, const QString &extra);
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
void newMessageReceived(qlonglong chatId, const QVariantMap &message);
void messageInformation(qlonglong chatId, qlonglong messageId, const QVariantMap &message);

View file

@ -119,7 +119,7 @@ void TDLibWrapper::initializeTDLibReciever() {
connect(this->tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString, int)), this, SIGNAL(chatOnlineMemberCountUpdated(QString, int)));
connect(this->tdLibReceiver, SIGNAL(messagesReceived(QVariantList, int)), this, SIGNAL(messagesReceived(QVariantList, int)));
connect(this->tdLibReceiver, SIGNAL(sponsoredMessagesReceived(qlonglong, QVariantList)), this, SLOT(handleSponsoredMess(qlonglong, QVariantList)));
connect(this->tdLibReceiver, SIGNAL(messageLinkInfoReceived(QString, QVariantMap)), this, SIGNAL(messageLinkInfoReceived(QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageLinkInfoReceived(QString, QVariantMap, QString)), this, SIGNAL(messageLinkInfoReceived(QString, QVariantMap, QString)));
connect(this->tdLibReceiver, SIGNAL(newMessageReceived(qlonglong, QVariantMap)), this, SIGNAL(newMessageReceived(qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageInformation(qlonglong, qlonglong, QVariantMap)), this, SLOT(handleMessageInformation(qlonglong, qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageSendSucceeded(qlonglong, qlonglong, QVariantMap)), this, SIGNAL(messageSendSucceeded(qlonglong, qlonglong, QVariantMap)));
@ -656,13 +656,18 @@ void TDLibWrapper::getMessage(qlonglong chatId, qlonglong messageId)
this->sendRequest(requestObject);
}
void TDLibWrapper::getMessageLinkInfo(const QString &url)
void TDLibWrapper::getMessageLinkInfo(const QString &url, const QString &extra)
{
LOG("Retrieving message link info" << url);
LOG("Retrieving message link info" << url << extra);
QVariantMap requestObject;
requestObject.insert(_TYPE, "getMessageLinkInfo");
requestObject.insert("url", url);
if (extra == "") {
requestObject.insert(_EXTRA, url);
} else {
requestObject.insert(_EXTRA, url + "|" + extra);
}
this->sendRequest(requestObject);
}

View file

@ -172,7 +172,7 @@ public:
Q_INVOKABLE void sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &explanation, const QString &replyToMessageId = "0");
Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, bool sendCopy, bool removeCaption);
Q_INVOKABLE void getMessage(qlonglong chatId, qlonglong messageId);
Q_INVOKABLE void getMessageLinkInfo(const QString &url);
Q_INVOKABLE void getMessageLinkInfo(const QString &url, const QString &extra = "");
Q_INVOKABLE void getCallbackQueryAnswer(const QString &chatId, const QString &messageId, const QVariantMap &payload);
Q_INVOKABLE void getChatPinnedMessage(qlonglong chatId);
Q_INVOKABLE void getChatSponsoredMessages(qlonglong chatId);
@ -265,7 +265,7 @@ signals:
void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount);
void messagesReceived(const QVariantList &messages, int totalCount);
void sponsoredMessagesReceived(qlonglong chatId, const QVariantList &messages);
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo);
void messageLinkInfoReceived(const QString &url, const QVariantMap &messageLinkInfo, const QString &extra);
void newMessageReceived(qlonglong chatId, const QVariantMap &message);
void copyToDownloadsSuccessful(const QString &fileName, const QString &filePath);
void copyToDownloadsError(const QString &fileName, const QString &filePath);

View file

@ -1304,6 +1304,10 @@
<source>Logging out</source>
<translation>Abmelden</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation>Kann Link nicht öffnen.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1306,6 +1306,10 @@ messages</numerusform>
<source>Logging out</source>
<translation>Logging out</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation>Unable to open link.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1304,6 +1304,10 @@
<source>Logging out</source>
<translation>Saliendo de la cuenta</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1305,6 +1305,10 @@
<source>Logging out</source>
<translation>Kirjaudutaan ulos</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1304,6 +1304,10 @@
<source>Logging out</source>
<translation>Se déconnecte</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1285,6 +1285,10 @@
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1304,6 +1304,10 @@
<source>Logging out</source>
<translation>Disconnetto</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1323,6 +1323,10 @@
<source>Logging out</source>
<translation>Wylogowywanie</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1326,6 +1326,10 @@
<source>Logging out</source>
<translation>Завершение сеанса</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1323,6 +1323,10 @@
<source>Logging out</source>
<translation>Odhlasovanie</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1304,6 +1304,10 @@
<source>Logging out</source>
<translation>Loggar ut</translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1286,6 +1286,10 @@
<source>Logging out</source>
<translation></translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>

View file

@ -1304,6 +1304,10 @@
<source>Logging out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to open link.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>