Remove some usages of App::main().

This commit is contained in:
John Preston 2020-06-10 22:08:17 +04:00
parent ea86433be5
commit ee43027bea
53 changed files with 518 additions and 429 deletions

View File

@ -477,7 +477,7 @@ void ApiWrap::importChatInvite(const QString &hash) {
handleChats(data.vchats());
}, [&](auto &&) {
LOG(("API Error: unexpected update cons %1 "
"(MainWidget::inviteImportDone)").arg(result.type()));
"(ApiWrap::importChatInvite)").arg(result.type()));
});
}).fail([=](const RPCError &error) {
const auto &type = error.type();

View File

@ -207,16 +207,16 @@ namespace App {
if (update.paletteChanged()) {
createPaletteCorners();
if (App::main()) {
App::main()->updateScrollColors();
if (const auto m = App::main()) { // multi good
m->updateScrollColors();
}
HistoryView::serviceColorsUpdated();
} else if (update.type == Update::Type::New) {
prepareCorners(StickerCorners, st::dateRadius, st::msgServiceBg);
prepareCorners(StickerSelectedCorners, st::dateRadius, st::msgServiceBgSelected);
if (App::main()) {
App::main()->updateScrollColors();
if (const auto m = App::main()) { // multi good
m->updateScrollColors();
}
HistoryView::serviceColorsUpdated();
}

View File

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document_media.h"
#include "boxes/background_preview_box.h"
#include "boxes/confirm_box.h"
#include "window/window_session_controller.h"
#include "app.h"
#include "styles/style_overview.h"
#include "styles/style_layers.h"
@ -131,8 +132,10 @@ private:
};
BackgroundBox::BackgroundBox(QWidget*, not_null<Main::Session*> session)
: _session(session) {
BackgroundBox::BackgroundBox(
QWidget*,
not_null<Window::SessionController*> controller)
: _controller(controller) {
}
void BackgroundBox::prepare() {
@ -143,13 +146,13 @@ void BackgroundBox::prepare() {
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
_inner = setInnerWidget(
object_ptr<Inner>(this, _session),
object_ptr<Inner>(this, &_controller->session()),
st::backgroundScroll);
_inner->chooseEvents(
) | rpl::start_with_next([=](const Data::WallPaper &paper) {
Ui::show(
Box<BackgroundPreviewBox>(_session, paper),
Box<BackgroundPreviewBox>(_controller, paper),
Ui::LayerOption::KeepOther);
}, _inner->lifetime());
@ -161,7 +164,7 @@ void BackgroundBox::prepare() {
void BackgroundBox::removePaper(const Data::WallPaper &paper) {
const auto box = std::make_shared<QPointer<Ui::BoxContent>>();
const auto session = _session;
const auto session = &_controller->session();
const auto remove = [=, weak = Ui::MakeWeak(this)]{
if (*box) {
(*box)->closeBox();

View File

@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h"
namespace Main {
class Session;
} // namespace Main
namespace Window {
class SessionController;
} // namespace Window
namespace Data {
class WallPaper;
@ -19,7 +19,7 @@ class WallPaper;
class BackgroundBox : public Ui::BoxContent {
public:
BackgroundBox(QWidget*, not_null<Main::Session*> session);
BackgroundBox(QWidget*, not_null<Window::SessionController*> controller);
protected:
void prepare() override;
@ -29,7 +29,7 @@ private:
void removePaper(const Data::WallPaper &paper);
const not_null<Main::Session*> _session;
const not_null<Window::SessionController*> _controller;
QPointer<Inner> _inner;

View File

@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unixtime.h"
#include "boxes/confirm_box.h"
#include "boxes/background_preview_box.h"
#include "window/window_session_controller.h"
#include "app.h"
#include "styles/style_history.h"
#include "styles/style_layers.h"
@ -396,18 +397,18 @@ QImage PrepareScaledFromFull(
BackgroundPreviewBox::BackgroundPreviewBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const Data::WallPaper &paper)
: _session(session)
: _controller(controller)
, _text1(GenerateTextItem(
delegate(),
_session->data().history(
_controller->session().data().history(
peerFromUser(PeerData::kServiceNotificationsId)),
tr::lng_background_text1(tr::now),
false))
, _text2(GenerateTextItem(
delegate(),
_session->data().history(
_controller->session().data().history(
peerFromUser(PeerData::kServiceNotificationsId)),
tr::lng_background_text2(tr::now),
true))
@ -417,7 +418,9 @@ BackgroundPreviewBox::BackgroundPreviewBox(
if (_media) {
_media->thumbnailWanted(_paper.fileOrigin());
}
subscribe(_session->downloaderTaskFinished(), [=] { update(); });
subscribe(_controller->session().downloaderTaskFinished(), [=] {
update();
});
}
not_null<HistoryView::ElementDelegate*> BackgroundPreviewBox::delegate() {
@ -500,9 +503,9 @@ void BackgroundPreviewBox::createBlurCheckbox() {
void BackgroundPreviewBox::apply() {
const auto install = (_paper.id() != Window::Theme::Background()->id())
&& Data::IsCloudWallPaper(_paper);
App::main()->setChatBackground(_paper, std::move(_full));
_controller->content()->setChatBackground(_paper, std::move(_full));
if (install) {
_session->api().request(MTPaccount_InstallWallPaper(
_controller->session().api().request(MTPaccount_InstallWallPaper(
_paper.mtpInput(),
_paper.mtpSettings()
)).send();
@ -763,12 +766,12 @@ void BackgroundPreviewBox::checkLoadedDocument() {
}
bool BackgroundPreviewBox::Start(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const QString &slug,
const QMap<QString, QString> &params) {
if (const auto paper = Data::WallPaper::FromColorSlug(slug)) {
Ui::show(Box<BackgroundPreviewBox>(
session,
controller,
paper->withUrlParams(params)));
return true;
}
@ -776,9 +779,10 @@ bool BackgroundPreviewBox::Start(
Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now)));
return false;
}
session->api().requestWallPaper(slug, [=](const Data::WallPaper &result) {
controller->session().api().requestWallPaper(slug, [=](
const Data::WallPaper &result) {
Ui::show(Box<BackgroundPreviewBox>(
session,
controller,
result.withUrlParams(params)));
}, [](const RPCError &error) {
Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now)));

View File

@ -19,9 +19,9 @@ namespace Data {
class DocumentMedia;
} // namespace Data
namespace Main {
class Session;
} // namespace Main
namespace Window {
class SessionController;
} // namespace Window
namespace Ui {
class Checkbox;
@ -34,11 +34,11 @@ class BackgroundPreviewBox
public:
BackgroundPreviewBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const Data::WallPaper &paper);
static bool Start(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const QString &slug,
const QMap<QString, QString> &params);
@ -71,7 +71,7 @@ private:
void startFadeInFrom(QPixmap previous);
void checkBlurAnimationStart();
const not_null<Main::Session*> _session;
const not_null<Window::SessionController*> _controller;
AdminLog::OwnedItem _text1;
AdminLog::OwnedItem _text2;
Data::WallPaper _paper;

View File

@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unique_qptr.h"
#include "base/event_filter.h"
#include "base/call_delayed.h"
#include "window/window_session_controller.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
#include "styles/style_settings.h"
@ -748,11 +749,11 @@ void Options::checkLastOption() {
CreatePollBox::CreatePollBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
PollData::Flags chosen,
PollData::Flags disabled,
Api::SendType sendType)
: _session(session)
: _controller(controller)
, _chosen(chosen)
, _disabled(disabled)
, _sendType(sendType) {
@ -774,6 +775,7 @@ not_null<Ui::InputField*> CreatePollBox::setupQuestion(
not_null<Ui::VerticalLayout*> container) {
using namespace Settings;
const auto session = &_controller->session();
AddSubsectionTitle(container, tr::lng_polls_create_question());
const auto question = container->add(
object_ptr<Ui::InputField>(
@ -782,7 +784,7 @@ not_null<Ui::InputField*> CreatePollBox::setupQuestion(
Ui::InputField::Mode::MultiLine,
tr::lng_polls_create_question_placeholder()),
st::createPollFieldPadding);
InitField(getDelegate()->outerContainer(), question, _session);
InitField(getDelegate()->outerContainer(), question, session);
question->setMaxLength(kQuestionLimit + kErrorLimit);
question->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
question->customTab(true);
@ -824,6 +826,7 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution(
)->setDuration(0)->toggleOn(std::move(shown));
const auto inner = outer->entity();
const auto session = &_controller->session();
AddSkip(inner);
AddSubsectionTitle(inner, tr::lng_polls_solution_title());
const auto solution = inner->add(
@ -833,14 +836,14 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution(
Ui::InputField::Mode::MultiLine,
tr::lng_polls_solution_placeholder()),
st::createPollFieldPadding);
InitField(getDelegate()->outerContainer(), solution, _session);
InitField(getDelegate()->outerContainer(), solution, session);
solution->setMaxLength(kSolutionLimit + kErrorLimit);
solution->setInstantReplaces(Ui::InstantReplaces::Default());
solution->setInstantReplacesEnabled(
_session->settings().replaceEmojiValue());
session->settings().replaceEmojiValue());
solution->setMarkdownReplacesEnabled(rpl::single(true));
solution->setEditLinkCallback(
DefaultEditLinkCallback(_session, solution));
DefaultEditLinkCallback(_controller, solution));
solution->customTab(true);
const auto warning = CreateWarningLabel(
@ -896,7 +899,7 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
const auto options = lifetime().make_state<Options>(
getDelegate()->outerContainer(),
container,
_session,
&_controller->session(),
(_chosen & PollData::Flag::Quiz));
auto limit = options->usedCount() | rpl::after_next([=](int count) {
setCloseByEscape(!count);
@ -1011,7 +1014,7 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
const auto collectResult = [=] {
using Flag = PollData::Flag;
auto result = PollData(&_session->data(), id);
auto result = PollData(&_controller->session().data(), id);
result.question = question->getLastText().trimmed();
result.answers = options->toPollAnswers();
const auto solutionWithTags = quiz->checked()

View File

@ -18,9 +18,9 @@ namespace Ui {
class VerticalLayout;
} // namespace Ui
namespace Main {
class Session;
} // namespace Main
namespace Window {
class SessionController;
} // namespace Window
class CreatePollBox : public Ui::BoxContent {
public:
@ -31,7 +31,7 @@ public:
CreatePollBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
PollData::Flags chosen,
PollData::Flags disabled,
Api::SendType sendType);
@ -62,7 +62,7 @@ private:
not_null<Ui::VerticalLayout*> container,
rpl::producer<bool> shown);
const not_null<Main::Session*> _session;
const not_null<Window::SessionController*> _controller;
const PollData::Flags _chosen = PollData::Flags();
const PollData::Flags _disabled = PollData::Flags();
const Api::SendType _sendType = Api::SendType();

View File

@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/popup_menu.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/effects/animations.h"
#include "window/window_session_controller.h"
namespace Ui {
namespace {
@ -48,7 +49,7 @@ class Inner : public Ui::RpWidget {
public:
Inner(
QWidget *parent,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
Dictionaries enabledDictionaries);
Dictionaries enabledRows() const;
@ -56,7 +57,7 @@ public:
private:
void setupContent(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
Dictionaries enabledDictionaries);
Dictionaries _enabledRows;
@ -101,10 +102,10 @@ auto CreateMultiSelect(QWidget *parent) {
Inner::Inner(
QWidget *parent,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
Dictionaries enabledDictionaries)
: RpWidget(parent) {
setupContent(session, std::move(enabledDictionaries));
setupContent(controller, std::move(enabledDictionaries));
}
QueryCallback Inner::queryCallback() const {
@ -117,7 +118,7 @@ Dictionaries Inner::enabledRows() const {
auto AddButtonWithLoader(
not_null<Ui::VerticalLayout*> content,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const Spellchecker::Dict &dict,
bool buttonEnabled,
rpl::producer<QStringView> query) {
@ -295,8 +296,8 @@ auto AddButtonWithLoader(
if (toggled && (state.is<Available>() || state.is<Failed>())) {
const auto weak = Ui::MakeWeak(button);
setLocalLoader(base::make_unique_q<Loader>(
App::main(),
session,
controller->content(),
&controller->session(),
id,
Spellchecker::GetDownloadLocation(id),
Spellchecker::DictPathByLangId(id),
@ -346,7 +347,7 @@ auto AddButtonWithLoader(
}
void Inner::setupContent(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
Dictionaries enabledDictionaries) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
@ -357,7 +358,7 @@ void Inner::setupContent(
const auto id = dict.id;
const auto row = AddButtonWithLoader(
content,
session,
controller,
dict,
ranges::contains(enabledDictionaries, id),
queryStream->events());
@ -387,8 +388,8 @@ void Inner::setupContent(
ManageDictionariesBox::ManageDictionariesBox(
QWidget*,
not_null<Main::Session*> session)
: _session(session) {
not_null<Window::SessionController*> controller)
: _controller(controller) {
}
void ManageDictionariesBox::setInnerFocus() {
@ -398,11 +399,12 @@ void ManageDictionariesBox::setInnerFocus() {
void ManageDictionariesBox::prepare() {
const auto multiSelect = CreateMultiSelect(this);
const auto session = &_controller->session();
const auto inner = setInnerWidget(
object_ptr<Inner>(
this,
_session,
_session->settings().dictionariesEnabled()),
_controller,
session->settings().dictionariesEnabled()),
st::boxScroll,
multiSelect->height()
);
@ -420,9 +422,9 @@ void ManageDictionariesBox::prepare() {
setTitle(tr::lng_settings_manage_dictionaries());
addButton(tr::lng_settings_save(), [=] {
_session->settings().setDictionariesEnabled(
session->settings().setDictionariesEnabled(
FilterEnabledDict(inner->enabledRows()));
_session->saveSettingsDelayed();
session->saveSettingsDelayed();
// Ignore boxClosing() when the Save button was pressed.
lifetime().destroy();
closeBox();
@ -430,9 +432,9 @@ void ManageDictionariesBox::prepare() {
addButton(tr::lng_close(), [=] { closeBox(); });
boxClosing() | rpl::start_with_next([=] {
_session->settings().setDictionariesEnabled(
session->settings().setDictionariesEnabled(
FilterEnabledDict(initialEnabledRows));
_session->saveSettingsDelayed();
session->saveSettingsDelayed();
}, lifetime());
setDimensionsToContent(st::boxWidth, inner);

View File

@ -11,9 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h"
namespace Main {
class Session;
} // namespace Main
namespace Window {
class SessionController;
} // namespace Window
namespace Ui {
@ -21,14 +21,14 @@ class ManageDictionariesBox : public Ui::BoxContent {
public:
ManageDictionariesBox(
QWidget*,
not_null<Main::Session*> session);
not_null<Window::SessionController*> controller);
protected:
void prepare() override;
void setInnerFocus() override;
private:
const not_null<Main::Session*> _session;
const not_null<Window::SessionController*> _controller;
Fn<void()> _setInnerFocus;
};

View File

@ -309,9 +309,9 @@ EditCaptionBox::EditCaptionBox(
_controller->session().settings().replaceEmojiValue());
_field->setMarkdownReplacesEnabled(rpl::single(true));
_field->setEditLinkCallback(
DefaultEditLinkCallback(&_controller->session(), _field));
DefaultEditLinkCallback(_controller, _field));
InitSpellchecker(&_controller->session(), _field);
InitSpellchecker(_controller, _field);
auto r = object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
this,

View File

@ -1440,15 +1440,22 @@ void Controller::deleteChannel() {
const auto channel = _peer->asChannel();
const auto chat = channel->migrateFrom();
const auto session = &_peer->session();
Ui::hideLayer();
Ui::showChatsList();
if (chat) {
chat->session().api().deleteConversation(chat, false);
session->api().deleteConversation(chat, false);
}
MTP::send(
MTPchannels_DeleteChannel(channel->inputChannel),
App::main()->rpcDone(&MainWidget::sentUpdatesReceived),
App::main()->rpcFail(&MainWidget::deleteChannelFailed));
session->api().request(MTPchannels_DeleteChannel(
channel->inputChannel
)).done([=](const MTPUpdates &result) {
session->api().applyUpdates(result);
//}).fail([=](const RPCError &error) {
// if (error.type() == qstr("CHANNEL_TOO_LARGE")) {
// Ui::show(Box<InformBox>(tr::lng_cant_delete_channel(tr::now)));
// }
}).send();
}
} // namespace

View File

@ -2069,13 +2069,13 @@ void SendFilesBox::setupCaption() {
_controller->session().settings().replaceEmojiValue());
_caption->setMarkdownReplacesEnabled(rpl::single(true));
_caption->setEditLinkCallback(
DefaultEditLinkCallback(&_controller->session(), _caption));
DefaultEditLinkCallback(_controller, _caption));
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
_caption,
&_controller->session());
InitSpellchecker(&_controller->session(), _caption);
InitSpellchecker(_controller, _caption);
updateCaptionPlaceholder();
setupEmojiPanel();

View File

@ -205,10 +205,10 @@ void ShareBox::prepareCommentField() {
_navigation->session().settings().replaceEmojiValue());
field->setMarkdownReplacesEnabled(rpl::single(true));
field->setEditLinkCallback(
DefaultEditLinkCallback(&_navigation->session(), field));
DefaultEditLinkCallback(_navigation->parentController(), field));
field->setSubmitSettings(_navigation->session().settings().sendSubmitWay());
InitSpellchecker(&_navigation->session(), field);
InitSpellchecker(_navigation->parentController(), field);
Ui::SendPendingMoveResizeEvents(_comment);
}

View File

@ -62,7 +62,7 @@ class EditLinkBox : public Ui::BoxContent {
public:
EditLinkBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const QString &text,
const QString &link,
Fn<void(QString, QString)> callback);
@ -73,7 +73,7 @@ protected:
void prepare() override;
private:
const not_null<Main::Session*> _session;
const not_null<Window::SessionController*> _controller;
QString _startText;
QString _startLink;
Fn<void(QString, QString)> _callback;
@ -111,11 +111,11 @@ QString FieldTagMimeProcessor::tagFromMimeTag(const QString &mimeTag) {
EditLinkBox::EditLinkBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const QString &text,
const QString &link,
Fn<void(QString, QString)> callback)
: _session(session)
: _controller(controller)
, _startText(text)
, _startLink(link)
, _callback(std::move(callback)) {
@ -131,6 +131,7 @@ void EditLinkBox::setInnerFocus() {
void EditLinkBox::prepare() {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
const auto session = &_controller->session();
const auto text = content->add(
object_ptr<Ui::InputField>(
content,
@ -140,12 +141,12 @@ void EditLinkBox::prepare() {
st::markdownLinkFieldPadding);
text->setInstantReplaces(Ui::InstantReplaces::Default());
text->setInstantReplacesEnabled(
_session->settings().replaceEmojiValue());
session->settings().replaceEmojiValue());
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
text,
_session);
InitSpellchecker(_session, text);
session);
InitSpellchecker(_controller, text);
const auto url = content->add(
object_ptr<Ui::InputField>(
@ -249,7 +250,7 @@ Fn<bool(
QString text,
QString link,
EditLinkAction action)> DefaultEditLinkCallback(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field) {
const auto weak = Ui::MakeWeak(field);
return [=](
@ -261,7 +262,7 @@ Fn<bool(
return Ui::InputField::IsValidMarkdownLink(link)
&& !TextUtilities::IsMentionLink(link);
}
Ui::show(Box<EditLinkBox>(session, text, link, [=](
Ui::show(Box<EditLinkBox>(controller, text, link, [=](
const QString &text,
const QString &link) {
if (const auto strong = weak.data()) {
@ -289,20 +290,19 @@ void InitMessageField(
field->setInstantReplacesEnabled(
controller->session().settings().replaceEmojiValue());
field->setMarkdownReplacesEnabled(rpl::single(true));
field->setEditLinkCallback(
DefaultEditLinkCallback(&controller->session(), field));
field->setEditLinkCallback(DefaultEditLinkCallback(controller, field));
}
void InitSpellchecker(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field) {
#ifndef TDESKTOP_DISABLE_SPELLCHECK
const auto s = Ui::CreateChild<Spellchecker::SpellingHighlighter>(
field.get(),
session->settings().spellcheckerEnabledValue(),
controller->session().settings().spellcheckerEnabledValue(),
Spellchecker::SpellingHighlighter::CustomContextMenuItem{
tr::lng_settings_manage_dictionaries(tr::now),
[=] { Ui::show(Box<Ui::ManageDictionariesBox>(session)); }
[=] { Ui::show(Box<Ui::ManageDictionariesBox>(controller)); }
});
field->setExtendedContextMenu(s->contextMenuCreated());
#endif // TDESKTOP_DISABLE_SPELLCHECK

View File

@ -34,14 +34,14 @@ Fn<bool(
QString text,
QString link,
Ui::InputField::EditLinkAction action)> DefaultEditLinkCallback(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field);
void InitMessageField(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field);
void InitSpellchecker(
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field);
bool HasSendText(not_null<const Ui::InputField*> field);

View File

@ -241,7 +241,7 @@ bool ShowWallPaper(
match->captured(1),
qthelp::UrlParamNameTransform::ToLower);
return BackgroundPreviewBox::Start(
session,
App::wnd()->sessionController(),
params.value(qsl("slug")),
params);
}

View File

@ -94,6 +94,7 @@ void CheckForSwitchInlineButton(not_null<HistoryItem*> item) {
using ButtonType = HistoryMessageMarkupButton::Type;
if (button.type == ButtonType::SwitchInline) {
Notify::switchInlineBotButtonReceived(
&item->history()->session(),
QString::fromUtf8(button.data));
return;
}
@ -889,6 +890,25 @@ void Session::chatsListDone(Data::Folder *folder) {
_chatsListLoadedEvents.fire_copy(folder);
}
void Session::userIsBotChanged(not_null<UserData*> user) {
if (const auto history = this->history(user)) {
chatsFilters().refreshHistory(history);
}
_userIsBotChanges.fire_copy(user);
}
rpl::producer<not_null<UserData*>> Session::userIsBotChanges() const {
return _userIsBotChanges.events();
}
void Session::botCommandsChanged(not_null<UserData*> user) {
_botCommandsChanges.fire_copy(user);
}
rpl::producer<not_null<UserData*>> Session::botCommandsChanges() const {
return _botCommandsChanges.events();
}
Storage::Cache::Database &Session::cache() {
return *_cache;
}

View File

@ -200,6 +200,11 @@ public:
void chatsListChanged(Data::Folder *folder);
void chatsListDone(Data::Folder *folder);
void userIsBotChanged(not_null<UserData*> user);
[[nodiscard]] rpl::producer<not_null<UserData*>> userIsBotChanges() const;
void botCommandsChanged(not_null<UserData*> user);
[[nodiscard]] rpl::producer<not_null<UserData*>> botCommandsChanges() const;
struct ItemVisibilityQuery {
not_null<HistoryItem*> item;
not_null<bool*> isVisible;
@ -771,6 +776,8 @@ private:
rpl::variable<bool> _contactsLoaded = false;
rpl::event_stream<Data::Folder*> _chatsListLoadedEvents;
rpl::event_stream<Data::Folder*> _chatsListChanged;
rpl::event_stream<not_null<UserData*>> _userIsBotChanges;
rpl::event_stream<not_null<UserData*>> _botCommandsChanges;
base::Observable<ItemVisibilityQuery> _queryItemVisibility;
rpl::event_stream<IdChange> _itemIdChanges;
rpl::event_stream<not_null<const HistoryItem*>> _itemLayoutChanges;

View File

@ -131,22 +131,15 @@ void UserData::setPhone(const QString &newPhone) {
void UserData::setBotInfoVersion(int version) {
if (version < 0) {
if (botInfo) {
if (!botInfo->commands.isEmpty()) {
botInfo->commands.clear();
Notify::botCommandsChanged(this);
}
botInfo = nullptr;
Notify::userIsBotChanged(this);
}
// We don't support bots becoming non-bots.
} else if (!botInfo) {
botInfo = std::make_unique<BotInfo>();
botInfo->version = version;
Notify::userIsBotChanged(this);
owner().userIsBotChanged(this);
} else if (botInfo->version < version) {
if (!botInfo->commands.isEmpty()) {
botInfo->commands.clear();
Notify::botCommandsChanged(this);
owner().botCommandsChanged(this);
}
botInfo->description.clear();
botInfo->version = version;
@ -199,7 +192,7 @@ void UserData::setBotInfo(const MTPBotInfo &info) {
botInfo->inited = true;
if (changedCommands) {
Notify::botCommandsChanged(this);
owner().botCommandsChanged(this);
}
} break;
}

View File

@ -239,7 +239,7 @@ InnerWidget::InnerWidget(
}
if (update.flags & (UpdateFlag::PhotoChanged | UpdateFlag::UserOccupiedChanged)) {
this->update();
emit App::main()->dialogsUpdated();
emit controller->content()->dialogsUpdated();
}
if (update.flags & UpdateFlag::UserIsContact) {
if (update.peer->isUser()) {
@ -1498,7 +1498,7 @@ void InnerWidget::removeDialog(Key key) {
refresh();
}
emit App::main()->dialogsUpdated();
emit _controller->content()->dialogsUpdated();
refresh();
}
@ -3019,7 +3019,7 @@ void InnerWidget::setupShortcuts() {
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
if (App::main()->selectingPeer()) {
if (_controller->content()->selectingPeer()) {
return;
}
const auto row = _controller->activeChatEntryCurrent();
@ -3059,7 +3059,9 @@ void InnerWidget::setupShortcuts() {
return jumpToDialogRow(last);
});
request->check(Command::ChatSelf) && request->handle([=] {
App::main()->choosePeer(session().userPeerId(), ShowAtUnreadMsgId);
_controller->content()->choosePeer(
session().userPeerId(),
ShowAtUnreadMsgId);
return true;
});
request->check(Command::ShowArchive) && request->handle([=] {

View File

@ -199,10 +199,10 @@ Widget::Widget(
});
_inner->chosenRow(
) | rpl::start_with_next([=](const ChosenRow &row) {
const auto openSearchResult = !App::main()->selectingPeer()
const auto openSearchResult = !controller->content()->selectingPeer()
&& row.filteredRow;
if (const auto history = row.key.history()) {
App::main()->choosePeer(
controller->content()->choosePeer(
history->peer->id,
(controller->uniqueChatsInSearchResults()
? ShowAtUnreadMsgId
@ -642,7 +642,7 @@ void Widget::showAnimated(Window::SlideDirection direction, const Window::Sectio
_cacheUnder = params.oldContentCache;
showFast();
_cacheOver = App::main()->grabForShowAnimation(params);
_cacheOver = controller()->content()->grabForShowAnimation(params);
if (_updateTelegram) {
_updateTelegram->hide();
@ -698,7 +698,7 @@ void Widget::escape() {
} else if (controller()->activeChatsFilterCurrent()) {
controller()->setActiveChatsFilter(FilterId(0));
}
} else if (!_searchInChat && !App::main()->selectingPeer()) {
} else if (!_searchInChat && !controller()->content()->selectingPeer()) {
if (controller()->activeChatEntryCurrent().key) {
emit cancelled();
}
@ -1243,7 +1243,9 @@ bool Widget::peopleFailed(const RPCError &error, mtpRequestId req) {
void Widget::dragEnterEvent(QDragEnterEvent *e) {
using namespace Storage;
if (App::main()->selectingPeer()) return;
if (controller()->content()->selectingPeer()) {
return;
}
const auto data = e->mimeData();
_dragInScroll = false;
@ -1295,9 +1297,9 @@ void Widget::updateDragInScroll(bool inScroll) {
if (_dragInScroll != inScroll) {
_dragInScroll = inScroll;
if (_dragInScroll) {
App::main()->showForwardLayer({});
controller()->content()->showForwardLayer({});
} else {
App::main()->dialogsCancelled();
controller()->content()->dialogsCancelled();
}
}
}
@ -1307,7 +1309,9 @@ void Widget::dropEvent(QDropEvent *e) {
if (_scroll->geometry().contains(e->pos())) {
if (auto peer = _inner->updateFromParentDrag(mapToGlobal(e->pos()))) {
e->acceptProposedAction();
App::main()->onFilesOrForwardDrop(peer->id, e->mimeData());
controller()->content()->onFilesOrForwardDrop(
peer->id,
e->mimeData());
controller()->widget()->activateWindow();
}
}
@ -1556,7 +1560,7 @@ void Widget::updateControlsGeometry() {
right -= _chooseFromUser->width(); _chooseFromUser->moveToLeft(right, _filter->y());
auto scrollTop = filterAreaTop + filterAreaHeight;
auto addToScroll = App::main() ? App::main()->contentScrollAddToY() : 0;
auto addToScroll = controller()->content()->contentScrollAddToY();
auto newScrollTop = _scroll->scrollTop() + addToScroll;
auto scrollHeight = height() - scrollTop;
const auto putBottomButton = [&](object_ptr<BottomButton> &button) {
@ -1589,14 +1593,16 @@ void Widget::updateControlsGeometry() {
}
void Widget::updateForwardBar() {
auto selecting = App::main()->selectingPeer();
auto selecting = controller()->content()->selectingPeer();
auto oneColumnSelecting = (Adaptive::OneColumn() && selecting);
if (!oneColumnSelecting == !_forwardCancel) {
return;
}
if (oneColumnSelecting) {
_forwardCancel.create(this, st::dialogsForwardCancel);
_forwardCancel->setClickedCallback([] { Global::RefPeerChooseCancel().notify(true); });
_forwardCancel->setClickedCallback([] {
Global::RefPeerChooseCancel().notify(true);
});
if (!_a_show.animating()) _forwardCancel->show();
} else {
_forwardCancel.destroyDelayed();
@ -1737,7 +1743,7 @@ bool Widget::onCancelSearch() {
void Widget::onCancelSearchInChat() {
cancelSearchRequest();
if (_searchInChat) {
if (Adaptive::OneColumn() && !App::main()->selectingPeer()) {
if (Adaptive::OneColumn() && !controller()->content()->selectingPeer()) {
if (const auto peer = _searchInChat.peer()) {
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
//} else if (const auto feed = _searchInChat.feed()) { // #feed
@ -1752,7 +1758,7 @@ void Widget::onCancelSearchInChat() {
_filter->clear();
_filter->updatePlaceholder();
applyFilterUpdate();
if (!Adaptive::OneColumn() && !App::main()->selectingPeer()) {
if (!Adaptive::OneColumn() && !controller()->content()->selectingPeer()) {
emit cancelled();
}
}

View File

@ -35,20 +35,27 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace App {
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) {
if (auto m = App::main()) {
m->sendBotCommand(peer, bot, cmd, replyTo);
void sendBotCommand(
not_null<PeerData*> peer,
UserData *bot,
const QString &cmd, MsgId replyTo) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &peer->session()) {
m->sendBotCommand(peer, bot, cmd, replyTo);
}
}
}
void hideSingleUseKeyboard(const HistoryItem *msg) {
if (auto m = App::main()) {
m->hideSingleUseKeyboard(msg->history()->peer, msg->id);
void hideSingleUseKeyboard(not_null<const HistoryItem*> message) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &message->history()->session()) {
m->hideSingleUseKeyboard(message->history()->peer, message->id);
}
}
}
bool insertBotCommand(const QString &cmd) {
if (auto m = App::main()) {
if (const auto m = App::main()) { // multi good
return m->insertBotCommand(cmd);
}
return false;
@ -82,8 +89,10 @@ void activateBotCommand(
case ButtonType::Callback:
case ButtonType::Game: {
if (auto m = App::main()) {
m->app_sendBotCallback(button, msg, row, column);
if (const auto m = App::main()) { // multi good
if (&m->session() == &msg->history()->session()) {
m->app_sendBotCallback(button, msg, row, column);
}
}
} break;
@ -94,7 +103,7 @@ void activateBotCommand(
case ButtonType::Url: {
auto url = QString::fromUtf8(button->data);
auto skipConfirmation = false;
if (auto bot = msg->getMessageBot()) {
if (const auto bot = msg->getMessageBot()) {
if (bot->isVerified()) {
skipConfirmation = true;
}
@ -137,27 +146,34 @@ void activateBotCommand(
chosen |= PollData::Flag::Quiz;
}
}
Window::PeerMenuCreatePoll(msg->history()->peer, chosen, disabled);
if (const auto m = App::main()) { // multi good
if (&m->session() == &msg->history()->session()) {
Window::PeerMenuCreatePoll(m->controller(), msg->history()->peer, chosen, disabled);
}
}
} break;
case ButtonType::SwitchInlineSame:
case ButtonType::SwitchInline: {
if (auto m = App::main()) {
if (auto bot = msg->getMessageBot()) {
auto tryFastSwitch = [bot, &button, msgId = msg->id]() -> bool {
auto samePeer = (button->type == ButtonType::SwitchInlineSame);
if (samePeer) {
Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data), bot, msgId);
return true;
} else if (bot->isBot() && bot->botInfo->inlineReturnPeerId) {
if (Notify::switchInlineBotButtonReceived(QString::fromUtf8(button->data))) {
const auto session = &msg->history()->session();
if (const auto m = App::main()) { // multi good
if (&m->session() == session) {
if (const auto bot = msg->getMessageBot()) {
const auto fastSwitchDone = [&] {
auto samePeer = (button->type == ButtonType::SwitchInlineSame);
if (samePeer) {
Notify::switchInlineBotButtonReceived(session, QString::fromUtf8(button->data), bot, msg->id);
return true;
} else if (bot->isBot() && bot->botInfo->inlineReturnPeerId) {
if (Notify::switchInlineBotButtonReceived(session, QString::fromUtf8(button->data))) {
return true;
}
}
return false;
}();
if (!fastSwitchDone) {
m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data));
}
return false;
};
if (!tryFastSwitch()) {
m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data));
}
}
}
@ -170,20 +186,18 @@ void activateBotCommand(
}
void searchByHashtag(const QString &tag, PeerData *inPeer) {
if (const auto window = App::wnd()) {
if (const auto controller = window->sessionController()) {
if (controller->openedFolder().current()) {
controller->closeFolder();
if (const auto m = App::main()) { // multi good
if (!inPeer || &m->session() == &inPeer->session()) {
if (m->controller()->openedFolder().current()) {
m->controller()->closeFolder();
}
}
Ui::hideSettingsAndLayer();
Core::App().hideMediaView();
if (const auto m = window->mainWidget()) {
Ui::hideSettingsAndLayer();
Core::App().hideMediaView();
m->searchMessages(
tag + ' ',
(inPeer && !inPeer->isUser())
? inPeer->owner().history(inPeer).get()
: Dialogs::Key());
? inPeer->owner().history(inPeer).get()
: Dialogs::Key());
}
}
}
@ -216,8 +230,7 @@ void showPeerProfile(not_null<const History*> history) {
void showPeerHistory(
const PeerId &peer,
MsgId msgId) {
auto ms = crl::now();
if (auto m = App::main()) {
if (const auto m = App::main()) { // multi good
m->ui_showPeerHistory(
peer,
Window::SectionShow::Way::ClearStack,
@ -226,15 +239,22 @@ void showPeerHistory(
}
void showPeerHistoryAtItem(not_null<const HistoryItem*> item) {
showPeerHistory(item->history()->peer->id, item->id);
showPeerHistory(item->history()->peer, item->id);
}
void showPeerHistory(not_null<const History*> history, MsgId msgId) {
showPeerHistory(history->peer->id, msgId);
showPeerHistory(history->peer, msgId);
}
void showPeerHistory(const PeerData *peer, MsgId msgId) {
showPeerHistory(peer->id, msgId);
void showPeerHistory(not_null<const PeerData*> peer, MsgId msgId) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &peer->session()) {
m->ui_showPeerHistory(
peer->id,
Window::SectionShow::Way::ClearStack,
msgId);
}
}
}
PeerData *getPeerForMouseAction() {
@ -254,36 +274,40 @@ bool skipPaintEvent(QWidget *widget, QPaintEvent *event) {
namespace Notify {
void userIsBotChanged(UserData *user) {
if (MainWidget *m = App::main()) m->notify_userIsBotChanged(user);
}
void botCommandsChanged(UserData *user) {
if (MainWidget *m = App::main()) {
m->notify_botCommandsChanged(user);
}
peerUpdatedDelayed(user, PeerUpdate::Flag::BotCommandsChanged);
}
void inlineBotRequesting(bool requesting) {
if (MainWidget *m = App::main()) m->notify_inlineBotRequesting(requesting);
}
void replyMarkupUpdated(const HistoryItem *item) {
if (MainWidget *m = App::main()) {
m->notify_replyMarkupUpdated(item);
void replyMarkupUpdated(not_null<const HistoryItem*> item) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &item->history()->session()) {
m->notify_replyMarkupUpdated(item);
}
}
}
void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) {
if (MainWidget *m = App::main()) {
m->notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop);
void inlineKeyboardMoved(
not_null<const HistoryItem*> item,
int oldKeyboardTop,
int newKeyboardTop) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &item->history()->session()) {
m->notify_inlineKeyboardMoved(
item,
oldKeyboardTop,
newKeyboardTop);
}
}
}
bool switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo) {
if (auto main = App::main()) {
return main->notify_switchInlineBotButtonReceived(query, samePeerBot, samePeerReplyTo);
bool switchInlineBotButtonReceived(
not_null<Main::Session*> session,
const QString &query,
UserData *samePeerBot,
MsgId samePeerReplyTo) {
if (const auto m = App::main()) { // multi good
if (session == &m->session()) {
return m->notify_switchInlineBotButtonReceived(
query,
samePeerBot,
samePeerReplyTo);
}
}
return false;
}

View File

@ -38,7 +38,7 @@ template <typename Guard, typename Lambda>
}
void sendBotCommand(
PeerData *peer,
not_null<PeerData*> peer,
UserData *bot,
const QString &cmd,
MsgId replyTo = 0);
@ -63,7 +63,7 @@ void showPeerProfile(not_null<const History*> history);
void showPeerHistory(const PeerId &peer, MsgId msgId);
void showPeerHistoryAtItem(not_null<const HistoryItem*> item);
void showPeerHistory(const PeerData *peer, MsgId msgId);
void showPeerHistory(not_null<const PeerData*> peer, MsgId msgId);
void showPeerHistory(not_null<const History*> history, MsgId msgId);
inline void showChatsList() {
showPeerHistory(PeerId(0), 0);
@ -81,13 +81,16 @@ enum ClipStopperType {
namespace Notify {
void userIsBotChanged(UserData *user);
void botCommandsChanged(UserData *user);
void inlineBotRequesting(bool requesting);
void replyMarkupUpdated(const HistoryItem *item);
void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop);
bool switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot = nullptr, MsgId samePeerReplyTo = 0);
void replyMarkupUpdated(not_null<const HistoryItem*> item);
void inlineKeyboardMoved(
not_null<const HistoryItem*> item,
int oldKeyboardTop,
int newKeyboardTop);
bool switchInlineBotButtonReceived(
not_null<Main::Session*> session,
const QString &query,
UserData *samePeerBot = nullptr,
MsgId samePeerReplyTo = 0);
void unreadCounterUpdated();

View File

@ -432,7 +432,7 @@ void Widget::paintEvent(QPaintEvent *e) {
//auto ms = crl::now();
//_historyDownShown.step(ms);
SectionWidget::PaintBackground(this, e->rect());
SectionWidget::PaintBackground(controller(), this, e->rect());
}
void Widget::onScroll() {

View File

@ -633,7 +633,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) {
view->draw(p, clip.translated(0, -y), selection, ms);
if (item->hasViews()) {
App::main()->scheduleViewIncrement(item);
_controller->content()->scheduleViewIncrement(item);
}
if (item->isUnreadMention() && !item->isUnreadMedia()) {
readMentions.insert(item);
@ -689,7 +689,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) {
if (_visibleAreaBottom >= middle
&& _visibleAreaTop <= middle) {
if (item->hasViews()) {
App::main()->scheduleViewIncrement(item);
_controller->content()->scheduleViewIncrement(item);
}
if (item->isUnreadMention() && !item->isUnreadMedia()) {
readMentions.insert(item);
@ -1279,9 +1279,6 @@ void HistoryInner::itemRemoved(not_null<const HistoryItem*> item) {
if (_history != item->history() && _migrated != item->history()) {
return;
}
if (!App::main()) {
return;
}
_animatedStickersPlayed.remove(item);
@ -2495,6 +2492,18 @@ void HistoryInner::elementStartStickerLoop(
_animatedStickersPlayed.emplace(view->data());
}
crl::time HistoryInner::elementHighlightTime(not_null<const Element*> view) {
const auto fullAnimMs = _controller->content()->highlightStartTime(
view->data());
if (fullAnimMs > 0) {
const auto now = crl::now();
if (fullAnimMs < now) {
return now - fullAnimMs;
}
}
return 0;
}
void HistoryInner::elementShowPollResults(
not_null<PollData*> poll,
FullMsgId context) {
@ -3117,7 +3126,7 @@ void HistoryInner::deleteItem(FullMsgId itemId) {
void HistoryInner::deleteItem(not_null<HistoryItem*> item) {
if (auto message = item->toHistoryMessage()) {
if (message->uploading()) {
App::main()->cancelUploadLayer(item);
_controller->content()->cancelUploadLayer(item);
return;
}
}
@ -3331,20 +3340,12 @@ not_null<HistoryView::ElementDelegate*> HistoryInner::ElementDelegate() {
replacing);
}
bool elementUnderCursor(
not_null<const HistoryView::Element*> view) override {
not_null<const Element*> view) override {
return (App::hoveredItem() == view);
}
crl::time elementHighlightTime(
not_null<const HistoryView::Element*> view) override {
const auto fullAnimMs = App::main()->highlightStartTime(
view->data());
if (fullAnimMs > 0) {
const auto now = crl::now();
if (fullAnimMs < now) {
return now - fullAnimMs;
}
}
return crl::time(0);
not_null<const Element*> view) override {
return Instance ? Instance->elementHighlightTime(view) : 0;
}
bool elementInSelectionMode() override {
return Instance ? Instance->inSelectionMode() : false;

View File

@ -83,6 +83,8 @@ public:
int from,
int till) const;
void elementStartStickerLoop(not_null<const Element*> view);
[[nodiscard]] crl::time elementHighlightTime(
not_null<const Element*> view);
void elementShowPollResults(
not_null<PollData*> poll,
FullMsgId context);

View File

@ -134,14 +134,6 @@ constexpr auto kCommonModifiers = 0
| Qt::ControlModifier;
const auto kPsaAboutPrefix = "cloud_lng_about_psa_";
ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() {
return [](ChannelData *channel, MsgId msgId) {
if (App::main()) {
App::main()->messageDataReceived(channel, msgId);
}
};
}
void ActivateWindow(not_null<Window::SessionController*> controller) {
const auto window = controller->widget();
window->activateWindow();
@ -416,7 +408,7 @@ HistoryWidget::HistoryWidget(
}
Unexpected("action in MimeData hook.");
});
InitSpellchecker(&controller->session(), _field);
InitSpellchecker(controller, _field);
const auto suggestions = Ui::Emoji::SuggestionsController::Init(
this,
@ -520,6 +512,25 @@ HistoryWidget::HistoryWidget(
}
}, lifetime());
session().data().userIsBotChanges(
) | rpl::filter([=](not_null<UserData*> user) {
return (_peer == user.get());
}) | rpl::start_with_next([=](not_null<UserData*> user) {
_list->notifyIsBotChanged();
_list->updateBotInfo();
updateControlsVisibility();
updateControlsGeometry();
}, lifetime());
session().data().botCommandsChanges(
) | rpl::filter([=](not_null<UserData*> user) {
return _peer && (_peer == user || !_peer->isUser());
}) | rpl::start_with_next([=](not_null<UserData*> user) {
if (_fieldAutocomplete->clearFilteredBotCommands()) {
onCheckFieldAutocomplete();
}
}, lifetime());
subscribe(Media::Player::instance()->switchToNextNotifier(), [this](const Media::Player::Instance::Switch &pair) {
if (pair.from.type() == AudioMsgId::Type::Voice) {
scrollToCurrentVoiceMessage(pair.from.contextId(), pair.to);
@ -1030,7 +1041,7 @@ void HistoryWidget::onHashtagOrBotCommandInsert(
// Send bot command at once, if it was not inserted by pressing Tab.
if (str.at(0) == '/' && method != FieldAutocomplete::ChooseMethod::ByTab) {
App::sendBotCommand(_peer, nullptr, str, replyToId());
App::main()->finishForwarding(Api::SendAction(_history));
controller()->content()->finishForwarding(Api::SendAction(_history));
setFieldText(_field->getTextWithTagsPart(_field->textCursor().position()));
} else {
_field->insertTag(str);
@ -1045,14 +1056,12 @@ void HistoryWidget::updateInlineBotQuery() {
if (_inlineBotUsername != query.username) {
_inlineBotUsername = query.username;
if (_inlineBotResolveRequestId) {
// Notify::inlineBotRequesting(false);
MTP::cancel(_inlineBotResolveRequestId);
_inlineBotResolveRequestId = 0;
}
if (query.lookingUpBot) {
_inlineBot = nullptr;
_inlineLookingUpBot = true;
// Notify::inlineBotRequesting(true);
_inlineBotResolveRequestId = MTP::send(
MTPcontacts_ResolveUsername(MTP_string(_inlineBotUsername)),
rpcDone(&HistoryWidget::inlineBotResolveDone),
@ -1085,6 +1094,10 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) {
UserData *bot) {
sendInlineResult(result, bot);
});
_inlineResults->requesting(
) | rpl::start_with_next([=](bool requesting) {
_tabbedSelectorToggle->setLoading(requesting);
}, _inlineResults->lifetime());
updateControlsGeometry();
orderWidgets();
}
@ -1217,9 +1230,7 @@ void HistoryWidget::saveFieldToHistoryLocalDraft() {
}
void HistoryWidget::onCloudDraftSave() {
if (App::main()) {
App::main()->saveDraftToCloud();
}
controller()->content()->saveDraftToCloud();
}
void HistoryWidget::writeDrafts(Data::Draft **localDraft, Data::Draft **editDraft) {
@ -1423,27 +1434,15 @@ void HistoryWidget::onRecordUpdate(quint16 level, qint32 samples) {
}
}
void HistoryWidget::notify_botCommandsChanged(UserData *user) {
if (_peer && (_peer == user || !_peer->isUser())) {
if (_fieldAutocomplete->clearFilteredBotCommands()) {
onCheckFieldAutocomplete();
}
}
}
void HistoryWidget::notify_inlineBotRequesting(bool requesting) {
_tabbedSelectorToggle->setLoading(requesting);
}
void HistoryWidget::notify_replyMarkupUpdated(const HistoryItem *item) {
void HistoryWidget::notify_replyMarkupUpdated(not_null<const HistoryItem*> item) {
if (_keyboard->forMsgId() == item->fullId()) {
updateBotKeyboard(item->history(), true);
}
}
void HistoryWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) {
void HistoryWidget::notify_inlineKeyboardMoved(not_null<const HistoryItem*> item, int oldKeyboardTop, int newKeyboardTop) {
if (_history == item->history() || _migrated == item->history()) {
if (int move = _list->moveScrollFollowingInlineKeyboard(item, oldKeyboardTop, newKeyboardTop)) {
if (const auto move = _list->moveScrollFollowingInlineKeyboard(item, oldKeyboardTop, newKeyboardTop)) {
_addToScroll = move;
}
}
@ -1480,18 +1479,6 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U
return false;
}
void HistoryWidget::notify_userIsBotChanged(UserData *user) {
if (const auto history = session().data().history(user)) {
session().data().chatsFilters().refreshHistory(history);
}
if (_peer && _peer == user) {
_list->notifyIsBotChanged();
_list->updateBotInfo();
updateControlsVisibility();
updateControlsGeometry();
}
}
void HistoryWidget::setupShortcuts() {
Shortcuts::Requests(
) | rpl::filter([=] {
@ -1502,7 +1489,7 @@ void HistoryWidget::setupShortcuts() {
using Command = Shortcuts::Command;
if (_history) {
request->check(Command::Search, 1) && request->handle([=] {
App::main()->searchInChat(_history);
controller()->content()->searchInChat(_history);
return true;
});
if (session().supportMode()) {
@ -1631,10 +1618,7 @@ void HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) {
if (_editMsgId || _replyToId) {
updateReplyEditTexts();
if (!_replyEditMsg) {
session().api().requestMessageData(
_peer->asChannel(),
_editMsgId ? _editMsgId : _replyToId,
replyEditMessageDataCallback());
requestMessageData(_editMsgId ? _editMsgId : _replyToId);
}
}
}
@ -1751,9 +1735,7 @@ void HistoryWidget::showHistory(
// Removing focus from list clears selected and updates top bar.
setFocus();
}
if (App::main()) {
App::main()->saveDraftToCloud();
}
controller()->content()->saveDraftToCloud();
if (_migrated) {
_migrated->clearLocalDraft(); // use migrated draft only once
_migrated->clearEditDraft();
@ -3040,7 +3022,7 @@ void HistoryWidget::saveEditMsgDone(History *history, const MTPUpdates &updates,
if (auto editDraft = history->editDraft()) {
if (editDraft->saveRequestId == req) {
history->clearEditDraft();
if (App::main()) App::main()->writeDrafts(history);
controller()->content()->writeDrafts(history);
}
}
}
@ -3135,8 +3117,8 @@ void HistoryWidget::send(Api::SendOptions options) {
if (!_keyboard->hasMarkup() && _keyboard->forceReply() && !_kbReplyTo) {
toggleKeyboard();
}
App::main()->historyToDown(_history);
App::main()->dialogsToUp();
controller()->content()->historyToDown(_history);
controller()->content()->dialogsToUp();
}
void HistoryWidget::sendWithModifiers(Qt::KeyboardModifiers modifiers) {
@ -3284,7 +3266,7 @@ void HistoryWidget::showAnimated(
historyDownAnimationFinish();
unreadMentionsAnimationFinish();
_topShadow->setVisible(params.withTopBarShadow ? false : true);
_cacheOver = App::main()->grabForShowAnimation(params);
_cacheOver = controller()->content()->grabForShowAnimation(params);
if (_tabbedPanel) {
_tabbedPanel->hideFast();
@ -3550,8 +3532,12 @@ void HistoryWidget::stopRecording(bool send) {
_send->setRecordActive(false);
}
void HistoryWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) { // replyTo != 0 from ReplyKeyboardMarkup, == 0 from cmd links
if (!_peer || _peer != peer) {
void HistoryWidget::sendBotCommand(
not_null<PeerData*> peer,
UserData *bot,
const QString &cmd,
MsgId replyTo) { // replyTo != 0 from ReplyKeyboardMarkup, == 0 from cmd links
if (_peer != peer.get()) {
return;
} else if (showSlowmodeError()) {
return;
@ -3853,7 +3839,6 @@ void HistoryWidget::inlineBotResolveDone(
_inlineBotResolveRequestId = 0;
const auto &data = result.c_contacts_resolvedPeer();
// Notify::inlineBotRequesting(false);
const auto resolvedBot = [&]() -> UserData* {
if (const auto result = session().data().processUsers(data.vusers())) {
if (result->isBot()
@ -3881,7 +3866,6 @@ bool HistoryWidget::inlineBotResolveFail(QString name, const RPCError &error) {
}
_inlineBotResolveRequestId = 0;
// Notify::inlineBotRequesting(false);
if (name == _inlineBotUsername) {
clearInlineBot();
}
@ -4840,9 +4824,9 @@ void HistoryWidget::sendFileConfirmed(
session().data().sendHistoryChangeNotifications();
if (_peer && file->to.peer == _peer->id) {
App::main()->historyToDown(_history);
controller()->content()->historyToDown(_history);
}
App::main()->dialogsToUp();
controller()->content()->dialogsToUp();
}
void HistoryWidget::photoUploaded(
@ -5044,7 +5028,7 @@ void HistoryWidget::updateControlsGeometry() {
}
}
updateHistoryGeometry(false, false, { ScrollChangeAdd, App::main() ? App::main()->contentScrollAddToY() : 0 });
updateHistoryGeometry(false, false, { ScrollChangeAdd, controller()->content()->contentScrollAddToY() });
updateFieldSize();
@ -5574,7 +5558,7 @@ void HistoryWidget::mousePressEvent(QMouseEvent *e) {
} else if (_inReplyEditForward) {
if (readyToForward()) {
const auto items = std::move(_toForward);
App::main()->cancelForwarding(_history);
controller()->content()->cancelForwarding(_history);
auto list = ranges::view::all(
items
) | ranges::view::transform(
@ -5872,10 +5856,7 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() {
updatePinnedBar();
}
if (!_pinnedBar->msg) {
session().api().requestMessageData(
_peer->asChannel(),
_pinnedBar->msgId,
replyEditMessageDataCallback());
requestMessageData(_pinnedBar->msgId);
}
} else if (_pinnedBar) {
destroyPinnedBar();
@ -5889,6 +5870,16 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() {
return result;
}
void HistoryWidget::requestMessageData(MsgId msgId) {
const auto callback = [=](ChannelData *channel, MsgId msgId) {
messageDataReceived(channel, msgId);
};
session().api().requestMessageData(
_peer->asChannel(),
msgId,
crl::guard(this, callback));
}
void HistoryWidget::destroyPinnedBar() {
_pinnedBar.reset();
_inPinnedMsg = false;
@ -6017,7 +6008,7 @@ void HistoryWidget::replyToMessage(not_null<HistoryItem*> item) {
} else {
const auto itemId = item->fullId();
Ui::show(Box<ConfirmBox>(tr::lng_reply_cant_forward(tr::now), tr::lng_selected_forward(tr::now), crl::guard(this, [=] {
App::main()->setForwardDraft(
controller()->content()->setForwardDraft(
_peer->id,
{ 1, itemId });
})));
@ -6025,7 +6016,7 @@ void HistoryWidget::replyToMessage(not_null<HistoryItem*> item) {
return;
}
App::main()->cancelForwarding(_history);
controller()->content()->cancelForwarding(_history);
if (_editMsgId) {
if (auto localDraft = _history->localDraft()) {
@ -6296,7 +6287,7 @@ void HistoryWidget::cancelFieldAreaState() {
} else if (_editMsgId) {
cancelEdit();
} else if (readyToForward()) {
App::main()->cancelForwarding(_history);
controller()->content()->cancelForwarding(_history);
} else if (_replyToId) {
cancelReply();
} else if (_kbReplyTo) {
@ -7030,7 +7021,7 @@ void HistoryWidget::paintEvent(QPaintEvent *e) {
updateListSize();
}
Window::SectionWidget::PaintBackground(this, e->rect());
Window::SectionWidget::PaintBackground(controller(), this, e->rect());
Painter p(this);
const auto clip = e->rect();

View File

@ -182,7 +182,6 @@ public:
void unpinMessage(FullMsgId itemId);
MsgId replyToId() const;
void messageDataReceived(ChannelData *channel, MsgId msgId);
bool lastForceReplyReplied(const FullMsgId &replyTo) const;
bool lastForceReplyReplied() const;
bool cancelReply(bool lastKeyboardUsed = false);
@ -204,7 +203,11 @@ public:
void escape();
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo);
void sendBotCommand(
not_null<PeerData*> peer,
UserData *bot,
const QString &cmd,
MsgId replyTo);
void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo);
bool insertBotCommand(const QString &cmd);
@ -270,12 +273,10 @@ public:
PeerData *ui_getPeerForMouseAction();
void notify_botCommandsChanged(UserData *user);
void notify_inlineBotRequesting(bool requesting);
void notify_replyMarkupUpdated(const HistoryItem *item);
void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop);
void notify_replyMarkupUpdated(not_null<const HistoryItem*> item);
void notify_inlineKeyboardMoved(not_null<const HistoryItem*> item, int oldKeyboardTop, int newKeyboardTop);
bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo);
void notify_userIsBotChanged(UserData *user);
~HistoryWidget();
@ -376,6 +377,9 @@ private:
void setTabbedPanel(std::unique_ptr<TabbedPanel> panel);
void updateField();
void requestMessageData(MsgId msgId);
void messageDataReceived(ChannelData *channel, MsgId msgId);
void send(Api::SendOptions options);
void sendWithModifiers(Qt::KeyboardModifiers modifiers);
void sendSilent();

View File

@ -852,7 +852,7 @@ void ScheduledWidget::paintEvent(QPaintEvent *e) {
//auto ms = crl::now();
//_historyDownShown.step(ms);
SectionWidget::PaintBackground(this, e->rect());
SectionWidget::PaintBackground(controller(), this, e->rect());
}
void ScheduledWidget::onScroll() {

View File

@ -145,7 +145,6 @@ TopBarWidget::TopBarWidget(
lifetime());
setCursor(style::cur_pointer);
updateControlsVisibility();
}
TopBarWidget::~TopBarWidget() = default;
@ -182,7 +181,7 @@ void TopBarWidget::refreshLang() {
void TopBarWidget::onSearch() {
if (_activeChat) {
App::main()->searchInChat(_activeChat);
_controller->content()->searchInChat(_activeChat);
}
}
@ -620,7 +619,7 @@ void TopBarWidget::updateControlsVisibility() {
_sendNow->setVisible(_canSendNow);
auto backVisible = Adaptive::OneColumn()
|| (App::main() && !App::main()->stackIsEmpty())
|| !_controller->content()->stackIsEmpty()
|| _activeChat.folder();
_back->setVisible(backVisible);
if (_info) {
@ -653,11 +652,8 @@ void TopBarWidget::updateControlsVisibility() {
}
void TopBarWidget::updateMembersShowArea() {
if (!App::main()) {
return;
}
auto membersShowAreaNeeded = [this]() {
auto peer = App::main()->peer();
const auto membersShowAreaNeeded = [&] {
auto peer = _controller->content()->peer();
if ((_selectedCount > 0) || !peer) {
return false;
}
@ -668,8 +664,8 @@ void TopBarWidget::updateMembersShowArea() {
return megagroup->canViewMembers() && (megagroup->membersCount() < Global::ChatSizeMax());
}
return false;
};
if (!membersShowAreaNeeded()) {
}();
if (!membersShowAreaNeeded) {
if (_membersShowArea) {
_membersShowAreaActive.fire(false);
_membersShowArea.destroy();

View File

@ -51,7 +51,7 @@ public:
not_null<Window::SessionController*> controller);
~TopBarWidget();
Main::Session &session() const;
[[nodiscard]] Main::Session &session() const;
void updateControlsVisibility();
void finishAnimating();

View File

@ -1019,7 +1019,9 @@ bool Widget::overlaps(const QRect &globalRect) const {
}
void Widget::inlineBotChanged() {
if (!_inlineBot) return;
if (!_inlineBot) {
return;
}
if (!isHidden() && !_hiding) {
hideAnimated();
@ -1033,12 +1035,12 @@ void Widget::inlineBotChanged() {
_inner->inlineBotChanged();
_inner->hideInlineRowsPanel();
Notify::inlineBotRequesting(false);
_requesting.fire(false);
}
void Widget::inlineResultsDone(const MTPmessages_BotResults &result) {
_inlineRequestId = 0;
Notify::inlineBotRequesting(false);
_requesting.fire(false);
auto it = _inlineCache.find(_inlineQuery);
auto adding = (it != _inlineCache.cend());
@ -1104,7 +1106,7 @@ void Widget::queryInlineBot(UserData *bot, PeerData *peer, QString query) {
if (_inlineRequestId) {
MTP::cancel(_inlineRequestId);
_inlineRequestId = 0;
Notify::inlineBotRequesting(false);
_requesting.fire(false);
}
if (_inlineCache.find(query) != _inlineCache.cend()) {
_inlineRequestTimer.stop();
@ -1129,7 +1131,7 @@ void Widget::onInlineRequest() {
return;
}
}
Notify::inlineBotRequesting(true);
_requesting.fire(true);
_inlineRequestId = _api.request(MTPmessages_GetInlineBotResults(
MTP_flags(0),
_inlineBot->inputUser,
@ -1141,7 +1143,7 @@ void Widget::onInlineRequest() {
inlineResultsDone(result);
}).fail([=](const RPCError &error) {
// show error?
Notify::inlineBotRequesting(false);
_requesting.fire(false);
_inlineRequestId = 0;
}).handleAllErrors().send();
}

View File

@ -199,6 +199,10 @@ public:
_inner->setResultSelectedCallback(std::move(callback));
}
[[nodiscard]] rpl::producer<bool> requesting() const {
return _requesting.events();
}
~Widget();
protected:
@ -276,6 +280,8 @@ private:
QString _inlineQuery, _inlineNextQuery, _inlineNextOffset;
mtpRequestId _inlineRequestId = 0;
rpl::event_stream<bool> _requesting;
};
} // namespace Layout

View File

@ -525,6 +525,10 @@ Main::Session &MainWidget::session() const {
return _controller->session();
}
not_null<Window::SessionController*> MainWidget::controller() const {
return _controller;
}
void MainWidget::setupConnectingWidget() {
using namespace rpl::mappers;
_connecting = std::make_unique<Window::ConnectionState>(
@ -772,19 +776,11 @@ void MainWidget::onFilesOrForwardDrop(
}
}
void MainWidget::notify_botCommandsChanged(UserData *bot) {
_history->notify_botCommandsChanged(bot);
}
void MainWidget::notify_inlineBotRequesting(bool requesting) {
_history->notify_inlineBotRequesting(requesting);
}
void MainWidget::notify_replyMarkupUpdated(const HistoryItem *item) {
void MainWidget::notify_replyMarkupUpdated(not_null<const HistoryItem*> item) {
_history->notify_replyMarkupUpdated(item);
}
void MainWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) {
void MainWidget::notify_inlineKeyboardMoved(not_null<const HistoryItem*> item, int oldKeyboardTop, int newKeyboardTop) {
_history->notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop);
}
@ -792,10 +788,6 @@ bool MainWidget::notify_switchInlineBotButtonReceived(const QString &query, User
return _history->notify_switchInlineBotButtonReceived(query, samePeerBot, samePeerReplyTo);
}
void MainWidget::notify_userIsBotChanged(UserData *bot) {
_history->notify_userIsBotChanged(bot);
}
void MainWidget::clearHider(not_null<Window::HistoryHider*> instance) {
if (_hider != instance) {
return;
@ -1010,7 +1002,11 @@ MsgId MainWidget::currentReplyToIdFor(not_null<History*> history) const {
return 0;
}
void MainWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) {
void MainWidget::sendBotCommand(
not_null<PeerData*> peer,
UserData *bot,
const QString &cmd,
MsgId replyTo) {
_history->sendBotCommand(peer, bot, cmd, replyTo);
}
@ -1435,10 +1431,6 @@ Image *MainWidget::newBackgroundThumb() {
: nullptr;
}
void MainWidget::messageDataReceived(ChannelData *channel, MsgId msgId) {
_history->messageDataReceived(channel, msgId);
}
void MainWidget::updateBotKeyboard(History *h) {
_history->updateBotKeyboard(h);
}
@ -2180,16 +2172,6 @@ void MainWidget::sentUpdatesReceived(uint64 randomId, const MTPUpdates &result)
feedUpdates(result, randomId);
}
bool MainWidget::deleteChannelFailed(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
//if (error.type() == qstr("CHANNEL_TOO_LARGE")) {
// Ui::show(Box<InformBox>(tr::lng_cant_delete_channel(tr::now)));
//}
return true;
}
void MainWidget::historyToDown(History *history) {
_history->historyToDown(history);
}
@ -2984,7 +2966,11 @@ void MainWidget::gotDifference(const MTPupdates_Difference &difference) {
};
}
bool MainWidget::getDifferenceTimeChanged(ChannelData *channel, int32 ms, ChannelGetDifferenceTime &channelCurTime, crl::time &curTime) {
bool MainWidget::getDifferenceTimeChanged(
ChannelData *channel,
int32 ms,
ChannelGetDifferenceTime &channelCurTime,
crl::time &curTime) {
if (channel) {
if (ms <= 0) {
ChannelGetDifferenceTime::iterator i = channelCurTime.find(channel);
@ -3133,11 +3119,11 @@ void MainWidget::getDifferenceAfterFail() {
}
void MainWidget::getDifference() {
if (this != App::main()) return;
_getDifferenceTimeByPts = 0;
if (requestingDifference()) return;
if (requestingDifference()) {
return;
}
_bySeqUpdates.clear();
_bySeqTimer.cancel();
@ -3158,9 +3144,9 @@ void MainWidget::getDifference() {
rpcFail(&MainWidget::failDifference));
}
void MainWidget::getChannelDifference(ChannelData *channel, ChannelDifferenceRequest from) {
if (this != App::main() || !channel) return;
void MainWidget::getChannelDifference(
not_null<ChannelData*> channel,
ChannelDifferenceRequest from) {
if (from != ChannelDifferenceRequest::PtsGapOrShortPoll) {
_channelGetDifferenceTimeByPts.remove(channel);
}
@ -3187,8 +3173,8 @@ void MainWidget::getChannelDifference(ChannelData *channel, ChannelDifferenceReq
filter,
MTP_int(channel->pts()),
MTP_int(kChannelGetDifferenceLimit)),
rpcDone(&MainWidget::gotChannelDifference, channel),
rpcFail(&MainWidget::failChannelDifference, channel));
rpcDone(&MainWidget::gotChannelDifference, channel.get()),
rpcFail(&MainWidget::failChannelDifference, channel.get()));
}
void MainWidget::sendPing() {
@ -4628,7 +4614,7 @@ namespace App {
MainWidget *main() {
if (const auto window = wnd()) {
return window->mainWidget();
return window->sessionContent();
}
return nullptr;
}

View File

@ -113,6 +113,7 @@ public:
not_null<Window::SessionController*> controller);
[[nodiscard]] Main::Session &session() const;
[[nodiscard]] not_null<Window::SessionController*> controller() const;
[[nodiscard]] bool isMainSectionShown() const;
[[nodiscard]] bool isThirdSectionShown() const;
@ -149,7 +150,6 @@ public:
void sentUpdatesReceived(const MTPUpdates &updates) {
return sentUpdatesReceived(0, updates);
}
bool deleteChannelFailed(const RPCError &error);
void historyToDown(History *hist);
void dialogsToUp();
void checkHistoryActivation();
@ -211,7 +211,11 @@ public:
MsgId currentReplyToIdFor(not_null<History*> history) const;
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo);
void sendBotCommand(
not_null<PeerData*> peer,
UserData *bot,
const QString &cmd,
MsgId replyTo);
void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo);
bool insertBotCommand(const QString &cmd);
@ -233,7 +237,6 @@ public:
void checkChatBackground();
Image *newBackgroundThumb();
void messageDataReceived(ChannelData *channel, MsgId msgId);
void updateBotKeyboard(History *h);
void pushReplyReturn(not_null<HistoryItem*> item);
@ -284,12 +287,9 @@ public:
MsgId msgId);
PeerData *ui_getPeerForMouseAction();
void notify_botCommandsChanged(UserData *bot);
void notify_inlineBotRequesting(bool requesting);
void notify_replyMarkupUpdated(const HistoryItem *item);
void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop);
void notify_replyMarkupUpdated(not_null<const HistoryItem*> item);
void notify_inlineKeyboardMoved(not_null<const HistoryItem*> item, int oldKeyboardTop, int newKeyboardTop);
bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo);
void notify_userIsBotChanged(UserData *bot);
void closeBothPlayers();
@ -381,7 +381,9 @@ private:
void saveSectionInStack();
void getChannelDifference(ChannelData *channel, ChannelDifferenceRequest from = ChannelDifferenceRequest::Unknown);
void getChannelDifference(
not_null<ChannelData*> channel,
ChannelDifferenceRequest from = ChannelDifferenceRequest::Unknown);
void gotDifference(const MTPupdates_Difference &diff);
bool failDifference(const RPCError &e);
void feedDifference(const MTPVector<MTPUser> &users, const MTPVector<MTPChat> &chats, const MTPVector<MTPMessage> &msgs, const MTPVector<MTPUpdate> &other);

View File

@ -405,8 +405,8 @@ void MainWindow::ui_removeLayerBlackout() {
}
}
MainWidget *MainWindow::mainWidget() {
return _main;
MainWidget *MainWindow::sessionContent() const {
return _main.data();
}
void MainWindow::ui_showBox(

View File

@ -56,11 +56,7 @@ public:
void setupIntro();
void setupMain();
MainWidget *chatsWidget() {
return mainWidget();
}
MainWidget *mainWidget();
MainWidget *sessionContent() const;
[[nodiscard]] bool doWeMarkAsRead();

View File

@ -62,6 +62,7 @@ struct PeerUpdate {
UserHasCalls = (1 << 27),
UserOccupiedChanged = (1 << 28),
UserSupportInfoChanged = (1 << 29),
UserIsBotChanged = (1 << 30),
// For channels
ChannelAmIn = (1 << 19),

View File

@ -313,7 +313,7 @@ void SetupSpellchecker(
Spellchecker::ButtonManageDictsState(session),
st::settingsButton
)->addClickHandler([=] {
Ui::show(Box<Ui::ManageDictionariesBox>(session));
Ui::show(Box<Ui::ManageDictionariesBox>(controller));
});
button->toggledValue(

View File

@ -393,7 +393,7 @@ private:
};
void ChooseFromFile(
not_null<::Main::Session*> session,
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent);
BackgroundRow::BackgroundRow(
@ -409,10 +409,10 @@ BackgroundRow::BackgroundRow(
updateImage();
_chooseFromGallery->addClickHandler([=] {
Ui::show(Box<BackgroundBox>(&controller->session()));
Ui::show(Box<BackgroundBox>(controller));
});
_chooseFromFile->addClickHandler([=] {
ChooseFromFile(&controller->session(), this);
ChooseFromFile(controller, this);
});
using Update = const Window::Theme::BackgroundUpdate;
@ -594,7 +594,7 @@ void BackgroundRow::updateImage() {
}
void ChooseFromFile(
not_null<::Main::Session*> session,
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) {
const auto &imgExtensions = cImgExtensions();
auto filters = QStringList(
@ -602,7 +602,7 @@ void ChooseFromFile(
+ imgExtensions.join(qsl(" *"))
+ qsl(")"));
filters.push_back(FileDialog::AllFilesFilter());
const auto callback = crl::guard(session, [=](
const auto callback = crl::guard(controller, [=](
const FileDialog::OpenResult &result) {
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
return;
@ -629,7 +629,7 @@ void ChooseFromFile(
auto local = Data::CustomWallPaper();
local.setLocalImageAsThumbnail(std::make_shared<Image>(
std::move(image)));
Ui::show(Box<BackgroundPreviewBox>(session, local));
Ui::show(Box<BackgroundPreviewBox>(controller, local));
});
FileDialog::GetOpenPath(
parent.get(),

View File

@ -681,8 +681,8 @@ rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionsDescription()
}
ForwardsPrivacyController::ForwardsPrivacyController(
not_null<::Main::Session*> session)
: _session(session) {
not_null<Window::SessionController*> controller)
: _controller(controller) {
}
ApiWrap::Privacy::Key ForwardsPrivacyController::key() {
@ -735,7 +735,7 @@ object_ptr<Ui::RpWidget> ForwardsPrivacyController::setupAboveWidget(
auto message = GenerateForwardedItem(
delegate(),
_session->data().history(
_controller->session().data().history(
peerFromUser(PeerData::kServiceNotificationsId)),
tr::lng_edit_privacy_forwards_sample_message(tr::now));
const auto view = message.get();
@ -760,7 +760,7 @@ object_ptr<Ui::RpWidget> ForwardsPrivacyController::setupAboveWidget(
widget->paintRequest(
) | rpl::start_with_next([=](QRect rect) {
Window::SectionWidget::PaintBackground(widget, rect);
Window::SectionWidget::PaintBackground(_controller, widget, rect);
Painter p(widget);
p.translate(0, padding + view->marginBottom());

View File

@ -12,6 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_element.h"
#include "mtproto/sender.h"
namespace Window {
class SessionController;
} // namespace Window
namespace Settings {
class BlockedBoxController
@ -168,7 +172,8 @@ public:
using Option = EditPrivacyBox::Option;
using Exception = EditPrivacyBox::Exception;
explicit ForwardsPrivacyController(not_null<::Main::Session*> session);
explicit ForwardsPrivacyController(
not_null<Window::SessionController*> controller);
Key key() override;
MTPInputPrivacyKey apiKey() override;
@ -195,7 +200,7 @@ private:
not_null<HistoryView::Element*> view,
Option value);
const not_null<::Main::Session*> _session;
const not_null<Window::SessionController*> _controller;
};

View File

@ -164,7 +164,7 @@ void SetupPrivacy(
add(
tr::lng_settings_forwards_privacy(),
Key::Forwards,
[=] { return std::make_unique<ForwardsPrivacyController>(session); });
[=] { return std::make_unique<ForwardsPrivacyController>(controller); });
add(
tr::lng_settings_profile_photo_privacy(),
Key::ProfilePhoto,

View File

@ -48,7 +48,7 @@ class EditInfoBox : public Ui::BoxContent {
public:
EditInfoBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const TextWithTags &text,
Fn<void(TextWithTags, Fn<void(bool success)>)> submit);
@ -57,7 +57,7 @@ protected:
void setInnerFocus() override;
private:
not_null<Main::Session*> _session;
const not_null<Window::SessionController*> _controller;
object_ptr<Ui::InputField> _field = { nullptr };
Fn<void(TextWithTags, Fn<void(bool success)>)> _submit;
@ -65,10 +65,10 @@ private:
EditInfoBox::EditInfoBox(
QWidget*,
not_null<Main::Session*> session,
not_null<Window::SessionController*> controller,
const TextWithTags &text,
Fn<void(TextWithTags, Fn<void(bool success)>)> submit)
: _session(session)
: _controller(controller)
, _field(
this,
st::supportInfoField,
@ -77,12 +77,13 @@ EditInfoBox::EditInfoBox(
text)
, _submit(std::move(submit)) {
_field->setMaxLength(kMaxSupportInfoLength);
_field->setSubmitSettings(session->settings().sendSubmitWay());
_field->setSubmitSettings(
controller->session().settings().sendSubmitWay());
_field->setInstantReplaces(Ui::InstantReplaces::Default());
_field->setInstantReplacesEnabled(
session->settings().replaceEmojiValue());
controller->session().settings().replaceEmojiValue());
_field->setMarkdownReplacesEnabled(rpl::single(true));
_field->setEditLinkCallback(DefaultEditLinkCallback(session, _field));
_field->setEditLinkCallback(DefaultEditLinkCallback(controller, _field));
}
void EditInfoBox::prepare() {
@ -106,7 +107,7 @@ void EditInfoBox::prepare() {
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
_field,
_session);
&_controller->session());
auto cursor = _field->textCursor();
cursor.movePosition(QTextCursor::End);
@ -427,9 +428,10 @@ void Helper::refreshInfo(not_null<UserData*> user) {
user->inputUser
)).done([=](const MTPhelp_UserInfo &result) {
applyInfo(user, result);
if (_userInfoEditPending.contains(user)) {
_userInfoEditPending.erase(user);
showEditInfoBox(user);
if (const auto controller = _userInfoEditPending.take(user)) {
if (const auto strong = controller->get()) {
showEditInfoBox(strong, user);
}
}
}).send();
}
@ -497,14 +499,18 @@ UserInfo Helper::infoCurrent(not_null<UserData*> user) const {
return (i != end(_userInformation)) ? i->second : UserInfo();
}
void Helper::editInfo(not_null<UserData*> user) {
void Helper::editInfo(
not_null<Window::SessionController*> controller,
not_null<UserData*> user) {
if (!_userInfoEditPending.contains(user)) {
_userInfoEditPending.emplace(user);
_userInfoEditPending.emplace(user, controller.get());
refreshInfo(user);
}
}
void Helper::showEditInfoBox(not_null<UserData*> user) {
void Helper::showEditInfoBox(
not_null<Window::SessionController*> controller,
not_null<UserData*> user) {
const auto info = infoCurrent(user);
const auto editData = TextWithTags{
info.text.text,
@ -518,7 +524,7 @@ void Helper::showEditInfoBox(not_null<UserData*> user) {
}, done);
};
Ui::show(
Box<EditInfoBox>(&user->session(), editData, save),
Box<EditInfoBox>(controller, editData, save),
Ui::LayerOption::KeepOther);
}

View File

@ -59,7 +59,9 @@ public:
rpl::producer<TextWithEntities> infoTextValue(
not_null<UserData*> user) const;
UserInfo infoCurrent(not_null<UserData*> user) const;
void editInfo(not_null<UserData*> user);
void editInfo(
not_null<Window::SessionController*> controller,
not_null<UserData*> user);
Templates &templates();
@ -80,7 +82,9 @@ private:
void applyInfo(
not_null<UserData*> user,
const MTPhelp_UserInfo &result);
void showEditInfoBox(not_null<UserData*> user);
void showEditInfoBox(
not_null<Window::SessionController*> controller,
not_null<UserData*> user);
void saveInfo(
not_null<UserData*> user,
TextWithEntities text,
@ -98,7 +102,9 @@ private:
base::flat_map<not_null<History*>, TimeId> _occupiedChats;
base::flat_map<not_null<UserData*>, UserInfo> _userInformation;
base::flat_set<not_null<UserData*>> _userInfoEditPending;
base::flat_map<
not_null<UserData*>,
base::weak_ptr<Window::SessionController>> _userInfoEditPending;
base::flat_map<not_null<UserData*>, SavingInfo> _userInfoSaving;
rpl::lifetime _lifetime;

View File

@ -84,17 +84,20 @@ QPixmap SectionWidget::grabForShowAnimation(
return Ui::GrabWidget(this);
}
void SectionWidget::PaintBackground(not_null<QWidget*> widget, QRect clip) {
void SectionWidget::PaintBackground(
not_null<Window::SessionController*> controller,
not_null<QWidget*> widget,
QRect clip) {
Painter p(widget);
auto fill = QRect(0, 0, widget->width(), App::main()->height());
auto fill = QRect(0, 0, widget->width(), controller->content()->height());
if (const auto color = Window::Theme::Background()->colorForFill()) {
p.fillRect(fill, *color);
return;
}
auto fromy = App::main()->backgroundFromY();
auto fromy = controller->content()->backgroundFromY();
auto x = 0, y = 0;
auto cached = App::main()->cachedBackground(fill, x, y);
auto cached = controller->content()->cachedBackground(fill, x, y);
if (cached.isNull()) {
if (Window::Theme::Background()->tile()) {
auto &pix = Window::Theme::Background()->pixmapForTiled();

View File

@ -44,6 +44,9 @@ public:
}
[[nodiscard]] Main::Session &session() const;
[[nodiscard]] not_null<Window::SessionController*> controller() const {
return _controller;
}
// Tabbed selector management.
virtual bool pushTabbedSelectorToThirdSection(
@ -63,11 +66,6 @@ public:
return mapToGlobal(rect());
}
protected:
[[nodiscard]] not_null<Window::SessionController*> controller() const {
return _controller;
}
private:
const not_null<Window::SessionController*> _controller;
@ -88,7 +86,9 @@ struct SectionSlideParams {
class SectionWidget : public AbstractSectionWidget {
public:
SectionWidget(QWidget *parent, not_null<Window::SessionController*> controller);
SectionWidget(
QWidget *parent,
not_null<Window::SessionController*> controller);
virtual Dialogs::RowDescriptor activeChat() const {
return {};
@ -140,7 +140,10 @@ public:
return nullptr;
}
static void PaintBackground(not_null<QWidget*> widget, QRect clip);
static void PaintBackground(
not_null<Window::SessionController*> controller,
not_null<QWidget*> widget,
QRect clip);
protected:
void paintEvent(QPaintEvent *e) override;

View File

@ -135,7 +135,7 @@ MainMenu::MainMenu(
setAttribute(Qt::WA_OpaquePaintEvent);
const auto showSelfChat = [=] {
App::main()->choosePeer(
controller->content()->choosePeer(
_controller->session().userPeerId(),
ShowAtUnreadMsgId);
};
@ -143,7 +143,7 @@ MainMenu::MainMenu(
const auto folder = _controller->session().data().folderLoaded(
Data::Folder::kId);
if (folder) {
App::wnd()->sessionController()->openFolder(folder);
controller->openFolder(folder);
Ui::hideSettingsAndLayer();
}
};

View File

@ -460,7 +460,7 @@ void Filler::addUserActions(not_null<UserData*> user) {
if (_source != PeerMenuSource::ChatsList) {
if (user->session().supportMode()) {
_addAction("Edit support info", [=] {
user->session().supportHelper().editInfo(user);
user->session().supportHelper().editInfo(controller, user);
});
}
if (!user->isContact() && !user->isSelf() && !user->isBot()) {
@ -490,7 +490,7 @@ void Filler::addUserActions(not_null<UserData*> user) {
if (user->canSendPolls()) {
_addAction(
tr::lng_polls_create(tr::now),
[=] { PeerMenuCreatePoll(user); });
[=] { PeerMenuCreatePoll(controller, user); });
}
if (user->canExportChatHistory()) {
_addAction(
@ -528,7 +528,7 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
if (chat->canSendPolls()) {
_addAction(
tr::lng_polls_create(tr::now),
[=] { PeerMenuCreatePoll(chat); });
[=] { PeerMenuCreatePoll(controller, chat); });
}
if (chat->canExportChatHistory()) {
_addAction(
@ -574,7 +574,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
if (channel->canSendPolls()) {
_addAction(
tr::lng_polls_create(tr::now),
[=] { PeerMenuCreatePoll(channel); });
[=] { PeerMenuCreatePoll(navigation, channel); });
}
if (channel->canExportChatHistory()) {
_addAction(
@ -790,6 +790,7 @@ void PeerMenuShareContactBox(
}
void PeerMenuCreatePoll(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
PollData::Flags chosen,
PollData::Flags disabled) {
@ -798,7 +799,7 @@ void PeerMenuCreatePoll(
disabled |= PollData::Flag::PublicVotes;
}
const auto box = Ui::show(Box<CreatePollBox>(
&peer->session(),
controller,
chosen,
disabled,
Api::SendType::Normal));
@ -811,7 +812,7 @@ void PeerMenuCreatePoll(
auto action = Api::SendAction(peer->owner().history(peer));
action.clearDraft = false;
action.options = result.options;
if (const auto id = App::main()->currentReplyToIdFor(action.history)) {
if (const auto id = controller->content()->currentReplyToIdFor(action.history)) {
action.replyTo = id;
}
if (const auto localDraft = action.history->localDraft()) {
@ -919,7 +920,8 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
auto callback = [
ids = std::move(items),
callback = std::move(successCallback),
weak
weak,
navigation
](not_null<PeerData*> peer) mutable {
if (peer->isSelf()) {
auto items = peer->owner().idsToItems(ids);
@ -932,7 +934,7 @@ QPointer<Ui::RpWidget> ShowForwardMessagesBox(
Ui::Toast::Show(tr::lng_share_done(tr::now));
});
}
} else if (!App::main()->setForwardDraft(peer->id, std::move(ids))) {
} else if (!navigation->parentController()->content()->setForwardDraft(peer->id, std::move(ids))) {
return;
}
if (const auto strong = *weak) {

View File

@ -62,6 +62,7 @@ void PeerMenuAddChannelMembers(
not_null<ChannelData*> channel);
//void PeerMenuUngroupFeed(not_null<Data::Feed*> feed); // #feed
void PeerMenuCreatePoll(
not_null<Window::SessionController*> controller,
not_null<PeerData*> peer,
PollData::Flags chosen = PollData::Flags(),
PollData::Flags disabled = PollData::Flags());

View File

@ -158,7 +158,7 @@ auto SessionController::tabbedSelector() const
void SessionController::takeTabbedSelectorOwnershipFrom(
not_null<QWidget*> parent) {
if (_tabbedSelector->parent() == parent) {
if (const auto chats = widget()->chatsWidget()) {
if (const auto chats = widget()->sessionContent()) {
chats->returnTabbedSelector();
}
if (_tabbedSelector->parent() == parent) {
@ -395,7 +395,7 @@ bool SessionController::forceWideDialogs() const {
} else if (dialogsListFocused().value()) {
return true;
}
return !App::main()->isMainSectionShown();
return !content()->isMainSectionShown();
}
auto SessionController::computeColumnLayout() const -> ColumnLayout {
@ -499,7 +499,7 @@ bool SessionController::canShowThirdSectionWithoutResize() const {
}
bool SessionController::takeThirdSectionFromLayer() {
return App::wnd()->takeThirdSectionFromLayer();
return widget()->takeThirdSectionFromLayer();
}
void SessionController::resizeForThirdSection() {
@ -682,14 +682,14 @@ void SessionController::clearPassportForm() {
}
void SessionController::updateColumnLayout() {
App::main()->updateColumnLayout();
content()->updateColumnLayout();
}
void SessionController::showPeerHistory(
PeerId peerId,
const SectionShow &params,
MsgId msgId) {
App::main()->ui_showPeerHistory(
content()->ui_showPeerHistory(
peerId,
params,
msgId);
@ -718,30 +718,30 @@ void SessionController::showPeerHistory(
void SessionController::showSection(
SectionMemento &&memento,
const SectionShow &params) {
if (!params.thirdColumn && App::wnd()->showSectionInExistingLayer(
if (!params.thirdColumn && widget()->showSectionInExistingLayer(
&memento,
params)) {
return;
}
App::main()->showSection(std::move(memento), params);
content()->showSection(std::move(memento), params);
}
void SessionController::showBackFromStack(const SectionShow &params) {
chats()->showBackFromStack(params);
content()->showBackFromStack(params);
}
void SessionController::showSpecialLayer(
object_ptr<Ui::LayerWidget> &&layer,
anim::type animated) {
App::wnd()->showSpecialLayer(std::move(layer), animated);
widget()->showSpecialLayer(std::move(layer), animated);
}
void SessionController::removeLayerBlackout() {
App::wnd()->ui_removeLayerBlackout();
widget()->ui_removeLayerBlackout();
}
not_null<MainWidget*> SessionController::chats() const {
return App::wnd()->chatsWidget();
not_null<MainWidget*> SessionController::content() const {
return widget()->sessionContent();
}
void SessionController::setDefaultFloatPlayerDelegate(

View File

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/flags.h"
#include "base/observer.h"
#include "base/object_ptr.h"
#include "base/weak_ptr.h"
#include "dialogs/dialogs_key.h"
#include "ui/effects/animation_value.h"
@ -163,6 +164,7 @@ private:
class SessionController
: public SessionNavigation
, public base::has_weak_ptr
, private base::Subscriber {
public:
SessionController(
@ -173,6 +175,7 @@ public:
return *_window;
}
[[nodiscard]] not_null<::MainWindow*> widget() const;
[[nodiscard]] not_null<MainWidget*> content() const;
[[nodiscard]] auto tabbedSelector() const
-> not_null<ChatHelpers::TabbedSelector*>;
@ -314,7 +317,6 @@ private:
void checkOpenedFilter();
int minimalThreeColumnWidth() const;
not_null<MainWidget*> chats() const;
int countDialogsWidthFromRatio(int bodyWidth) const;
int countThirdColumnWidthFromRatio(int bodyWidth) const;
struct ShrinkResult {