2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +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

@@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h"
#include "ui/ui_utility.h"
#include "ui/chat/chat_theme.h"
#include "ui/toasts/common_toasts.h"
#include "ui/painter.h"
#include "boxes/premium_preview_box.h"
#include "data/data_peer.h"

View File

@@ -892,12 +892,11 @@ void SaveThemeBox(
} else if (error == u"THEME_SLUG_INVALID"_q) {
type = SaveErrorType::Link;
} else if (error == u"THEME_SLUG_OCCUPIED"_q) {
Ui::Toast::Show(
Ui::BoxShow(box).toastParent(),
box->showToast(
tr::lng_create_channel_link_occupied(tr::now));
type = SaveErrorType::Link;
} else if (!error.isEmpty()) {
Ui::Toast::Show(Ui::BoxShow(box).toastParent(), error);
box->showToast(error);
}
if (type == SaveErrorType::Name) {
name->showError();

View File

@@ -39,6 +39,61 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QScreen>
namespace Window {
namespace {
class Show final : public Ui::Show {
public:
explicit Show(not_null<Controller*> window);
void showBox(
object_ptr<Ui::BoxContent> content,
Ui::LayerOptions options
= Ui::LayerOption::KeepOther) const override;
void hideLayer() const override;
[[nodiscard]] not_null<QWidget*> toastParent() const override;
[[nodiscard]] bool valid() const override;
operator bool() const override;
private:
const base::weak_ptr<Controller> _window;
};
Show::Show(not_null<Controller*> window)
: _window(base::make_weak(window)) {
}
void Show::showBox(
object_ptr<Ui::BoxContent> content,
Ui::LayerOptions options) const {
if (const auto window = _window.get()) {
window->show(std::move(content), options);
}
}
void Show::hideLayer() const {
if (const auto window = _window.get()) {
window->show(
object_ptr<Ui::BoxContent>{ nullptr },
Ui::LayerOption::CloseOther);
}
}
not_null<QWidget*> Show::toastParent() const {
const auto window = _window.get();
Assert(window != nullptr);
return window->widget()->bodyWidget();
}
bool Show::valid() const {
return !_window.empty();
}
Show::operator bool() const {
return valid();
}
} // namespace
Controller::Controller() : Controller(CreateArgs{}) {
}
@@ -220,13 +275,11 @@ void Controller::checkLockByTerms() {
}
void Controller::showTermsDecline() {
const auto box = show(
Box<Window::TermsBox>(
TextWithEntities{ tr::lng_terms_update_sorry(tr::now) },
tr::lng_terms_decline_and_delete(),
tr::lng_terms_back(),
true),
Ui::LayerOption::KeepOther);
const auto box = show(Box<Window::TermsBox>(
TextWithEntities{ tr::lng_terms_update_sorry(tr::now) },
tr::lng_terms_decline_and_delete(),
tr::lng_terms_back(),
true));
box->agreeClicks(
) | rpl::start_with_next([=] {
@@ -252,14 +305,12 @@ void Controller::showTermsDelete() {
hideLayer();
}
};
show(
Ui::MakeConfirmBox({
.text = tr::lng_terms_delete_warning(),
.confirmed = deleteByTerms,
.confirmText = tr::lng_terms_delete_now(),
.confirmStyle = &st::attentionBoxButton,
}),
Ui::LayerOption::KeepOther);
show(Ui::MakeConfirmBox({
.text = tr::lng_terms_delete_warning(),
.confirmed = deleteByTerms,
.confirmText = tr::lng_terms_delete_now(),
.confirmStyle = &st::attentionBoxButton,
}));
}
void Controller::finishFirstShow() {
@@ -341,8 +392,16 @@ int Controller::verticalShadowTop() const {
: 0;
}
void Controller::showToast(const QString &text) {
Ui::Toast::Show(_widget.bodyWidget(), text);
void Controller::showToast(Ui::Toast::Config &&config) {
Show(this).showToast(std::move(config));
}
void Controller::showToast(TextWithEntities &&text, crl::time duration) {
Show(this).showToast(std::move(text), duration);
}
void Controller::showToast(const QString &text, crl::time duration) {
Show(this).showToast(text, duration);
}
void Controller::showLayer(
@@ -515,6 +574,10 @@ auto Controller::floatPlayerDelegateValue() const
return _floatPlayerDelegate.value();
}
std::shared_ptr<Ui::Show> Controller::uiShow() {
return std::make_shared<Show>(this);
}
rpl::lifetime &Controller::lifetime() {
return _lifetime;
}

View File

@@ -16,6 +16,14 @@ class Account;
class Session;
} // namespace Main
namespace Ui {
class Show;
} // namespace Ui
namespace Ui::Toast {
struct Config;
} // namespace Ui::Toast
namespace Media::View {
struct OpenRequest;
} // namespace Media::View
@@ -87,7 +95,11 @@ public:
showBox(std::move(content), options, animated);
return result;
}
void showToast(const QString &text);
void showToast(Ui::Toast::Config &&config);
void showToast(TextWithEntities &&text, crl::time duration = 0);
void showToast(const QString &text, crl::time duration = 0);
void showLayer(
std::unique_ptr<Ui::LayerWidget> &&layer,
Ui::LayerOptions options,
@@ -131,6 +143,8 @@ public:
[[nodiscard]] auto floatPlayerDelegateValue() const
-> rpl::producer<FloatDelegate*>;
[[nodiscard]] std::shared_ptr<Ui::Show> uiShow();
[[nodiscard]] rpl::lifetime &lifetime();
private:

View File

@@ -243,7 +243,7 @@ void TermsBox::prepare() {
st::termsPadding),
0,
age ? age->height() : 0);
const auto toastParent = Ui::BoxShow(this).toastParent();
const auto show = uiShow();
content->entity()->setClickHandlerFilter([=](
const ClickHandlerPtr &handler,
Qt::MouseButton button) {
@@ -252,8 +252,7 @@ void TermsBox::prepare() {
: QString();
if (TextUtilities::RegExpMention().match(link).hasMatch()) {
_lastClickedMention = link;
Ui::Toast::Show(
toastParent,
show->showToast(
tr::lng_terms_agree_to_proceed(tr::now, lt_bot, link));
return false;
}

View File

@@ -157,7 +157,7 @@ void ShowCallsBox(not_null<Window::SessionController*> window) {
Window::SectionShow(anim::type::instant));
};
const auto clearAll = crl::guard(box, [=] {
Ui::BoxShow(box).showBox(Box(Calls::ClearCallsBox, window));
box->uiShow()->showBox(Box(Calls::ClearCallsBox, window));
});
state->menu->addAction(
tr::lng_settings_section_call_settings(tr::now),

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);

View File

@@ -34,6 +34,10 @@ class MainList;
struct EntryState;
} // namespace Dialogs
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Window {
class Controller;
@@ -119,6 +123,10 @@ QPointer<Ui::BoxContent> ShowChooseRecipientBox(
FnMut<bool(not_null<Data::Thread*>)> &&chosen,
rpl::producer<QString> titleOverride = nullptr,
FnMut<void()> &&successCallback = nullptr);
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
std::shared_ptr<ChatHelpers::Show> show,
Data::ForwardDraft &&draft,
Fn<void()> &&successCallback = nullptr);
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
not_null<Window::SessionNavigation*> navigation,
Data::ForwardDraft &&draft,

View File

@@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document_resolver.h"
#include "data/data_media_types.h"
#include "data/data_session.h"
#include "data/data_file_origin.h"
#include "data/data_folder.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
@@ -64,7 +65,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/message_sending_animation_controller.h"
#include "ui/style/style_palette_colorizer.h"
#include "ui/toast/toast.h"
#include "ui/toasts/common_toasts.h"
#include "calls/calls_instance.h" // Core::App().calls().inCall().
#include "calls/group/calls_group_call.h"
#include "ui/boxes/calendar_box.h"
@@ -109,6 +109,137 @@ constexpr auto kMaxChatEntryHistorySize = 50;
};
}
class MainWindowShow final : public ChatHelpers::Show {
public:
explicit MainWindowShow(not_null<SessionNavigation*> navigation);
void showBox(
object_ptr<Ui::BoxContent> content,
Ui::LayerOptions options
= Ui::LayerOption::KeepOther) const override;
void hideLayer() const override;
not_null<QWidget*> toastParent() const override;
bool valid() const override;
operator bool() const override;
Main::Session &session() const override;
bool paused(ChatHelpers::PauseReason reason) const override;
rpl::producer<> pauseChanged() const override;
rpl::producer<bool> adjustShadowLeft() const override;
SendMenu::Type sendMenuType() const override;
bool showMediaPreview(
Data::FileOrigin origin,
not_null<DocumentData*> document) const override;
bool showMediaPreview(
Data::FileOrigin origin,
not_null<PhotoData*> photo) const override;
void processChosenSticker(
ChatHelpers::FileChosen chosen) const override;
private:
const base::weak_ptr<SessionController> _window;
};
MainWindowShow::MainWindowShow(
not_null<SessionNavigation*> navigation)
: _window(base::make_weak(navigation->parentController())) {
}
void MainWindowShow::showBox(
object_ptr<Ui::BoxContent> content,
Ui::LayerOptions options) const {
if (const auto window = _window.get()) {
window->show(std::move(content), options);
}
}
void MainWindowShow::hideLayer() const {
if (const auto window = _window.get()) {
window->show(
object_ptr<Ui::BoxContent>{ nullptr },
Ui::LayerOption::CloseOther);
}
}
not_null<QWidget*> MainWindowShow::toastParent() const {
const auto window = _window.get();
Assert(window != nullptr);
return window->widget()->bodyWidget();
}
bool MainWindowShow::valid() const {
return !_window.empty();
}
MainWindowShow::operator bool() const {
return valid();
}
Main::Session &MainWindowShow::session() const {
const auto window = _window.get();
Assert(window != nullptr);
return window->session();
}
bool MainWindowShow::paused(ChatHelpers::PauseReason reason) const {
const auto window = _window.get();
return window && window->isGifPausedAtLeastFor(reason);
}
rpl::producer<> MainWindowShow::pauseChanged() const {
const auto window = _window.get();
if (!window) {
return rpl::never<>();
}
return window->gifPauseLevelChanged();
}
rpl::producer<bool> MainWindowShow::adjustShadowLeft() const {
const auto window = _window.get();
if (!window) {
return rpl::single(false);
}
return window->adaptive().value(
) | rpl::map([=] {
return !window->adaptive().isOneColumn();
});
}
SendMenu::Type MainWindowShow::sendMenuType() const {
const auto window = _window.get();
if (!window) {
return SendMenu::Type::Disabled;
}
return window->content()->sendMenuType();
}
bool MainWindowShow::showMediaPreview(
Data::FileOrigin origin,
not_null<DocumentData*> document) const {
const auto window = _window.get();
return window && window->widget()->showMediaPreview(origin, document);
}
bool MainWindowShow::showMediaPreview(
Data::FileOrigin origin,
not_null<PhotoData*> photo) const {
const auto window = _window.get();
return window && window->widget()->showMediaPreview(origin, photo);
}
void MainWindowShow::processChosenSticker(
ChatHelpers::FileChosen chosen) const {
if (const auto window = _window.get()) {
Ui::PostponeCall(window, [=, chosen = std::move(chosen)]() mutable {
window->stickerOrEmojiChosen(std::move(chosen));
});
}
}
} // namespace
void ActivateWindow(not_null<SessionController*> controller) {
@@ -160,8 +291,8 @@ void DateClickHandler::onClick(ClickContext context) const {
}
SessionNavigation::SessionNavigation(not_null<Main::Session*> session)
: _session(session)
, _api(&_session->mtp()) {
: _session(session)
, _api(&_session->mtp()) {
}
SessionNavigation::~SessionNavigation() = default;
@@ -263,12 +394,10 @@ void SessionNavigation::resolveChannelById(
done(channel);
return;
}
const auto fail = [=] {
Ui::ShowMultilineToast({
.parentOverride = Window::Show(this).toastParent(),
.text = { tr::lng_error_post_link_invalid(tr::now) }
});
};
const auto fail = crl::guard(this, [=] {
MainWindowShow(this).showToast(
tr::lng_error_post_link_invalid(tr::now));
});
_api.request(base::take(_resolveRequestId)).cancel();
_resolveRequestId = _api.request(MTPchannels_GetChannels(
MTP_vector<MTPInputChannel>(
@@ -464,12 +593,10 @@ void SessionNavigation::joinVoiceChatFromLink(
const PeerByLinkInfo &info) {
Expects(info.voicechatHash.has_value());
const auto bad = [=] {
Ui::ShowMultilineToast({
.parentOverride = Window::Show(this).toastParent(),
.text = { tr::lng_group_invite_bad_link(tr::now) }
});
};
const auto bad = crl::guard(this, [=] {
MainWindowShow(this).showToast(
tr::lng_group_invite_bad_link(tr::now));
});
const auto hash = *info.voicechatHash;
_api.request(base::take(_resolveRequestId)).cancel();
_resolveRequestId = _api.request(
@@ -603,9 +730,7 @@ void SessionNavigation::showRepliesForMessage(
_showingRepliesRequestId = 0;
if (error.type() == u"CHANNEL_PRIVATE"_q
|| error.type() == u"USER_BANNED_IN_CHANNEL"_q) {
Ui::Toast::Show(
Show(this).toastParent(),
tr::lng_group_not_accessible(tr::now));
showToast(tr::lng_group_not_accessible(tr::now));
}
}).send();
}
@@ -697,6 +822,27 @@ void SessionNavigation::showPollResults(
showSection(std::make_shared<Info::Memento>(poll, contextId), params);
}
auto SessionNavigation::showToast(Ui::Toast::Config &&config)
-> base::weak_ptr<Ui::Toast::Instance> {
return MainWindowShow(this).showToast(std::move(config));
}
auto SessionNavigation::showToast(const QString &text, crl::time duration)
-> base::weak_ptr<Ui::Toast::Instance> {
return MainWindowShow(this).showToast(text);
}
auto SessionNavigation::showToast(
TextWithEntities &&text,
crl::time duration)
-> base::weak_ptr<Ui::Toast::Instance> {
return MainWindowShow(this).showToast(std::move(text));
}
std::shared_ptr<ChatHelpers::Show> SessionNavigation::uiShow() {
return std::make_shared<MainWindowShow>(this);
}
struct SessionController::CachedThemeKey {
Ui::ChatThemeKey theme;
QString paper;
@@ -731,7 +877,7 @@ SessionController::SessionController(
, _tabbedSelector(
std::make_unique<ChatHelpers::TabbedSelector>(
_window->widget(),
this,
uiShow(),
GifPauseReason::TabbedPanel))
, _invitePeekTimer([=] { checkInvitePeek(); })
, _activeChatsFilter(session->data().chatsFilters().defaultId())
@@ -1065,12 +1211,8 @@ void SessionController::setupPremiumToast() {
session().mtp().requestConfig();
return premium;
}) | rpl::start_with_next([=] {
Ui::Toast::Show(
Window::Show(this).toastParent(),
{
.text = { tr::lng_premium_success(tr::now) },
.st = &st::defaultToast,
});
MainWindowShow(this).showToast(
{ tr::lng_premium_success(tr::now) });
}, _lifetime);
}
@@ -1327,14 +1469,6 @@ void SessionController::floatPlayerAreaUpdated() {
}
}
void SessionController::materializeLocalDrafts() {
_materializeLocalDraftsRequests.fire({});
}
rpl::producer<> SessionController::materializeLocalDraftsRequests() const {
return _materializeLocalDraftsRequests.events();
}
int SessionController::dialogsSmallColumnWidth() const {
return st::defaultDialogRow.padding.left()
+ st::defaultDialogRow.photoSize
@@ -1558,14 +1692,9 @@ void SessionController::showPeer(not_null<PeerData*> peer, MsgId msgId) {
&& (!currentPeer->isChannel()
|| currentPeer->asChannel()->linkedChat()
!= clickedChannel)) {
Ui::ShowMultilineToast({
.parentOverride = Window::Show(this).toastParent(),
.text = {
.text = peer->isMegagroup()
? tr::lng_group_not_accessible(tr::now)
: tr::lng_channel_not_accessible(tr::now)
},
});
MainWindowShow(this).showToast(peer->isMegagroup()
? tr::lng_group_not_accessible(tr::now)
: tr::lng_channel_not_accessible(tr::now));
} else {
showPeerHistory(peer->id, SectionShow(), msgId);
}
@@ -1581,10 +1710,7 @@ void SessionController::startOrJoinGroupCall(not_null<PeerData*> peer) {
void SessionController::startOrJoinGroupCall(
not_null<PeerData*> peer,
Calls::StartGroupCallArgs args) {
Core::App().calls().startOrJoinGroupCall(
std::make_shared<Show>(this),
peer,
args);
Core::App().calls().startOrJoinGroupCall(uiShow(), peer, args);
}
void SessionController::showCalendar(Dialogs::Key chat, QDate requestedDate) {
@@ -1963,21 +2089,15 @@ void SessionController::setActiveChatsFilter(
}
void SessionController::showAddContact() {
_window->show(
Box<AddContactBox>(&session()),
Ui::LayerOption::KeepOther);
_window->show(Box<AddContactBox>(&session()));
}
void SessionController::showNewGroup() {
_window->show(
Box<GroupInfoBox>(this, GroupInfoBox::Type::Group),
Ui::LayerOption::KeepOther);
_window->show(Box<GroupInfoBox>(this, GroupInfoBox::Type::Group));
}
void SessionController::showNewChannel() {
_window->show(
Box<GroupInfoBox>(this, GroupInfoBox::Type::Channel),
Ui::LayerOption::KeepOther);
_window->show(Box<GroupInfoBox>(this, GroupInfoBox::Type::Channel));
}
Window::Adaptive &SessionController::adaptive() const {
@@ -2012,13 +2132,6 @@ void SessionController::hideLayer(anim::type animated) {
_window->hideLayer(animated);
}
void SessionController::showToast(TextWithEntities &&text) {
Ui::ShowMultilineToast({
.parentOverride = Window::Show(this).toastParent(),
.text = std::move(text),
});
}
void SessionController::openPhoto(
not_null<PhotoData*> photo,
FullMsgId contextId,
@@ -2376,44 +2489,4 @@ SessionController::~SessionController() {
resetFakeUnreadWhileOpened();
}
Show::Show(not_null<SessionNavigation*> navigation)
: Show(&navigation->parentController()->window()) {
}
Show::Show(Controller *window)
: _window(base::make_weak(window)) {
}
Show::~Show() = default;
void Show::showBox(
object_ptr<Ui::BoxContent> content,
Ui::LayerOptions options) const {
if (const auto window = _window.get()) {
window->show(std::move(content), options);
}
}
void Show::hideLayer() const {
if (const auto window = _window.get()) {
window->show(
object_ptr<Ui::BoxContent>{ nullptr },
Ui::LayerOption::CloseOther);
}
}
not_null<QWidget*> Show::toastParent() const {
const auto window = _window.get();
Assert(window != nullptr);
return window->widget()->bodyWidget();
}
bool Show::valid() const {
return !_window.empty();
}
Show::operator bool() const {
return valid();
}
} // namespace Window

View File

@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/weak_ptr.h"
#include "base/timer.h"
#include "boxes/gift_premium_box.h" // GiftPremiumValidator.
#include "chat_helpers/compose/compose_show.h"
#include "data/data_chat_participant_status.h"
#include "dialogs/dialogs_key.h"
#include "ui/layers/layer_widget.h"
@@ -80,22 +81,14 @@ class CachedIconFactory;
namespace Window {
using GifPauseReason = ChatHelpers::PauseReason;
using GifPauseReasons = ChatHelpers::PauseReasons;
class MainWindow;
class SectionMemento;
class Controller;
class FiltersMenu;
enum class GifPauseReason {
Any = 0,
InlineResults = (1 << 0),
TabbedPanel = (1 << 1),
Layer = (1 << 2),
RoundPlaying = (1 << 3),
MediaPreview = (1 << 4),
};
using GifPauseReasons = base::flags<GifPauseReason>;
inline constexpr bool is_flag_type(GifPauseReason) { return true; };
enum class ResolveType {
Default,
BotApp,
@@ -186,7 +179,7 @@ public:
explicit SessionNavigation(not_null<Main::Session*> session);
virtual ~SessionNavigation();
Main::Session &session() const;
[[nodiscard]] Main::Session &session() const;
virtual void showSection(
std::shared_ptr<SectionMemento> memento,
@@ -276,6 +269,17 @@ public:
FullMsgId contextId,
const SectionShow &params = SectionShow());
base::weak_ptr<Ui::Toast::Instance> showToast(
Ui::Toast::Config &&config);
base::weak_ptr<Ui::Toast::Instance> showToast(
TextWithEntities &&text,
crl::time duration = 0);
base::weak_ptr<Ui::Toast::Instance> showToast(
const QString &text,
crl::time duration = 0);
[[nodiscard]] std::shared_ptr<ChatHelpers::Show> uiShow();
private:
void resolvePhone(
const QString &phone,
@@ -345,8 +349,6 @@ public:
anim::type animated = anim::type::normal);
void hideLayer(anim::type animated = anim::type::normal);
void showToast(TextWithEntities &&text);
[[nodiscard]] auto sendingAnimation() const
-> Ui::MessageSendingAnimationController &;
[[nodiscard]] auto tabbedSelector() const
@@ -406,9 +408,6 @@ public:
bool isGifPausedAtLeastFor(GifPauseReason reason) const;
void floatPlayerAreaUpdated();
void materializeLocalDrafts();
[[nodiscard]] rpl::producer<> materializeLocalDraftsRequests() const;
struct ColumnLayout {
int bodyWidth = 0;
int dialogsWidth = 0;
@@ -696,8 +695,6 @@ private:
QString _premiumRef;
rpl::event_stream<> _materializeLocalDraftsRequests;
rpl::lifetime _lifetime;
};
@@ -711,22 +708,4 @@ void ActivateWindow(not_null<SessionController*> controller);
not_null<SessionController*> controller,
GifPauseReason level);
class Show : public Ui::Show {
public:
explicit Show(not_null<SessionNavigation*> navigation);
explicit Show(Controller *window);
~Show();
void showBox(
object_ptr<Ui::BoxContent> content,
Ui::LayerOptions options = Ui::LayerOption::KeepOther) const override;
void hideLayer() const override;
[[nodiscard]] not_null<QWidget*> toastParent() const override;
[[nodiscard]] bool valid() const override;
operator bool() const override;
private:
const base::weak_ptr<Controller> _window;
};
} // namespace Window