2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Detach ComposeControls from SessionController.

This commit is contained in:
John Preston
2023-05-02 13:33:19 +04:00
parent 665467b02d
commit 65afa2c402
178 changed files with 2080 additions and 1869 deletions

View File

@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "menu/menu_check_item.h"
#include "boxes/share_box.h"
#include "chat_helpers/compose/compose_show.h"
#include "chat_helpers/message_field.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/widgets/input_fields.h"
@@ -40,7 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
#include "ui/layers/generic_box.h"
#include "ui/toasts/common_toasts.h"
#include "ui/delayed_activation.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
@@ -197,7 +197,7 @@ void PeerMenuAddMuteSubmenuAction(
notifySettings->update(thread, { .unmute = true });
}), &st::menuIconUnmute);
} else {
const auto show = std::make_shared<Window::Show>(controller);
const auto show = controller->uiShow();
addAction(PeerMenuCallback::Args{
.text = tr::lng_context_mute(tr::now),
.handler = nullptr,
@@ -212,23 +212,19 @@ void PeerMenuAddMuteSubmenuAction(
}
void ForwardToSelf(
not_null<Window::SessionNavigation*> navigation,
std::shared_ptr<Main::SessionShow> show,
const Data::ForwardDraft &draft) {
const auto content = navigation->parentController()->content();
const auto session = &navigation->session();
const auto session = &show->session();
const auto history = session->data().history(session->user());
auto resolved = history->resolveForwardDraft(draft);
if (!resolved.items.empty()) {
auto action = Api::SendAction(history);
action.clearDraft = false;
action.generateLocal = false;
const auto weakContent = Ui::MakeWeak(content);
session->api().forwardMessages(
std::move(resolved),
action,
crl::guard(weakContent, [w = weakContent] {
Ui::Toast::Show(w, tr::lng_share_done(tr::now));
}));
[=] { show->showToast(tr::lng_share_done(tr::now)); });
}
}
@@ -414,9 +410,7 @@ void TogglePinnedThread(
(&owner->session())->data().chatsFilters().list(),
filterId,
&Data::ChatFilter::id)) {
Ui::Toast::Show(
Window::Show(controller).toastParent(),
tr::lng_cant_do_this(tr::now));
controller->showToast(tr::lng_cant_do_this(tr::now));
return;
}
@@ -777,9 +771,7 @@ void Filler::addViewDiscussion() {
const auto navigation = _controller;
_addAction(tr::lng_profile_view_discussion(tr::now), [=] {
if (channel->invitePeekExpires()) {
Ui::Toast::Show(
Window::Show(navigation).toastParent(),
tr::lng_channel_invite_private(tr::now));
navigation->showToast(tr::lng_channel_invite_private(tr::now));
return;
}
navigation->showPeerHistory(
@@ -955,11 +947,9 @@ void Filler::addTopicLink() {
const auto query = base + '/' + QString::number(id.bare);
const auto link = channel->session().createInternalLinkFull(query);
QGuiApplication::clipboard()->setText(link);
Ui::Toast::Show(
Window::Show(controller).toastParent(),
(channel->hasUsername()
? tr::lng_channel_public_link_copied(tr::now)
: tr::lng_context_about_private_link(tr::now)));
controller->showToast(channel->hasUsername()
? tr::lng_channel_public_link_copied(tr::now)
: tr::lng_context_about_private_link(tr::now));
}, &st::menuIconCopy);
}
@@ -1048,7 +1038,7 @@ void Filler::addTTLSubmenu(bool addSeparator) {
return; // #TODO later forum
}
const auto validator = TTLMenu::TTLValidator(
std::make_shared<Window::Show>(_controller),
_controller->uiShow(),
_peer);
if (!validator.can()) {
return;
@@ -1170,7 +1160,6 @@ void Filler::addVideoChat() {
FillVideoChatMenu(_controller, _request, _addAction);
return;
}
const auto show = std::make_shared<Window::Show>(_controller);
_addAction(PeerMenuCallback::Args{
.text = tr::lng_menu_start_group_call_options(tr::now),
.handler = nullptr,
@@ -1276,14 +1265,11 @@ void Filler::fillArchiveActions() {
}, hidden ? &st::menuIconExpand : &st::menuIconCollapse);
_addAction(tr::lng_context_archive_to_menu(tr::now), [=] {
Ui::Toast::Show(
Window::Show(controller).toastParent(),
Ui::Toast::Config{
.text = { tr::lng_context_archive_to_menu_info(tr::now) },
.st = &st::windowArchiveToast,
.durationMs = kArchivedToastDuration,
.multiline = true,
});
controller->showToast({
.text = { tr::lng_context_archive_to_menu_info(tr::now) },
.st = &st::windowArchiveToast,
.duration = kArchivedToastDuration,
});
controller->session().settings().setArchiveInMainMenu(
!controller->session().settings().archiveInMainMenu());
@@ -1378,16 +1364,13 @@ void PeerMenuShareContactBox(
const auto peer = thread->peer();
if (!Data::CanSend(thread, ChatRestriction::SendOther)) {
navigation->parentController()->show(
Ui::MakeInformBox(tr::lng_forward_share_cant()),
Ui::LayerOption::KeepOther);
Ui::MakeInformBox(tr::lng_forward_share_cant()));
return;
} else if (peer->isSelf()) {
auto action = Api::SendAction(thread);
action.clearDraft = false;
user->session().api().shareContact(user, action);
Ui::Toast::Show(
Window::Show(navigation).toastParent(),
tr::lng_share_done(tr::now));
navigation->showToast(tr::lng_share_done(tr::now));
if (auto strong = *weak) {
strong->closeBox();
}
@@ -1419,8 +1402,7 @@ void PeerMenuShareContactBox(
close();
},
.confirmText = tr::lng_forward_send(),
}),
Ui::LayerOption::KeepOther);
}));
};
*weak = navigation->parentController()->show(
Box<PeerListBox>(
@@ -1431,8 +1413,7 @@ void PeerMenuShareContactBox(
box->addButton(tr::lng_cancel(), [=] {
box->closeBox();
});
}),
Ui::LayerOption::CloseOther);
}));
}
void PeerMenuCreatePoll(
@@ -1585,8 +1566,7 @@ void PeerMenuBlockUserBox(
}
}
Ui::Toast::Show(
Window::Show(window).toastParent(),
window->showToast(
tr::lng_new_contact_block_done(tr::now, lt_user, name));
}, st::attentionBoxButton);
@@ -1650,15 +1630,16 @@ QPointer<Ui::BoxContent> ShowChooseRecipientBox(
std::make_unique<ChooseRecipientBoxController>(
&navigation->session(),
std::move(callback)),
std::move(initBox)), Ui::LayerOption::KeepOther);
std::move(initBox)));
return weak->data();
}
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
not_null<Window::SessionNavigation*> navigation,
std::shared_ptr<ChatHelpers::Show> show,
Data::ForwardDraft &&draft,
Fn<void()> &&successCallback) {
const auto owner = &navigation->session().data();
const auto session = &show->session();
const auto owner = &session->data();
const auto msgIds = owner->itemsToIds(owner->idsToItems(draft.ids));
if (msgIds.empty()) {
return nullptr;
@@ -1753,7 +1734,6 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
};
const auto session = &navigation->session();
struct State {
not_null<ListBox*> box;
not_null<Controller*> controller;
@@ -1764,24 +1744,37 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
const auto controllerRaw = controller.get();
auto box = Box<ListBox>(std::move(controller), nullptr);
const auto boxRaw = box.data();
navigation->parentController()->show(
std::move(box),
Ui::LayerOption::KeepOther);
show->showBox(std::move(box));
auto state = State{ boxRaw, controllerRaw };
return boxRaw->lifetime().make_state<State>(std::move(state));
}();
{ // Chosen a single.
auto chosen = [navigation, draft = std::move(draft)](
auto chosen = [show, draft = std::move(draft)](
not_null<Data::Thread*> thread) mutable {
const auto content = navigation->parentController()->content();
const auto peer = thread->peer();
if (peer->isSelf()
&& !draft.ids.empty()
&& draft.ids.front().peer != peer->id) {
ForwardToSelf(navigation, draft);
ForwardToSelf(show, draft);
return true;
}
auto controller = Core::App().windowFor(peer);
if (!controller) {
return false;
}
if (controller->maybeSession() != &peer->session()) {
controller = peer->isForum()
? Core::App().ensureSeparateWindowForAccount(
&peer->account())
: Core::App().ensureSeparateWindowForPeer(
peer,
ShowAtUnreadMsgId);
if (controller->maybeSession() != &peer->session()) {
return false;
}
}
const auto content = controller->sessionController()->content();
return content->setForwardDraft(thread, std::move(draft));
};
auto callback = [=, chosen = std::move(chosen)](
@@ -1810,7 +1803,7 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
st::shareCommentPadding);
const auto send = ShareBox::DefaultForwardCallback(
std::make_shared<Window::Show>(navigation),
show,
session->data().message(msgIds.front())->history(),
msgIds);
@@ -1913,10 +1906,11 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
QObject::connect(field, &Ui::InputField::submitted, [=] {
submit({});
});
const auto show = std::make_shared<Ui::BoxShow>(state->box);
if (show->valid()) {
InitMessageFieldHandlers(session, show, field, nullptr);
}
InitMessageFieldHandlers(
session,
show,
field,
[=] { return show->paused(GifPauseReason::Layer); });
field->setSubmitSettings(Core::App().settings().sendSubmitWay());
Ui::SendPendingMoveResizeEvents(comment);
@@ -1951,6 +1945,16 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
return QPointer<Ui::BoxContent>(state->box);
}
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
not_null<Window::SessionNavigation*> navigation,
Data::ForwardDraft &&draft,
Fn<void()> &&successCallback) {
return ShowForwardMessagesBox(
navigation->uiShow(),
std::move(draft),
std::move(successCallback));
}
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
not_null<Window::SessionNavigation*> navigation,
MessageIdsList &&items,
@@ -1994,8 +1998,7 @@ QPointer<Ui::BoxContent> ShowShareGameBox(
Ui::MakeConfirmBox({
.text = confirmText,
.confirmed = std::move(send),
}),
Ui::LayerOption::KeepOther);
}));
};
auto filter = [](not_null<Data::Thread*> thread) {
return !thread->peer()->isSelf()
@@ -2012,7 +2015,7 @@ QPointer<Ui::BoxContent> ShowShareGameBox(
&navigation->session(),
std::move(chosen),
std::move(filter)),
std::move(initBox)), Ui::LayerOption::KeepOther);
std::move(initBox)));
return weak->data();
}
@@ -2071,10 +2074,7 @@ QPointer<Ui::BoxContent> ShowSendNowMessagesBox(
history->peer,
{ .forward = &list });
if (!error.isEmpty()) {
Ui::ShowMultilineToast({
.parentOverride = Window::Show(navigation).toastParent(),
.text = { error },
});
navigation->showToast(error);
return { nullptr };
}
auto done = [
@@ -2102,13 +2102,11 @@ QPointer<Ui::BoxContent> ShowSendNowMessagesBox(
callback();
}
};
return navigation->parentController()->show(
Ui::MakeConfirmBox({
.text = text,
.confirmed = std::move(done),
.confirmText = tr::lng_send_button(),
}),
Ui::LayerOption::KeepOther).data();
return navigation->parentController()->show(Ui::MakeConfirmBox({
.text = text,
.confirmed = std::move(done),
.confirmText = tr::lng_send_button(),
})).data();
}
void PeerMenuAddChannelMembers(
@@ -2117,9 +2115,7 @@ void PeerMenuAddChannelMembers(
if (!channel->isMegagroup()
&& (channel->membersCount()
>= channel->session().serverConfig().chatSizeMax)) {
navigation->parentController()->show(
Box<MaxInviteBox>(channel),
Ui::LayerOption::KeepOther);
navigation->parentController()->show(Box<MaxInviteBox>(channel));
return;
}
const auto api = &channel->session().api();
@@ -2325,7 +2321,7 @@ void ToggleHistoryArchived(not_null<History*> history, bool archived) {
? tr::lng_archived_added(tr::now)
: tr::lng_archived_removed(tr::now)) },
.st = &st::windowArchiveToast,
.durationMs = (archived
.duration = (archived
? kArchivedToastDuration
: Ui::Toast::kDefaultDuration),
.multiline = true,
@@ -2341,9 +2337,7 @@ Fn<void()> ClearHistoryHandler(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer) {
return [=] {
controller->show(
Box<DeleteMessagesBox>(peer, true),
Ui::LayerOption::KeepOther);
controller->show(Box<DeleteMessagesBox>(peer, true));
};
}
@@ -2351,9 +2345,7 @@ Fn<void()> DeleteAndLeaveHandler(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer) {
return [=] {
controller->show(
Box<DeleteMessagesBox>(peer, false),
Ui::LayerOption::KeepOther);
controller->show(Box<DeleteMessagesBox>(peer, false));
};
}
@@ -2377,9 +2369,7 @@ bool FillVideoChatMenu(
controller->startOrJoinGroupCall(peer, std::move(args));
};
const auto rtmpCallback = [=] {
Core::App().calls().showStartWithRtmp(
std::make_shared<Window::Show>(controller),
peer);
Core::App().calls().showStartWithRtmp(controller->uiShow(), peer);
};
const auto livestream = !peer->isMegagroup() && peer->isChannel();
const auto has = (peer->groupCall() != nullptr);