mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-02 23:45:44 +00:00
Handle chat link clicks.
This commit is contained in:
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "window/window_session_controller.h"
|
||||
|
||||
#include "api/api_text_entities.h"
|
||||
#include "boxes/add_contact_box.h"
|
||||
#include "boxes/peers/add_bot_to_chat_box.h"
|
||||
#include "boxes/peers/edit_peer_info_box.h"
|
||||
@@ -307,6 +308,13 @@ void SessionNavigation::showPeerByLink(const PeerByLinkInfo &info) {
|
||||
resolvePhone(info.phone, [=](not_null<PeerData*> peer) {
|
||||
showPeerByLinkResolved(peer, info);
|
||||
});
|
||||
} else if (!info.chatLinkSlug.isEmpty()) {
|
||||
resolveChatLink(info.chatLinkSlug, [=](
|
||||
not_null<PeerData*> peer,
|
||||
TextWithEntities draft) {
|
||||
Data::SetChatLinkDraft(peer, draft);
|
||||
showPeerByLinkResolved(peer, info);
|
||||
});
|
||||
} else if (const auto name = std::get_if<QString>(&info.usernameOrId)) {
|
||||
resolveUsername(*name, [=](not_null<PeerData*> peer) {
|
||||
if (info.startAutoSubmit) {
|
||||
@@ -352,6 +360,33 @@ void SessionNavigation::resolvePhone(
|
||||
}).send();
|
||||
}
|
||||
|
||||
void SessionNavigation::resolveChatLink(
|
||||
const QString &slug,
|
||||
Fn<void(not_null<PeerData*> peer, TextWithEntities draft)> done) {
|
||||
_api.request(base::take(_resolveRequestId)).cancel();
|
||||
_resolveRequestId = _api.request(MTPaccount_ResolveBusinessChatLink(
|
||||
MTP_string(slug)
|
||||
)).done([=](const MTPaccount_ResolvedBusinessChatLinks &result) {
|
||||
_resolveRequestId = 0;
|
||||
parentController()->hideLayer();
|
||||
const auto &data = result.data();
|
||||
_session->data().processUsers(data.vusers());
|
||||
_session->data().processChats(data.vchats());
|
||||
|
||||
using namespace Api;
|
||||
const auto peerId = peerFromMTP(data.vpeer());
|
||||
done(_session->data().peer(peerId), {
|
||||
qs(data.vmessage()),
|
||||
EntitiesFromMTP(_session, data.ventities().value_or_empty())
|
||||
});
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
_resolveRequestId = 0;
|
||||
if (error.code() == 400) {
|
||||
showToast(tr::lng_confirm_phone_link_invalid(tr::now));
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
void SessionNavigation::resolveUsername(
|
||||
const QString &username,
|
||||
Fn<void(not_null<PeerData*>)> done) {
|
||||
|
Reference in New Issue
Block a user