mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add a general FastShareLink method.
This commit is contained in:
parent
56080bd0e4
commit
da423b5bd2
3 changed files with 122 additions and 87 deletions
|
@ -234,7 +234,10 @@ void ShareBox::prepareCommentField() {
|
||||||
const auto field = _comment->entity();
|
const auto field = _comment->entity();
|
||||||
|
|
||||||
field->submits(
|
field->submits(
|
||||||
) | rpl::start_with_next([=] { submit({}); }, field->lifetime());
|
) | rpl::start_with_next([=] {
|
||||||
|
submit({});
|
||||||
|
}, field->lifetime());
|
||||||
|
|
||||||
if (const auto show = uiShow(); show->valid()) {
|
if (const auto show = uiShow(); show->valid()) {
|
||||||
InitMessageFieldHandlers(
|
InitMessageFieldHandlers(
|
||||||
_descriptor.session,
|
_descriptor.session,
|
||||||
|
@ -246,6 +249,14 @@ void ShareBox::prepareCommentField() {
|
||||||
}
|
}
|
||||||
field->setSubmitSettings(Core::App().settings().sendSubmitWay());
|
field->setSubmitSettings(Core::App().settings().sendSubmitWay());
|
||||||
|
|
||||||
|
field->changes() | rpl::start_with_next([=] {
|
||||||
|
if (!field->getLastText().isEmpty()) {
|
||||||
|
setCloseByOutsideClick(false);
|
||||||
|
} else if (_inner->selected().empty()) {
|
||||||
|
setCloseByOutsideClick(true);
|
||||||
|
}
|
||||||
|
}, field->lifetime());
|
||||||
|
|
||||||
Ui::SendPendingMoveResizeEvents(_comment);
|
Ui::SendPendingMoveResizeEvents(_comment);
|
||||||
if (_bottomWidget) {
|
if (_bottomWidget) {
|
||||||
Ui::SendPendingMoveResizeEvents(_bottomWidget);
|
Ui::SendPendingMoveResizeEvents(_bottomWidget);
|
||||||
|
@ -255,8 +266,6 @@ void ShareBox::prepareCommentField() {
|
||||||
void ShareBox::prepare() {
|
void ShareBox::prepare() {
|
||||||
prepareCommentField();
|
prepareCommentField();
|
||||||
|
|
||||||
setCloseByOutsideClick(false);
|
|
||||||
|
|
||||||
_select->resizeToWidth(st::boxWideWidth);
|
_select->resizeToWidth(st::boxWideWidth);
|
||||||
Ui::SendPendingMoveResizeEvents(_select);
|
Ui::SendPendingMoveResizeEvents(_select);
|
||||||
|
|
||||||
|
@ -313,6 +322,12 @@ void ShareBox::prepare() {
|
||||||
not_null<Data::Thread*> thread,
|
not_null<Data::Thread*> thread,
|
||||||
bool checked) {
|
bool checked) {
|
||||||
innerSelectedChanged(thread, checked);
|
innerSelectedChanged(thread, checked);
|
||||||
|
if (checked) {
|
||||||
|
setCloseByOutsideClick(false);
|
||||||
|
} else if (_inner->selected().empty()
|
||||||
|
&& _comment->entity()->getLastText().isEmpty()) {
|
||||||
|
setCloseByOutsideClick(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ui::Emoji::SuggestionsController::Init(
|
Ui::Emoji::SuggestionsController::Init(
|
||||||
|
@ -1678,6 +1693,101 @@ void FastShareMessage(
|
||||||
Ui::LayerOption::CloseOther);
|
Ui::LayerOption::CloseOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FastShareLink(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
const QString &url) {
|
||||||
|
FastShareLink(controller->uiShow(), url);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FastShareLink(
|
||||||
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
|
const QString &url) {
|
||||||
|
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
||||||
|
const auto sending = std::make_shared<bool>();
|
||||||
|
auto copyCallback = [=] {
|
||||||
|
QGuiApplication::clipboard()->setText(url);
|
||||||
|
show->showToast(tr::lng_background_link_copied(tr::now));
|
||||||
|
};
|
||||||
|
auto submitCallback = [=](
|
||||||
|
std::vector<not_null<::Data::Thread*>> &&result,
|
||||||
|
TextWithTags &&comment,
|
||||||
|
Api::SendOptions options,
|
||||||
|
::Data::ForwardOptions) {
|
||||||
|
if (*sending || result.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto error = [&] {
|
||||||
|
for (const auto thread : result) {
|
||||||
|
const auto error = GetErrorTextForSending(
|
||||||
|
thread,
|
||||||
|
{ .text = &comment });
|
||||||
|
if (!error.isEmpty()) {
|
||||||
|
return std::make_pair(error, thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::make_pair(QString(), result.front());
|
||||||
|
}();
|
||||||
|
if (!error.first.isEmpty()) {
|
||||||
|
auto text = TextWithEntities();
|
||||||
|
if (result.size() > 1) {
|
||||||
|
text.append(
|
||||||
|
Ui::Text::Bold(error.second->chatListName())
|
||||||
|
).append("\n\n");
|
||||||
|
}
|
||||||
|
text.append(error.first);
|
||||||
|
if (const auto weak = *box) {
|
||||||
|
weak->getDelegate()->show(Ui::MakeConfirmBox({
|
||||||
|
.text = text,
|
||||||
|
.inform = true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*sending = true;
|
||||||
|
if (!comment.text.isEmpty()) {
|
||||||
|
comment.text = url + "\n" + comment.text;
|
||||||
|
const auto add = url.size() + 1;
|
||||||
|
for (auto &tag : comment.tags) {
|
||||||
|
tag.offset += add;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
comment.text = url;
|
||||||
|
}
|
||||||
|
auto &api = show->session().api();
|
||||||
|
for (const auto thread : result) {
|
||||||
|
auto message = Api::MessageToSend(
|
||||||
|
Api::SendAction(thread, options));
|
||||||
|
message.textWithTags = comment;
|
||||||
|
message.action.clearDraft = false;
|
||||||
|
api.sendMessage(std::move(message));
|
||||||
|
}
|
||||||
|
if (*box) {
|
||||||
|
(*box)->closeBox();
|
||||||
|
}
|
||||||
|
show->showToast(tr::lng_share_done(tr::now));
|
||||||
|
};
|
||||||
|
auto filterCallback = [](not_null<::Data::Thread*> thread) {
|
||||||
|
if (const auto user = thread->peer()->asUser()) {
|
||||||
|
if (user->canSendIgnoreRequirePremium()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ::Data::CanSend(thread, ChatRestriction::SendOther);
|
||||||
|
};
|
||||||
|
*box = show->show(
|
||||||
|
Box<ShareBox>(ShareBox::Descriptor{
|
||||||
|
.session = &show->session(),
|
||||||
|
.copyCallback = std::move(copyCallback),
|
||||||
|
.submitCallback = std::move(submitCallback),
|
||||||
|
.filterCallback = std::move(filterCallback),
|
||||||
|
.premiumRequiredError = SharePremiumRequiredError(),
|
||||||
|
}),
|
||||||
|
Ui::LayerOption::KeepOther,
|
||||||
|
anim::type::normal);
|
||||||
|
}
|
||||||
|
|
||||||
auto SharePremiumRequiredError()
|
auto SharePremiumRequiredError()
|
||||||
-> Fn<RecipientPremiumRequiredError(not_null<UserData*>)> {
|
-> Fn<RecipientPremiumRequiredError(not_null<UserData*>)> {
|
||||||
return WritePremiumRequiredError;
|
return WritePremiumRequiredError;
|
||||||
|
|
|
@ -37,6 +37,7 @@ struct SendOptions;
|
||||||
|
|
||||||
namespace Main {
|
namespace Main {
|
||||||
class Session;
|
class Session;
|
||||||
|
class SessionShow;
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
|
||||||
namespace Dialogs {
|
namespace Dialogs {
|
||||||
|
@ -68,6 +69,12 @@ void ShareGameScoreByHash(
|
||||||
void FastShareMessage(
|
void FastShareMessage(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<HistoryItem*> item);
|
not_null<HistoryItem*> item);
|
||||||
|
void FastShareLink(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
const QString &url);
|
||||||
|
void FastShareLink(
|
||||||
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
|
const QString &url);
|
||||||
|
|
||||||
struct RecipientPremiumRequiredError;
|
struct RecipientPremiumRequiredError;
|
||||||
[[nodiscard]] auto SharePremiumRequiredError()
|
[[nodiscard]] auto SharePremiumRequiredError()
|
||||||
|
|
|
@ -297,80 +297,6 @@ ShareBoxResult Shown::shareBox(ShareBoxDescriptor &&descriptor) {
|
||||||
state->destroyRequests.fire({});
|
state->destroyRequests.fire({});
|
||||||
}, wrap->lifetime());
|
}, wrap->lifetime());
|
||||||
|
|
||||||
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
|
|
||||||
const auto sending = std::make_shared<bool>();
|
|
||||||
auto copyCallback = [=] {
|
|
||||||
QGuiApplication::clipboard()->setText(url);
|
|
||||||
show->showToast(tr::lng_background_link_copied(tr::now));
|
|
||||||
};
|
|
||||||
auto submitCallback = [=](
|
|
||||||
std::vector<not_null<::Data::Thread*>> &&result,
|
|
||||||
TextWithTags &&comment,
|
|
||||||
Api::SendOptions options,
|
|
||||||
::Data::ForwardOptions) {
|
|
||||||
if (*sending || result.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto error = [&] {
|
|
||||||
for (const auto thread : result) {
|
|
||||||
const auto error = GetErrorTextForSending(
|
|
||||||
thread,
|
|
||||||
{ .text = &comment });
|
|
||||||
if (!error.isEmpty()) {
|
|
||||||
return std::make_pair(error, thread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return std::make_pair(QString(), result.front());
|
|
||||||
}();
|
|
||||||
if (!error.first.isEmpty()) {
|
|
||||||
auto text = TextWithEntities();
|
|
||||||
if (result.size() > 1) {
|
|
||||||
text.append(
|
|
||||||
Ui::Text::Bold(error.second->chatListName())
|
|
||||||
).append("\n\n");
|
|
||||||
}
|
|
||||||
text.append(error.first);
|
|
||||||
if (const auto weak = *box) {
|
|
||||||
weak->getDelegate()->show(Ui::MakeConfirmBox({
|
|
||||||
.text = text,
|
|
||||||
.inform = true,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*sending = true;
|
|
||||||
if (!comment.text.isEmpty()) {
|
|
||||||
comment.text = url + "\n" + comment.text;
|
|
||||||
const auto add = url.size() + 1;
|
|
||||||
for (auto &tag : comment.tags) {
|
|
||||||
tag.offset += add;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
comment.text = url;
|
|
||||||
}
|
|
||||||
auto &api = _session->api();
|
|
||||||
for (const auto thread : result) {
|
|
||||||
auto message = Api::MessageToSend(
|
|
||||||
Api::SendAction(thread, options));
|
|
||||||
message.textWithTags = comment;
|
|
||||||
message.action.clearDraft = false;
|
|
||||||
api.sendMessage(std::move(message));
|
|
||||||
}
|
|
||||||
if (*box) {
|
|
||||||
(*box)->closeBox();
|
|
||||||
}
|
|
||||||
show->showToast(tr::lng_share_done(tr::now));
|
|
||||||
};
|
|
||||||
auto filterCallback = [](not_null<::Data::Thread*> thread) {
|
|
||||||
if (const auto user = thread->peer()->asUser()) {
|
|
||||||
if (user->canSendIgnoreRequirePremium()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ::Data::CanSend(thread, ChatRestriction::SendOther);
|
|
||||||
};
|
|
||||||
const auto focus = crl::guard(layer, [=] {
|
const auto focus = crl::guard(layer, [=] {
|
||||||
if (!layer->window()->isActiveWindow()) {
|
if (!layer->window()->isActiveWindow()) {
|
||||||
layer->window()->activateWindow();
|
layer->window()->activateWindow();
|
||||||
|
@ -383,16 +309,8 @@ ShareBoxResult Shown::shareBox(ShareBoxDescriptor &&descriptor) {
|
||||||
.hide = [=] { show->hideLayer(); },
|
.hide = [=] { show->hideLayer(); },
|
||||||
.destroyRequests = state->destroyRequests.events(),
|
.destroyRequests = state->destroyRequests.events(),
|
||||||
};
|
};
|
||||||
*box = show->show(
|
|
||||||
Box<ShareBox>(ShareBox::Descriptor{
|
FastShareLink(Main::MakeSessionShow(show, _session), url);
|
||||||
.session = _session,
|
|
||||||
.copyCallback = std::move(copyCallback),
|
|
||||||
.submitCallback = std::move(submitCallback),
|
|
||||||
.filterCallback = std::move(filterCallback),
|
|
||||||
.premiumRequiredError = SharePremiumRequiredError(),
|
|
||||||
}),
|
|
||||||
Ui::LayerOption::KeepOther,
|
|
||||||
anim::type::normal);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue