mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Provided Window::SessionController to FastShareMessage.
This commit is contained in:
parent
b9f6591734
commit
63b5eb66ff
3 changed files with 59 additions and 48 deletions
|
@ -10,8 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
#include "dialogs/dialogs_indexed_list.h"
|
#include "dialogs/dialogs_indexed_list.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "mainwidget.h"
|
|
||||||
#include "base/qthelp_url.h"
|
#include "base/qthelp_url.h"
|
||||||
#include "storage/storage_account.h"
|
#include "storage/storage_account.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
@ -1265,7 +1263,9 @@ QString AppendShareGameScoreUrl(
|
||||||
return url + shareComponent;
|
return url + shareComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FastShareMessage(not_null<HistoryItem*> item) {
|
void FastShareMessage(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<HistoryItem*> item) {
|
||||||
struct ShareData {
|
struct ShareData {
|
||||||
ShareData(not_null<PeerData*> peer, MessageIdsList &&ids)
|
ShareData(not_null<PeerData*> peer, MessageIdsList &&ids)
|
||||||
: peer(peer)
|
: peer(peer)
|
||||||
|
@ -1275,6 +1275,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
|
||||||
MessageIdsList msgIds;
|
MessageIdsList msgIds;
|
||||||
base::flat_set<mtpRequestId> requests;
|
base::flat_set<mtpRequestId> requests;
|
||||||
};
|
};
|
||||||
|
const auto show = std::make_shared<Window::Show>(controller);
|
||||||
const auto history = item->history();
|
const auto history = item->history();
|
||||||
const auto owner = &history->owner();
|
const auto owner = &history->owner();
|
||||||
const auto session = &history->session();
|
const auto session = &history->session();
|
||||||
|
@ -1298,29 +1299,30 @@ void FastShareMessage(not_null<HistoryItem*> item) {
|
||||||
return item->media() && item->media()->forceForwardedInfo();
|
return item->media() && item->media()->forceForwardedInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
auto copyCallback = [=]() {
|
auto copyCallback = [=, toastParent = show->toastParent()] {
|
||||||
if (const auto item = owner->message(data->msgIds[0])) {
|
const auto item = owner->message(data->msgIds[0]);
|
||||||
if (item->hasDirectLink()) {
|
if (!item) {
|
||||||
HistoryView::CopyPostLink(
|
return;
|
||||||
session,
|
}
|
||||||
item->fullId(),
|
if (item->hasDirectLink()) {
|
||||||
HistoryView::Context::History);
|
using namespace HistoryView;
|
||||||
} else if (const auto bot = item->getMessageBot()) {
|
CopyPostLink(session, item->fullId(), Context::History);
|
||||||
if (const auto media = item->media()) {
|
} else if (const auto bot = item->getMessageBot()) {
|
||||||
if (const auto game = media->game()) {
|
if (const auto media = item->media()) {
|
||||||
const auto link = session->createInternalLinkFull(
|
if (const auto game = media->game()) {
|
||||||
bot->username
|
const auto link = session->createInternalLinkFull(
|
||||||
+ qsl("?game=")
|
bot->username + qsl("?game=") + game->shortName);
|
||||||
+ game->shortName);
|
|
||||||
|
|
||||||
QGuiApplication::clipboard()->setText(link);
|
QGuiApplication::clipboard()->setText(link);
|
||||||
|
|
||||||
Ui::Toast::Show(tr::lng_share_game_link_copied(tr::now));
|
Ui::Toast::Show(
|
||||||
}
|
toastParent,
|
||||||
|
tr::lng_share_game_link_copied(tr::now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto submitCallback = [=](
|
auto submitCallback = [=](
|
||||||
std::vector<not_null<PeerData*>> &&result,
|
std::vector<not_null<PeerData*>> &&result,
|
||||||
TextWithTags &&comment,
|
TextWithTags &&comment,
|
||||||
|
@ -1354,7 +1356,7 @@ void FastShareMessage(not_null<HistoryItem*> item) {
|
||||||
).append("\n\n");
|
).append("\n\n");
|
||||||
}
|
}
|
||||||
text.append(error.first);
|
text.append(error.first);
|
||||||
Ui::show(
|
show->showBox(
|
||||||
Ui::MakeInformBox(text),
|
Ui::MakeInformBox(text),
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
return;
|
return;
|
||||||
|
@ -1401,20 +1403,25 @@ void FastShareMessage(not_null<HistoryItem*> item) {
|
||||||
| (ShouldSendSilent(peer, options)
|
| (ShouldSendSilent(peer, options)
|
||||||
? MTPmessages_ForwardMessages::Flag::f_silent
|
? MTPmessages_ForwardMessages::Flag::f_silent
|
||||||
: MTPmessages_ForwardMessages::Flag(0));
|
: MTPmessages_ForwardMessages::Flag(0));
|
||||||
history->sendRequestId = api.request(MTPmessages_ForwardMessages(
|
history->sendRequestId = api.request(
|
||||||
MTP_flags(sendFlags),
|
MTPmessages_ForwardMessages(
|
||||||
data->peer->input,
|
MTP_flags(sendFlags),
|
||||||
MTP_vector<MTPint>(msgIds),
|
data->peer->input,
|
||||||
MTP_vector<MTPlong>(generateRandom()),
|
MTP_vector<MTPint>(msgIds),
|
||||||
peer->input,
|
MTP_vector<MTPlong>(generateRandom()),
|
||||||
MTP_int(options.scheduled),
|
peer->input,
|
||||||
MTP_inputPeerEmpty() // send_as
|
MTP_int(options.scheduled),
|
||||||
)).done([=](const MTPUpdates &updates, mtpRequestId requestId) {
|
MTP_inputPeerEmpty() // send_as
|
||||||
|
)).done([=](const MTPUpdates &updates, mtpRequestId reqId) {
|
||||||
history->session().api().applyUpdates(updates);
|
history->session().api().applyUpdates(updates);
|
||||||
data->requests.remove(requestId);
|
data->requests.remove(reqId);
|
||||||
if (data->requests.empty()) {
|
if (data->requests.empty()) {
|
||||||
Ui::Toast::Show(tr::lng_share_done(tr::now));
|
if (show->valid()) {
|
||||||
Ui::hideLayer();
|
Ui::Toast::Show(
|
||||||
|
show->toastParent(),
|
||||||
|
tr::lng_share_done(tr::now));
|
||||||
|
show->hideLayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
|
@ -1437,17 +1444,19 @@ void FastShareMessage(not_null<HistoryItem*> item) {
|
||||||
auto copyLinkCallback = canCopyLink
|
auto copyLinkCallback = canCopyLink
|
||||||
? Fn<void()>(std::move(copyCallback))
|
? Fn<void()>(std::move(copyCallback))
|
||||||
: Fn<void()>();
|
: Fn<void()>();
|
||||||
Ui::show(Box<ShareBox>(ShareBox::Descriptor{
|
controller->show(
|
||||||
.session = session,
|
Box<ShareBox>(ShareBox::Descriptor{
|
||||||
.copyCallback = std::move(copyLinkCallback),
|
.session = session,
|
||||||
.submitCallback = std::move(submitCallback),
|
.copyCallback = std::move(copyLinkCallback),
|
||||||
.filterCallback = std::move(filterCallback),
|
.submitCallback = std::move(submitCallback),
|
||||||
.forwardOptions = {
|
.filterCallback = std::move(filterCallback),
|
||||||
.messagesCount = int(data->msgIds.size()),
|
.forwardOptions = {
|
||||||
.show = !hasOnlyForcedForwardedInfo,
|
.messagesCount = int(data->msgIds.size()),
|
||||||
.hasCaptions = hasCaptions,
|
.show = !hasOnlyForcedForwardedInfo,
|
||||||
},
|
.hasCaptions = hasCaptions,
|
||||||
}));
|
},
|
||||||
|
}),
|
||||||
|
Ui::LayerOption::CloseOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShareGameScoreByHash(
|
void ShareGameScoreByHash(
|
||||||
|
@ -1512,7 +1521,7 @@ void ShareGameScoreByHash(
|
||||||
|
|
||||||
const auto msgId = MsgId(int64(hashDataInts[2]));
|
const auto msgId = MsgId(int64(hashDataInts[2]));
|
||||||
if (const auto item = session.data().message(peerId, msgId)) {
|
if (const auto item = session.data().message(peerId, msgId)) {
|
||||||
FastShareMessage(item);
|
FastShareMessage(controller, item);
|
||||||
} else {
|
} else {
|
||||||
const auto weak = base::make_weak(controller.get());
|
const auto weak = base::make_weak(controller.get());
|
||||||
const auto resolveMessageAndShareScore = crl::guard(weak, [=](
|
const auto resolveMessageAndShareScore = crl::guard(weak, [=](
|
||||||
|
@ -1522,7 +1531,7 @@ void ShareGameScoreByHash(
|
||||||
peerId,
|
peerId,
|
||||||
msgId);
|
msgId);
|
||||||
if (item) {
|
if (item) {
|
||||||
FastShareMessage(item);
|
FastShareMessage(weak.get(), item);
|
||||||
} else {
|
} else {
|
||||||
weak->show(
|
weak->show(
|
||||||
Ui::MakeInformBox(tr::lng_edit_deleted()),
|
Ui::MakeInformBox(tr::lng_edit_deleted()),
|
||||||
|
|
|
@ -62,7 +62,9 @@ QString AppendShareGameScoreUrl(
|
||||||
void ShareGameScoreByHash(
|
void ShareGameScoreByHash(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &hash);
|
const QString &hash);
|
||||||
void FastShareMessage(not_null<HistoryItem*> item);
|
void FastShareMessage(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<HistoryItem*> item);
|
||||||
|
|
||||||
class ShareBox final : public Ui::BoxContent {
|
class ShareBox final : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -2634,7 +2634,7 @@ ClickHandlerPtr Message::rightActionLink() const {
|
||||||
Window::SectionShow::Way::Forward,
|
Window::SectionShow::Way::Forward,
|
||||||
savedFromMsgId);
|
savedFromMsgId);
|
||||||
} else {
|
} else {
|
||||||
FastShareMessage(item);
|
FastShareMessage(controller, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue