2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Allow sharing stories and copying a link.

This commit is contained in:
John Preston
2023-06-12 20:41:26 +04:00
parent 3ac7725111
commit a933168ef7
26 changed files with 587 additions and 152 deletions

View File

@@ -46,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_scheduled_messages.h"
#include "data/data_channel_admins.h"
#include "data/data_session.h"
#include "data/data_stories.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_user.h"
@@ -763,9 +764,7 @@ QString ApiWrap::exportDirectMessageLink(
channel->inputChannel,
MTP_int(item->id)
)).done([=](const MTPExportedMessageLink &result) {
const auto link = result.match([&](const auto &data) {
return qs(data.vlink());
});
const auto link = qs(result.data().vlink());
if (current != link) {
_unlikelyMessageLinks.emplace_or_assign(itemId, link);
}
@@ -773,6 +772,32 @@ QString ApiWrap::exportDirectMessageLink(
return current;
}
QString ApiWrap::exportDirectStoryLink(not_null<Data::Story*> story) {
const auto storyId = story->fullId();
const auto user = story->peer()->asUser();
Assert(user != nullptr);
const auto fallback = [&] {
const auto base = user->username();
const auto story = QString::number(storyId.story);
const auto query = base + "?story=" + story;
return session().createInternalLinkFull(query);
};
const auto i = _unlikelyStoryLinks.find(storyId);
const auto current = (i != end(_unlikelyStoryLinks))
? i->second
: fallback();
request(MTPstories_ExportStoryLink(
story->peer()->asUser()->inputUser,
MTP_int(story->id())
)).done([=](const MTPExportedStoryLink &result) {
const auto link = qs(result.data().vlink());
if (current != link) {
_unlikelyStoryLinks.emplace_or_assign(storyId, link);
}
}).send();
return current;
}
void ApiWrap::requestContacts() {
if (_session->data().contactsLoaded().current() || _contactsRequestId) {
return;