Moved out sending method of many messages to many peers to single place.
This commit is contained in:
parent
037f2bcce2
commit
bd8e7fdddd
|
@ -210,8 +210,6 @@ ShareBox::ShareBox(QWidget*, Descriptor &&descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShareBox::prepareCommentField() {
|
void ShareBox::prepareCommentField() {
|
||||||
using namespace rpl::mappers;
|
|
||||||
|
|
||||||
_comment->hide(anim::type::instant);
|
_comment->hide(anim::type::instant);
|
||||||
|
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
|
@ -476,7 +474,7 @@ void ShareBox::showMenu(not_null<Ui::RpWidget*> parent) {
|
||||||
auto item = base::make_unique_q<Menu::ItemWithCheck>(
|
auto item = base::make_unique_q<Menu::ItemWithCheck>(
|
||||||
_menu->menu(),
|
_menu->menu(),
|
||||||
st::popupMenuWithIcons.menu,
|
st::popupMenuWithIcons.menu,
|
||||||
new QAction(QString(), _menu->menu()),
|
Ui::CreateChild<QAction>(_menu->menu().get()),
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr);
|
nullptr);
|
||||||
std::move(
|
std::move(
|
||||||
|
@ -1343,75 +1341,23 @@ QString AppendShareGameScoreUrl(
|
||||||
return url + shareComponent;
|
return url + shareComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FastShareMessage(
|
ShareBox::SubmitCallback ShareBox::DefaultForwardCallback(
|
||||||
not_null<Window::SessionController*> controller,
|
std::shared_ptr<Ui::Show> show,
|
||||||
not_null<HistoryItem*> item) {
|
not_null<History*> history,
|
||||||
struct ShareData {
|
MessageIdsList msgIds) {
|
||||||
ShareData(not_null<PeerData*> peer, MessageIdsList &&ids)
|
struct State final {
|
||||||
: peer(peer)
|
|
||||||
, msgIds(std::move(ids)) {
|
|
||||||
}
|
|
||||||
not_null<PeerData*> peer;
|
|
||||||
MessageIdsList msgIds;
|
|
||||||
base::flat_set<mtpRequestId> requests;
|
base::flat_set<mtpRequestId> requests;
|
||||||
};
|
};
|
||||||
const auto show = std::make_shared<Window::Show>(controller);
|
const auto state = std::make_shared<State>();
|
||||||
const auto history = item->history();
|
return [=](
|
||||||
const auto owner = &history->owner();
|
|
||||||
const auto session = &history->session();
|
|
||||||
const auto data = std::make_shared<ShareData>(
|
|
||||||
history->peer,
|
|
||||||
owner->itemOrItsGroup(item));
|
|
||||||
const auto isGame = item->getMessageBot()
|
|
||||||
&& item->media()
|
|
||||||
&& (item->media()->game() != nullptr);
|
|
||||||
const auto canCopyLink = item->hasDirectLink() || isGame;
|
|
||||||
|
|
||||||
const auto items = owner->idsToItems(data->msgIds);
|
|
||||||
const auto hasCaptions = ranges::any_of(items, [](auto item) {
|
|
||||||
return item->media()
|
|
||||||
&& !item->originalText().text.isEmpty()
|
|
||||||
&& item->media()->allowsEditCaption();
|
|
||||||
});
|
|
||||||
const auto hasOnlyForcedForwardedInfo = hasCaptions
|
|
||||||
? false
|
|
||||||
: ranges::all_of(items, [](auto item) {
|
|
||||||
return item->media() && item->media()->forceForwardedInfo();
|
|
||||||
});
|
|
||||||
|
|
||||||
auto copyCallback = [=, toastParent = show->toastParent()] {
|
|
||||||
const auto item = owner->message(data->msgIds[0]);
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (item->hasDirectLink()) {
|
|
||||||
using namespace HistoryView;
|
|
||||||
CopyPostLink(controller, item->fullId(), Context::History);
|
|
||||||
} else if (const auto bot = item->getMessageBot()) {
|
|
||||||
if (const auto media = item->media()) {
|
|
||||||
if (const auto game = media->game()) {
|
|
||||||
const auto link = session->createInternalLinkFull(
|
|
||||||
bot->username() + u"?game="_q + game->shortName);
|
|
||||||
|
|
||||||
QGuiApplication::clipboard()->setText(link);
|
|
||||||
|
|
||||||
Ui::Toast::Show(
|
|
||||||
toastParent,
|
|
||||||
tr::lng_share_game_link_copied(tr::now));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
auto submitCallback = [=](
|
|
||||||
std::vector<not_null<Data::Thread*>> &&result,
|
std::vector<not_null<Data::Thread*>> &&result,
|
||||||
TextWithTags &&comment,
|
TextWithTags &&comment,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
Data::ForwardOptions forwardOptions) {
|
Data::ForwardOptions forwardOptions) {
|
||||||
if (!data->requests.empty()) {
|
if (!state->requests.empty()) {
|
||||||
return; // Share clicked already.
|
return; // Share clicked already.
|
||||||
}
|
}
|
||||||
auto items = history->owner().idsToItems(data->msgIds);
|
auto items = history->owner().idsToItems(msgIds);
|
||||||
if (items.empty() || result.empty()) {
|
if (items.empty() || result.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1451,20 +1397,20 @@ void FastShareMessage(
|
||||||
| ((forwardOptions == Data::ForwardOptions::NoNamesAndCaptions)
|
| ((forwardOptions == Data::ForwardOptions::NoNamesAndCaptions)
|
||||||
? Flag::f_drop_media_captions
|
? Flag::f_drop_media_captions
|
||||||
: Flag(0));
|
: Flag(0));
|
||||||
auto msgIds = QVector<MTPint>();
|
auto mtpMsgIds = QVector<MTPint>();
|
||||||
msgIds.reserve(data->msgIds.size());
|
mtpMsgIds.reserve(msgIds.size());
|
||||||
for (const auto &fullId : data->msgIds) {
|
for (const auto &fullId : msgIds) {
|
||||||
msgIds.push_back(MTP_int(fullId.msg));
|
mtpMsgIds.push_back(MTP_int(fullId.msg));
|
||||||
}
|
}
|
||||||
const auto generateRandom = [&] {
|
const auto generateRandom = [&] {
|
||||||
auto result = QVector<MTPlong>(data->msgIds.size());
|
auto result = QVector<MTPlong>(msgIds.size());
|
||||||
for (auto &value : result) {
|
for (auto &value : result) {
|
||||||
value = base::RandomValue<MTPlong>();
|
value = base::RandomValue<MTPlong>();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
auto &api = owner->session().api();
|
auto &api = history->owner().session().api();
|
||||||
auto &histories = owner->histories();
|
auto &histories = history->owner().histories();
|
||||||
const auto requestType = Data::Histories::RequestType::Send;
|
const auto requestType = Data::Histories::RequestType::Send;
|
||||||
for (const auto thread : result) {
|
for (const auto thread : result) {
|
||||||
if (!comment.text.isEmpty()) {
|
if (!comment.text.isEmpty()) {
|
||||||
|
@ -1486,8 +1432,8 @@ void FastShareMessage(
|
||||||
history->sendRequestId = api.request(
|
history->sendRequestId = api.request(
|
||||||
MTPmessages_ForwardMessages(
|
MTPmessages_ForwardMessages(
|
||||||
MTP_flags(sendFlags),
|
MTP_flags(sendFlags),
|
||||||
data->peer->input,
|
history->peer->input,
|
||||||
MTP_vector<MTPint>(msgIds),
|
MTP_vector<MTPint>(mtpMsgIds),
|
||||||
MTP_vector<MTPlong>(generateRandom()),
|
MTP_vector<MTPlong>(generateRandom()),
|
||||||
peer->input,
|
peer->input,
|
||||||
MTP_int(topicRootId),
|
MTP_int(topicRootId),
|
||||||
|
@ -1495,8 +1441,8 @@ void FastShareMessage(
|
||||||
MTP_inputPeerEmpty() // send_as
|
MTP_inputPeerEmpty() // send_as
|
||||||
)).done([=](const MTPUpdates &updates, mtpRequestId reqId) {
|
)).done([=](const MTPUpdates &updates, mtpRequestId reqId) {
|
||||||
history->session().api().applyUpdates(updates);
|
history->session().api().applyUpdates(updates);
|
||||||
data->requests.remove(reqId);
|
state->requests.remove(reqId);
|
||||||
if (data->requests.empty()) {
|
if (state->requests.empty()) {
|
||||||
if (show->valid()) {
|
if (show->valid()) {
|
||||||
Ui::Toast::Show(
|
Ui::Toast::Show(
|
||||||
show->toastParent(),
|
show->toastParent(),
|
||||||
|
@ -1520,9 +1466,60 @@ void FastShareMessage(
|
||||||
}).afterRequest(history->sendRequestId).send();
|
}).afterRequest(history->sendRequestId).send();
|
||||||
return history->sendRequestId;
|
return history->sendRequestId;
|
||||||
});
|
});
|
||||||
data->requests.insert(history->sendRequestId);
|
state->requests.insert(history->sendRequestId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void FastShareMessage(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<HistoryItem*> item) {
|
||||||
|
const auto show = std::make_shared<Window::Show>(controller);
|
||||||
|
const auto history = item->history();
|
||||||
|
const auto owner = &history->owner();
|
||||||
|
const auto session = &history->session();
|
||||||
|
const auto msgIds = owner->itemOrItsGroup(item);
|
||||||
|
const auto isGame = item->getMessageBot()
|
||||||
|
&& item->media()
|
||||||
|
&& (item->media()->game() != nullptr);
|
||||||
|
const auto canCopyLink = item->hasDirectLink() || isGame;
|
||||||
|
|
||||||
|
const auto items = owner->idsToItems(msgIds);
|
||||||
|
const auto hasCaptions = ranges::any_of(items, [](auto item) {
|
||||||
|
return item->media()
|
||||||
|
&& !item->originalText().text.isEmpty()
|
||||||
|
&& item->media()->allowsEditCaption();
|
||||||
|
});
|
||||||
|
const auto hasOnlyForcedForwardedInfo = hasCaptions
|
||||||
|
? false
|
||||||
|
: ranges::all_of(items, [](auto item) {
|
||||||
|
return item->media() && item->media()->forceForwardedInfo();
|
||||||
|
});
|
||||||
|
|
||||||
|
auto copyCallback = [=, toastParent = show->toastParent()] {
|
||||||
|
const auto item = owner->message(msgIds[0]);
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (item->hasDirectLink()) {
|
||||||
|
using namespace HistoryView;
|
||||||
|
CopyPostLink(controller, item->fullId(), Context::History);
|
||||||
|
} else if (const auto bot = item->getMessageBot()) {
|
||||||
|
if (const auto media = item->media()) {
|
||||||
|
if (const auto game = media->game()) {
|
||||||
|
const auto link = session->createInternalLinkFull(
|
||||||
|
bot->username() + u"?game="_q + game->shortName);
|
||||||
|
|
||||||
|
QGuiApplication::clipboard()->setText(link);
|
||||||
|
|
||||||
|
Ui::Toast::Show(
|
||||||
|
toastParent,
|
||||||
|
tr::lng_share_game_link_copied(tr::now));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto filterCallback = [isGame](not_null<Data::Thread*> thread) {
|
auto filterCallback = [isGame](not_null<Data::Thread*> thread) {
|
||||||
return thread->canWrite()
|
return thread->canWrite()
|
||||||
&& (!isGame || !thread->peer()->isBroadcast());
|
&& (!isGame || !thread->peer()->isBroadcast());
|
||||||
|
@ -1534,10 +1531,13 @@ void FastShareMessage(
|
||||||
Box<ShareBox>(ShareBox::Descriptor{
|
Box<ShareBox>(ShareBox::Descriptor{
|
||||||
.session = session,
|
.session = session,
|
||||||
.copyCallback = std::move(copyLinkCallback),
|
.copyCallback = std::move(copyLinkCallback),
|
||||||
.submitCallback = std::move(submitCallback),
|
.submitCallback = ShareBox::DefaultForwardCallback(
|
||||||
|
show,
|
||||||
|
history,
|
||||||
|
msgIds),
|
||||||
.filterCallback = std::move(filterCallback),
|
.filterCallback = std::move(filterCallback),
|
||||||
.forwardOptions = {
|
.forwardOptions = {
|
||||||
.messagesCount = int(data->msgIds.size()),
|
.messagesCount = int(msgIds.size()),
|
||||||
.show = !hasOnlyForcedForwardedInfo,
|
.show = !hasOnlyForcedForwardedInfo,
|
||||||
.hasCaptions = hasCaptions,
|
.hasCaptions = hasCaptions,
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,6 +15,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/effects/round_checkbox.h"
|
#include "ui/effects/round_checkbox.h"
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
|
|
||||||
|
class History;
|
||||||
|
|
||||||
namespace style {
|
namespace style {
|
||||||
struct MultiSelect;
|
struct MultiSelect;
|
||||||
struct InputField;
|
struct InputField;
|
||||||
|
@ -74,9 +76,14 @@ public:
|
||||||
std::vector<not_null<Data::Thread*>>&&,
|
std::vector<not_null<Data::Thread*>>&&,
|
||||||
TextWithTags&&,
|
TextWithTags&&,
|
||||||
Api::SendOptions,
|
Api::SendOptions,
|
||||||
Data::ForwardOptions option)>;
|
Data::ForwardOptions)>;
|
||||||
using FilterCallback = Fn<bool(not_null<Data::Thread*>)>;
|
using FilterCallback = Fn<bool(not_null<Data::Thread*>)>;
|
||||||
|
|
||||||
|
[[nodiscard]] static SubmitCallback DefaultForwardCallback(
|
||||||
|
std::shared_ptr<Ui::Show> show,
|
||||||
|
not_null<History*> history,
|
||||||
|
MessageIdsList msgIds);
|
||||||
|
|
||||||
struct Descriptor {
|
struct Descriptor {
|
||||||
not_null<Main::Session*> session;
|
not_null<Main::Session*> session;
|
||||||
CopyCallback copyCallback;
|
CopyCallback copyCallback;
|
||||||
|
|
Loading…
Reference in New Issue