mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Added support of link to specific option in poll.
This commit is contained in:
@@ -4988,6 +4988,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_context_reply_to_task" = "Reply to Task";
|
||||
"lng_context_reply_to_poll_option" = "Reply to Option";
|
||||
"lng_context_copy_poll_option" = "Copy Option";
|
||||
"lng_context_copy_poll_option_link" = "Copy Option Link";
|
||||
"lng_context_delete_poll_option" = "Delete Item";
|
||||
"lng_context_poll_message_tab" = "Poll";
|
||||
"lng_context_poll_option_tab" = "Option";
|
||||
|
||||
@@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_birthday.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_poll.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
@@ -615,6 +616,8 @@ bool ResolveUsernameOrPhone(
|
||||
const auto threadId = topicId ? topicId : threadParam.toInt();
|
||||
const auto gameParam = params.value(u"game"_q);
|
||||
const auto videot = params.value(u"t"_q);
|
||||
const auto pollOption = PollOptionFromLink(
|
||||
params.value(u"option"_q));
|
||||
if (params.contains(u"direct"_q)) {
|
||||
resolveType = ResolveType::ChannelDirect;
|
||||
}
|
||||
@@ -633,6 +636,7 @@ bool ResolveUsernameOrPhone(
|
||||
.usernameOrId = domain,
|
||||
.phone = phone,
|
||||
.messageId = post,
|
||||
.pollOption = pollOption,
|
||||
.storyParam = storyParam,
|
||||
.storyAlbumId = storyAlbumId,
|
||||
.giftCollectionId = giftCollectionId,
|
||||
@@ -704,6 +708,8 @@ bool ResolvePrivatePost(
|
||||
const auto topicId = topicParam.toInt();
|
||||
const auto threadParam = params.value(u"thread"_q);
|
||||
const auto threadId = topicId ? topicId : threadParam.toInt();
|
||||
const auto pollOption = PollOptionFromLink(
|
||||
params.value(u"option"_q));
|
||||
if (!channelId || (msgId && !IsServerMsgId(msgId))) {
|
||||
return false;
|
||||
}
|
||||
@@ -711,6 +717,7 @@ bool ResolvePrivatePost(
|
||||
controller->showPeerByLink(Window::PeerByLinkInfo{
|
||||
.usernameOrId = channelId,
|
||||
.messageId = msgId,
|
||||
.pollOption = pollOption,
|
||||
.repliesInfo = commentId
|
||||
? Window::RepliesByLinkInfo{
|
||||
Window::CommentId{ commentId }
|
||||
|
||||
@@ -491,6 +491,15 @@ PollMedia PollMediaFromInputMTP(
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray PollOptionFromLink(const QString &value) {
|
||||
return QByteArray::fromBase64(value.toLatin1());
|
||||
}
|
||||
|
||||
QString PollOptionToLink(const QByteArray &option) {
|
||||
return QString::fromLatin1(
|
||||
option.toBase64(QByteArray::OmitTrailingEquals));
|
||||
}
|
||||
|
||||
MTPPoll PollDataToMTP(not_null<const PollData*> poll, bool close) {
|
||||
const auto convert = [&](const PollAnswer &answer) {
|
||||
const auto flags = answer.media
|
||||
|
||||
@@ -131,6 +131,9 @@ private:
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]] QByteArray PollOptionFromLink(const QString &value);
|
||||
[[nodiscard]] QString PollOptionToLink(const QByteArray &option);
|
||||
|
||||
[[nodiscard]] MTPPoll PollDataToMTP(
|
||||
not_null<const PollData*> poll,
|
||||
bool close = false);
|
||||
|
||||
@@ -1602,6 +1602,21 @@ void FillPollOptionPage(
|
||||
TextUtilities::SetClipboardText(text);
|
||||
},
|
||||
&st::menuIconCopy);
|
||||
if (item->hasDirectLink()) {
|
||||
const auto link = item->history()->session().api()
|
||||
.exportDirectMessageLink(item, false);
|
||||
const auto separator = (link.indexOf('?') >= 0) ? u'&' : u'?';
|
||||
const auto optionLink = link
|
||||
+ separator
|
||||
+ u"option="_q
|
||||
+ PollOptionToLink(pollOption);
|
||||
menu->addAction(
|
||||
tr::lng_context_copy_poll_option_link(tr::now),
|
||||
[optionLink] {
|
||||
QGuiApplication::clipboard()->setText(optionLink);
|
||||
},
|
||||
&st::menuIconLink);
|
||||
}
|
||||
const auto canDelete = [&] {
|
||||
if (!a->addedDate) {
|
||||
return false;
|
||||
|
||||
@@ -596,6 +596,7 @@ void SessionNavigation::showMessageByLinkResolved(
|
||||
params.origin = SectionShow::OriginMessage{
|
||||
info.clickFromMessageId
|
||||
};
|
||||
params.highlight.pollOption = info.pollOption;
|
||||
const auto peer = item->history()->peer;
|
||||
const auto topicId = peer->isForum() ? item->topicRootId() : 0;
|
||||
if (topicId) {
|
||||
@@ -615,6 +616,7 @@ void SessionNavigation::showPeerByLinkResolved(
|
||||
params.origin = SectionShow::OriginMessage{
|
||||
info.clickFromMessageId
|
||||
};
|
||||
params.highlight.pollOption = info.pollOption;
|
||||
if (info.voicechatHash && peer->isChannel()) {
|
||||
// First show the channel itself.
|
||||
crl::on_main(this, [=] {
|
||||
|
||||
@@ -40,6 +40,7 @@ struct PeerByLinkInfo {
|
||||
QString phone;
|
||||
QString chatLinkSlug;
|
||||
MsgId messageId = ShowAtUnreadMsgId;
|
||||
QByteArray pollOption;
|
||||
QString storyParam;
|
||||
int storyAlbumId = 0;
|
||||
int giftCollectionId = 0;
|
||||
|
||||
Reference in New Issue
Block a user