From bbd8e3eabf16bdd979dd2b690461573a7ec6a6d4 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Tue, 3 Nov 2020 22:21:01 +0100 Subject: [PATCH] Start chat from @-mention --- qml/js/functions.js | 9 +++++---- src/tdlibwrapper.cpp | 7 +++++++ src/tdlibwrapper.h | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/qml/js/functions.js b/qml/js/functions.js index 27d48f1..aca44c6 100644 --- a/qml/js/functions.js +++ b/qml/js/functions.js @@ -224,7 +224,7 @@ function enhanceMessageText(formattedText) { messageInsertions.push(new MessageInsertion((formattedText.entities[i].offset + formattedText.entities[i].length), "", 0 )); } if (entityType === "textEntityTypeMention") { - messageInsertions.push(new MessageInsertion(formattedText.entities[i].offset, "", 0 )); + messageInsertions.push(new MessageInsertion(formattedText.entities[i].offset, "", 0 )); messageInsertions.push(new MessageInsertion((formattedText.entities[i].offset + formattedText.entities[i].length), "", 0 )); } if (entityType === "textEntityTypeMentionName") { @@ -277,9 +277,10 @@ function enhanceMessageText(formattedText) { function handleLink(link) { if (link.indexOf("user://") === 0) { - //pageStack.push(Qt.resolvedUrl("../pages/UserPage.qml"), {"userName": link.substring(7)}); - } else if (link.indexOf("userid://") === 0) { - //pageStack.push(Qt.resolvedUrl("../pages/UserPage.qml"), {"userId": link.substring(9)}); + var userInformation = tdLibWrapper.getUserInformationByName(link.substring(8)); + tdLibWrapper.createPrivateChat(userInformation.id); + } else if (link.indexOf("userId://") === 0) { + tdLibWrapper.createPrivateChat(link.substring(9)); } else { Qt.openUrlExternally(link); } diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index aa0b0f5..d96026d 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -708,6 +708,11 @@ QVariantMap TDLibWrapper::getUserInformation(const QString &userId) return this->allUsers.value(userId).toMap(); } +QVariantMap TDLibWrapper::getUserInformationByName(const QString &userName) +{ + return this->allUserNames.value(userName).toMap(); +} + QVariantMap TDLibWrapper::getUnreadMessageInformation() { return this->unreadMessageInformation; @@ -898,6 +903,7 @@ void TDLibWrapper::handleUserUpdated(const QVariantMap &userInformation) } LOG("User information updated:" << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString()); this->allUsers.insert(updatedUserId, userInformation); + this->allUserNames.insert(userInformation.value("username").toString(), userInformation); emit userUpdated(updatedUserId, userInformation); } @@ -911,6 +917,7 @@ void TDLibWrapper::handleUserStatusUpdated(const QString &userId, const QVariant QVariantMap updatedUserInformation = this->allUsers.value(userId).toMap(); updatedUserInformation.insert("status", userStatusInformation); this->allUsers.insert(userId, updatedUserInformation); + this->allUserNames.insert(userInformation.value("username").toString(), userInformation); emit userUpdated(userId, updatedUserInformation); } diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 3cb91f2..5b9502a 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -92,6 +92,7 @@ public: Q_INVOKABLE TDLibWrapper::ConnectionState getConnectionState(); Q_INVOKABLE QVariantMap getUserInformation(); Q_INVOKABLE QVariantMap getUserInformation(const QString &userId); + Q_INVOKABLE QVariantMap getUserInformationByName(const QString &userName); Q_INVOKABLE QVariantMap getUnreadMessageInformation(); Q_INVOKABLE QVariantMap getUnreadChatInformation(); Q_INVOKABLE QVariantMap getBasicGroup(qlonglong groupId) const; @@ -239,6 +240,7 @@ private: QVariantMap options; QVariantMap userInformation; QVariantMap allUsers; + QVariantMap allUserNames; QVariantMap chats; QVariantMap unreadMessageInformation; QVariantMap unreadChatInformation;