mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Remove some more Auth() calls.
This commit is contained in:
parent
ff44094ded
commit
137fa0378c
59 changed files with 840 additions and 460 deletions
|
@ -314,9 +314,8 @@ namespace App {
|
|||
void quit() {
|
||||
if (quitting()) {
|
||||
return;
|
||||
} else if (Main::Session::Exists()
|
||||
&& Auth().data().exportInProgress()) {
|
||||
Auth().data().stopExportWithConfirmation([] { App::quit(); });
|
||||
} else if (Core::IsAppLaunched()
|
||||
&& Core::App().exportPreventsQuit()) {
|
||||
return;
|
||||
}
|
||||
setLaunchState(QuitRequested);
|
||||
|
|
|
@ -29,8 +29,10 @@ constexpr auto kDefaultLimit = 10 * kMegabyte;
|
|||
|
||||
AutoDownloadBox::AutoDownloadBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
Data::AutoDownload::Source source)
|
||||
: _source(source) {
|
||||
: _session(session)
|
||||
, _source(source) {
|
||||
}
|
||||
|
||||
void AutoDownloadBox::prepare() {
|
||||
|
@ -45,7 +47,7 @@ void AutoDownloadBox::setupContent() {
|
|||
|
||||
setTitle(tr::lng_media_auto_title());
|
||||
|
||||
const auto settings = &Auth().settings().autoDownload();
|
||||
const auto settings = &_session->settings().autoDownload();
|
||||
const auto checked = [=](Source source, Type type) {
|
||||
return (settings->bytesLimit(source, type) > 0);
|
||||
};
|
||||
|
@ -166,11 +168,11 @@ void AutoDownloadBox::setupContent() {
|
|||
Local::writeUserSettings();
|
||||
}
|
||||
if (allowMoreTypes.contains(Type::Photo)) {
|
||||
Auth().data().photoLoadSettingsChanged();
|
||||
_session->data().photoLoadSettingsChanged();
|
||||
}
|
||||
if (ranges::find_if(allowMoreTypes, _1 != Type::Photo)
|
||||
!= allowMoreTypes.end()) {
|
||||
Auth().data().documentLoadSettingsChanged();
|
||||
_session->data().documentLoadSettingsChanged();
|
||||
}
|
||||
closeBox();
|
||||
});
|
||||
|
|
|
@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "boxes/abstract_box.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Data {
|
||||
namespace AutoDownload {
|
||||
enum class Source;
|
||||
|
@ -17,7 +21,10 @@ enum class Source;
|
|||
|
||||
class AutoDownloadBox : public BoxContent {
|
||||
public:
|
||||
AutoDownloadBox(QWidget*, Data::AutoDownload::Source source);
|
||||
AutoDownloadBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
Data::AutoDownload::Source source);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
@ -25,6 +32,8 @@ protected:
|
|||
private:
|
||||
void setupContent();
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
Data::AutoDownload::Source _source;
|
||||
|
||||
};
|
||||
|
|
|
@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/checkbox.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
AutoLockBox::AutoLockBox(QWidget*, not_null<Main::Session*> session)
|
||||
: _session(session) {
|
||||
}
|
||||
|
||||
void AutoLockBox::prepare() {
|
||||
setTitle(tr::lng_passcode_autolock());
|
||||
|
||||
|
@ -39,6 +43,6 @@ void AutoLockBox::durationChanged(int seconds) {
|
|||
Local::writeUserSettings();
|
||||
Global::RefLocalPasscodeChanged().notify();
|
||||
|
||||
Auth().checkAutoLock();
|
||||
_session->checkAutoLock();
|
||||
closeBox();
|
||||
}
|
||||
|
|
|
@ -9,14 +9,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "boxes/abstract_box.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Ui {
|
||||
class Radiobutton;
|
||||
} // namespace Ui
|
||||
|
||||
class AutoLockBox : public BoxContent {
|
||||
public:
|
||||
AutoLockBox(QWidget*) {
|
||||
}
|
||||
AutoLockBox(QWidget*, not_null<Main::Session*> session);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
@ -24,6 +27,8 @@ protected:
|
|||
private:
|
||||
void durationChanged(int seconds);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
std::vector<object_ptr<Ui::Radiobutton>> _options;
|
||||
|
||||
};
|
||||
|
|
|
@ -54,7 +54,9 @@ class BackgroundBox::Inner
|
|||
, private MTP::Sender
|
||||
, private base::Subscriber {
|
||||
public:
|
||||
Inner(QWidget *parent);
|
||||
Inner(
|
||||
QWidget *parent,
|
||||
not_null<Main::Session*> session);
|
||||
|
||||
rpl::producer<Data::WallPaper> chooseEvents() const;
|
||||
rpl::producer<Data::WallPaper> removeRequests() const;
|
||||
|
@ -107,6 +109,8 @@ private:
|
|||
int row) const;
|
||||
void validatePaperThumbnail(const Paper &paper) const;
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
std::vector<Paper> _papers;
|
||||
|
||||
Selection _over;
|
||||
|
@ -118,7 +122,8 @@ private:
|
|||
|
||||
};
|
||||
|
||||
BackgroundBox::BackgroundBox(QWidget*) {
|
||||
BackgroundBox::BackgroundBox(QWidget*, not_null<Main::Session*> session)
|
||||
: _session(session) {
|
||||
}
|
||||
|
||||
void BackgroundBox::prepare() {
|
||||
|
@ -128,11 +133,15 @@ void BackgroundBox::prepare() {
|
|||
|
||||
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
||||
|
||||
_inner = setInnerWidget(object_ptr<Inner>(this), st::backgroundScroll);
|
||||
_inner = setInnerWidget(
|
||||
object_ptr<Inner>(this, _session),
|
||||
st::backgroundScroll);
|
||||
|
||||
_inner->chooseEvents(
|
||||
) | rpl::start_with_next([](const Data::WallPaper &paper) {
|
||||
Ui::show(Box<BackgroundPreviewBox>(paper), LayerOption::KeepOther);
|
||||
) | rpl::start_with_next([=](const Data::WallPaper &paper) {
|
||||
Ui::show(
|
||||
Box<BackgroundPreviewBox>(_session, paper),
|
||||
LayerOption::KeepOther);
|
||||
}, _inner->lifetime());
|
||||
|
||||
_inner->removeRequests(
|
||||
|
@ -143,6 +152,7 @@ void BackgroundBox::prepare() {
|
|||
|
||||
void BackgroundBox::removePaper(const Data::WallPaper &paper) {
|
||||
const auto box = std::make_shared<QPointer<BoxContent>>();
|
||||
const auto session = _session;
|
||||
const auto remove = [=, weak = make_weak(this)]{
|
||||
if (*box) {
|
||||
(*box)->closeBox();
|
||||
|
@ -150,8 +160,8 @@ void BackgroundBox::removePaper(const Data::WallPaper &paper) {
|
|||
if (weak) {
|
||||
weak->_inner->removePaper(paper);
|
||||
}
|
||||
Auth().data().removeWallpaper(paper);
|
||||
Auth().api().request(MTPaccount_SaveWallPaper(
|
||||
session->data().removeWallpaper(paper);
|
||||
session->api().request(MTPaccount_SaveWallPaper(
|
||||
paper.mtpInput(),
|
||||
MTP_bool(true),
|
||||
paper.mtpSettings()
|
||||
|
@ -166,17 +176,21 @@ void BackgroundBox::removePaper(const Data::WallPaper &paper) {
|
|||
LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
BackgroundBox::Inner::Inner(QWidget *parent) : RpWidget(parent)
|
||||
BackgroundBox::Inner::Inner(
|
||||
QWidget *parent,
|
||||
not_null<Main::Session*> session)
|
||||
: RpWidget(parent)
|
||||
, _session(session)
|
||||
, _check(std::make_unique<Ui::RoundCheckbox>(st::overviewCheck, [=] { update(); })) {
|
||||
_check->setChecked(true, Ui::RoundCheckbox::SetStyle::Fast);
|
||||
if (Auth().data().wallpapers().empty()) {
|
||||
if (_session->data().wallpapers().empty()) {
|
||||
resize(st::boxWideWidth, 2 * (st::backgroundSize.height() + st::backgroundPadding) + st::backgroundPadding);
|
||||
} else {
|
||||
updatePapers();
|
||||
}
|
||||
requestPapers();
|
||||
|
||||
subscribe(Auth().downloaderTaskFinished(), [=] { update(); });
|
||||
subscribe(_session->downloaderTaskFinished(), [=] { update(); });
|
||||
using Update = Window::Theme::BackgroundUpdate;
|
||||
subscribe(Window::Theme::Background(), [=](const Update &update) {
|
||||
if (update.paletteChanged()) {
|
||||
|
@ -192,9 +206,9 @@ BackgroundBox::Inner::Inner(QWidget *parent) : RpWidget(parent)
|
|||
|
||||
void BackgroundBox::Inner::requestPapers() {
|
||||
request(MTPaccount_GetWallPapers(
|
||||
MTP_int(Auth().data().wallpapersHash())
|
||||
MTP_int(_session->data().wallpapersHash())
|
||||
)).done([=](const MTPaccount_WallPapers &result) {
|
||||
if (Auth().data().updateWallpapers(result)) {
|
||||
if (_session->data().updateWallpapers(result)) {
|
||||
updatePapers();
|
||||
}
|
||||
}).send();
|
||||
|
@ -220,7 +234,7 @@ void BackgroundBox::Inner::sortPapers() {
|
|||
void BackgroundBox::Inner::updatePapers() {
|
||||
_over = _overDown = Selection();
|
||||
|
||||
_papers = Auth().data().wallpapers(
|
||||
_papers = _session->data().wallpapers(
|
||||
) | ranges::view::filter([](const Data::WallPaper &paper) {
|
||||
return !paper.isPattern() || paper.backgroundColor().has_value();
|
||||
}) | ranges::view::transform([](const Data::WallPaper &paper) {
|
||||
|
|
|
@ -9,13 +9,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "boxes/abstract_box.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Data {
|
||||
class WallPaper;
|
||||
} // namespace Data
|
||||
|
||||
class BackgroundBox : public BoxContent {
|
||||
public:
|
||||
BackgroundBox(QWidget*);
|
||||
BackgroundBox(QWidget*, not_null<Main::Session*> session);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
@ -25,6 +29,8 @@ private:
|
|||
|
||||
void removePaper(const Data::WallPaper &paper);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
QPointer<Inner> _inner;
|
||||
|
||||
};
|
||||
|
|
|
@ -387,20 +387,24 @@ QImage PrepareScaledFromFull(
|
|||
|
||||
BackgroundPreviewBox::BackgroundPreviewBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const Data::WallPaper &paper)
|
||||
: _text1(GenerateTextItem(
|
||||
: _session(session)
|
||||
, _text1(GenerateTextItem(
|
||||
delegate(),
|
||||
Auth().data().history(peerFromUser(PeerData::kServiceNotificationsId)),
|
||||
_session->data().history(
|
||||
peerFromUser(PeerData::kServiceNotificationsId)),
|
||||
tr::lng_background_text1(tr::now),
|
||||
false))
|
||||
, _text2(GenerateTextItem(
|
||||
delegate(),
|
||||
Auth().data().history(peerFromUser(PeerData::kServiceNotificationsId)),
|
||||
_session->data().history(
|
||||
peerFromUser(PeerData::kServiceNotificationsId)),
|
||||
tr::lng_background_text2(tr::now),
|
||||
true))
|
||||
, _paper(paper)
|
||||
, _radial([=](crl::time now) { radialAnimationCallback(now); }) {
|
||||
subscribe(Auth().downloaderTaskFinished(), [=] { update(); });
|
||||
subscribe(_session->downloaderTaskFinished(), [=] { update(); });
|
||||
}
|
||||
|
||||
not_null<HistoryView::ElementDelegate*> BackgroundPreviewBox::delegate() {
|
||||
|
@ -483,7 +487,7 @@ void BackgroundPreviewBox::apply() {
|
|||
&& Data::IsCloudWallPaper(_paper);
|
||||
App::main()->setChatBackground(_paper, std::move(_full));
|
||||
if (install) {
|
||||
Auth().api().request(MTPaccount_InstallWallPaper(
|
||||
_session->api().request(MTPaccount_InstallWallPaper(
|
||||
_paper.mtpInput(),
|
||||
_paper.mtpSettings()
|
||||
)).send();
|
||||
|
@ -736,18 +740,23 @@ void BackgroundPreviewBox::checkLoadedDocument() {
|
|||
}
|
||||
|
||||
bool BackgroundPreviewBox::Start(
|
||||
not_null<Main::Session*> session,
|
||||
const QString &slug,
|
||||
const QMap<QString, QString> ¶ms) {
|
||||
if (const auto paper = Data::WallPaper::FromColorSlug(slug)) {
|
||||
Ui::show(Box<BackgroundPreviewBox>(paper->withUrlParams(params)));
|
||||
Ui::show(Box<BackgroundPreviewBox>(
|
||||
session,
|
||||
paper->withUrlParams(params)));
|
||||
return true;
|
||||
}
|
||||
if (!IsValidWallPaperSlug(slug)) {
|
||||
Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now)));
|
||||
return false;
|
||||
}
|
||||
Auth().api().requestWallPaper(slug, [=](const Data::WallPaper &result) {
|
||||
Ui::show(Box<BackgroundPreviewBox>(result.withUrlParams(params)));
|
||||
session->api().requestWallPaper(slug, [=](const Data::WallPaper &result) {
|
||||
Ui::show(Box<BackgroundPreviewBox>(
|
||||
session,
|
||||
result.withUrlParams(params)));
|
||||
}, [](const RPCError &error) {
|
||||
Ui::show(Box<InformBox>(tr::lng_background_bad_link(tr::now)));
|
||||
});
|
||||
|
|
|
@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/effects/animations.h"
|
||||
#include "ui/effects/radial_animation.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Ui {
|
||||
class Checkbox;
|
||||
} // namespace Ui
|
||||
|
@ -23,9 +27,13 @@ class BackgroundPreviewBox
|
|||
: public BoxContent
|
||||
, private HistoryView::SimpleElementDelegate {
|
||||
public:
|
||||
BackgroundPreviewBox(QWidget*, const Data::WallPaper &paper);
|
||||
BackgroundPreviewBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const Data::WallPaper &paper);
|
||||
|
||||
static bool Start(
|
||||
not_null<Main::Session*> session,
|
||||
const QString &slug,
|
||||
const QMap<QString, QString> ¶ms);
|
||||
|
||||
|
@ -58,6 +66,7 @@ private:
|
|||
void startFadeInFrom(QPixmap previous);
|
||||
void checkBlurAnimationStart();
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
AdminLog::OwnedItem _text1;
|
||||
AdminLog::OwnedItem _text2;
|
||||
Data::WallPaper _paper;
|
||||
|
|
|
@ -60,8 +60,7 @@ void createErrorLabel(
|
|||
|
||||
class ChangePhoneBox::EnterPhone : public BoxContent {
|
||||
public:
|
||||
EnterPhone(QWidget*) {
|
||||
}
|
||||
EnterPhone(QWidget*, not_null<Main::Session*> session);
|
||||
|
||||
void setInnerFocus() override {
|
||||
_phone->setFocusFast();
|
||||
|
@ -79,6 +78,7 @@ private:
|
|||
showError(QString());
|
||||
}
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
object_ptr<Ui::PhoneInput> _phone = { nullptr };
|
||||
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _error = { nullptr };
|
||||
mtpRequestId _requestId = 0;
|
||||
|
@ -87,7 +87,13 @@ private:
|
|||
|
||||
class ChangePhoneBox::EnterCode : public BoxContent {
|
||||
public:
|
||||
EnterCode(QWidget*, const QString &phone, const QString &hash, int codeLength, int callTimeout);
|
||||
EnterCode(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const QString &phone,
|
||||
const QString &hash,
|
||||
int codeLength,
|
||||
int callTimeout);
|
||||
|
||||
void setInnerFocus() override {
|
||||
_code->setFocusFast();
|
||||
|
@ -107,6 +113,8 @@ private:
|
|||
}
|
||||
int countHeight();
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
QString _phone;
|
||||
QString _hash;
|
||||
int _codeLength = 0;
|
||||
|
@ -119,6 +127,12 @@ private:
|
|||
|
||||
};
|
||||
|
||||
ChangePhoneBox::EnterPhone::EnterPhone(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session)
|
||||
: _session(session) {
|
||||
}
|
||||
|
||||
void ChangePhoneBox::EnterPhone::prepare() {
|
||||
setTitle(tr::lng_change_phone_title());
|
||||
|
||||
|
@ -188,6 +202,7 @@ void ChangePhoneBox::EnterPhone::sendPhoneDone(const QString &phoneNumber, const
|
|||
}
|
||||
Ui::show(
|
||||
Box<EnterCode>(
|
||||
_session,
|
||||
phoneNumber,
|
||||
phoneCodeHash,
|
||||
codeLength,
|
||||
|
@ -229,8 +244,15 @@ void ChangePhoneBox::EnterPhone::showError(const QString &text) {
|
|||
}
|
||||
}
|
||||
|
||||
ChangePhoneBox::EnterCode::EnterCode(QWidget*, const QString &phone, const QString &hash, int codeLength, int callTimeout)
|
||||
: _phone(phone)
|
||||
ChangePhoneBox::EnterCode::EnterCode(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const QString &phone,
|
||||
const QString &hash,
|
||||
int codeLength,
|
||||
int callTimeout)
|
||||
: _session(session)
|
||||
, _phone(phone)
|
||||
, _hash(hash)
|
||||
, _codeLength(codeLength)
|
||||
, _callTimeout(callTimeout)
|
||||
|
@ -279,13 +301,15 @@ void ChangePhoneBox::EnterCode::submit() {
|
|||
}
|
||||
hideError();
|
||||
|
||||
const auto session = _session;
|
||||
const auto code = _code->getDigitsOnly();
|
||||
const auto weak = make_weak(this);
|
||||
_requestId = MTP::send(MTPaccount_ChangePhone(
|
||||
MTP_string(_phone),
|
||||
MTP_string(_hash),
|
||||
MTP_string(code)
|
||||
), rpcDone([weak = make_weak(this)](const MTPUser &result) {
|
||||
Auth().data().processUser(result);
|
||||
), rpcDone([=](const MTPUser &result) {
|
||||
session->data().processUser(result);
|
||||
if (weak) {
|
||||
Ui::hideLayer();
|
||||
}
|
||||
|
@ -342,11 +366,17 @@ bool ChangePhoneBox::EnterCode::sendCodeFail(const RPCError &error) {
|
|||
return true;
|
||||
}
|
||||
|
||||
ChangePhoneBox::ChangePhoneBox(QWidget*, not_null<Main::Session*> session)
|
||||
: _session(session) {
|
||||
}
|
||||
|
||||
void ChangePhoneBox::prepare() {
|
||||
const auto session = _session;
|
||||
|
||||
setTitle(tr::lng_change_phone_title());
|
||||
addButton(tr::lng_change_phone_button(), [] {
|
||||
Ui::show(Box<ConfirmBox>(tr::lng_change_phone_warning(tr::now), [] {
|
||||
Ui::show(Box<EnterPhone>());
|
||||
addButton(tr::lng_change_phone_button(), [=] {
|
||||
Ui::show(Box<ConfirmBox>(tr::lng_change_phone_warning(tr::now), [=] {
|
||||
Ui::show(Box<EnterPhone>(session));
|
||||
}));
|
||||
});
|
||||
addButton(tr::lng_cancel(), [this] {
|
||||
|
|
|
@ -9,10 +9,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "boxes/abstract_box.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
class ChangePhoneBox : public BoxContent {
|
||||
public:
|
||||
ChangePhoneBox(QWidget*) {
|
||||
}
|
||||
ChangePhoneBox(QWidget*, not_null<Main::Session*> session);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
@ -23,5 +26,7 @@ private:
|
|||
class EnterPhone;
|
||||
class EnterCode;
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -459,7 +459,8 @@ DeleteMessagesBox::DeleteMessagesBox(
|
|||
QWidget*,
|
||||
not_null<HistoryItem*> item,
|
||||
bool suggestModerateActions)
|
||||
: _ids(1, item->fullId()) {
|
||||
: _session(&item->history()->session())
|
||||
, _ids(1, item->fullId()) {
|
||||
if (suggestModerateActions) {
|
||||
_moderateBan = item->suggestBanReport();
|
||||
_moderateDeleteAll = item->suggestDeleteAllReport();
|
||||
|
@ -472,8 +473,10 @@ DeleteMessagesBox::DeleteMessagesBox(
|
|||
|
||||
DeleteMessagesBox::DeleteMessagesBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
MessageIdsList &&selected)
|
||||
: _ids(std::move(selected)) {
|
||||
: _session(session)
|
||||
, _ids(std::move(selected)) {
|
||||
Expects(!_ids.empty());
|
||||
}
|
||||
|
||||
|
@ -481,7 +484,8 @@ DeleteMessagesBox::DeleteMessagesBox(
|
|||
QWidget*,
|
||||
not_null<PeerData*> peer,
|
||||
bool justClear)
|
||||
: _wipeHistoryPeer(peer)
|
||||
: _session(&peer->session())
|
||||
, _wipeHistoryPeer(peer)
|
||||
, _wipeHistoryJustClear(justClear) {
|
||||
}
|
||||
|
||||
|
@ -579,7 +583,7 @@ void DeleteMessagesBox::prepare() {
|
|||
PeerData *DeleteMessagesBox::checkFromSinglePeer() const {
|
||||
auto result = (PeerData*)nullptr;
|
||||
for (const auto fullId : std::as_const(_ids)) {
|
||||
if (const auto item = Auth().data().message(fullId)) {
|
||||
if (const auto item = _session->data().message(fullId)) {
|
||||
const auto peer = item->history()->peer;
|
||||
if (!result) {
|
||||
result = peer;
|
||||
|
@ -762,7 +766,7 @@ void DeleteMessagesBox::deleteAndClear() {
|
|||
|
||||
base::flat_map<not_null<PeerData*>, QVector<MTPint>> idsByPeer;
|
||||
for (const auto itemId : _ids) {
|
||||
if (const auto item = Auth().data().message(itemId)) {
|
||||
if (const auto item = _session->data().message(itemId)) {
|
||||
const auto history = item->history();
|
||||
const auto wasOnServer = IsServerMsgId(item->id);
|
||||
const auto wasLast = (history->lastMessage() == item);
|
||||
|
@ -780,18 +784,21 @@ void DeleteMessagesBox::deleteAndClear() {
|
|||
for (const auto &[peer, ids] : idsByPeer) {
|
||||
peer->session().api().deleteMessages(peer, ids, revoke);
|
||||
}
|
||||
const auto session = _session;
|
||||
Ui::hideLayer();
|
||||
Auth().data().sendHistoryChangeNotifications();
|
||||
session->data().sendHistoryChangeNotifications();
|
||||
}
|
||||
|
||||
ConfirmInviteBox::ConfirmInviteBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDchatInvite &data,
|
||||
Fn<void()> submit)
|
||||
: _submit(std::move(submit))
|
||||
: _session(session)
|
||||
, _submit(std::move(submit))
|
||||
, _title(this, st::confirmInviteTitle)
|
||||
, _status(this, st::confirmInviteStatus)
|
||||
, _participants(GetParticipants(data))
|
||||
, _participants(GetParticipants(_session, data))
|
||||
, _isChannel(data.is_channel() && !data.is_megagroup()) {
|
||||
const auto title = qs(data.vtitle());
|
||||
const auto count = data.vparticipants_count().v;
|
||||
|
@ -807,11 +814,11 @@ ConfirmInviteBox::ConfirmInviteBox(
|
|||
_title->setText(title);
|
||||
_status->setText(status);
|
||||
|
||||
const auto photo = Auth().data().processPhoto(data.vphoto());
|
||||
const auto photo = _session->data().processPhoto(data.vphoto());
|
||||
if (!photo->isNull()) {
|
||||
_photo = photo->thumbnail();
|
||||
if (!_photo->loaded()) {
|
||||
subscribe(Auth().downloaderTaskFinished(), [=] {
|
||||
subscribe(_session->downloaderTaskFinished(), [=] {
|
||||
update();
|
||||
});
|
||||
_photo->load(Data::FileOrigin());
|
||||
|
@ -824,6 +831,7 @@ ConfirmInviteBox::ConfirmInviteBox(
|
|||
}
|
||||
|
||||
std::vector<not_null<UserData*>> ConfirmInviteBox::GetParticipants(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDchatInvite &data) {
|
||||
const auto participants = data.vparticipants();
|
||||
if (!participants) {
|
||||
|
@ -833,7 +841,7 @@ std::vector<not_null<UserData*>> ConfirmInviteBox::GetParticipants(
|
|||
auto result = std::vector<not_null<UserData*>>();
|
||||
result.reserve(v.size());
|
||||
for (const auto &participant : v) {
|
||||
if (const auto user = Auth().data().processUser(participant)) {
|
||||
if (const auto user = session->data().processUser(participant)) {
|
||||
result.push_back(user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "boxes/abstract_box.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Ui {
|
||||
class Checkbox;
|
||||
class FlatLabel;
|
||||
|
@ -150,7 +154,10 @@ public:
|
|||
QWidget*,
|
||||
not_null<HistoryItem*> item,
|
||||
bool suggestModerateActions);
|
||||
DeleteMessagesBox(QWidget*, MessageIdsList &&selected);
|
||||
DeleteMessagesBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
MessageIdsList &&selected);
|
||||
DeleteMessagesBox(QWidget*, not_null<PeerData*> peer, bool justClear);
|
||||
|
||||
void setDeleteConfirmedCallback(Fn<void()> callback) {
|
||||
|
@ -172,6 +179,8 @@ private:
|
|||
PeerData *checkFromSinglePeer() const;
|
||||
std::optional<RevokeConfig> revokeText(not_null<PeerData*> peer) const;
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
PeerData * const _wipeHistoryPeer = nullptr;
|
||||
const bool _wipeHistoryJustClear = false;
|
||||
const MessageIdsList _ids;
|
||||
|
@ -194,6 +203,7 @@ class ConfirmInviteBox : public BoxContent, public RPCSender {
|
|||
public:
|
||||
ConfirmInviteBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDchatInvite &data,
|
||||
Fn<void()> submit);
|
||||
~ConfirmInviteBox();
|
||||
|
@ -206,8 +216,11 @@ protected:
|
|||
|
||||
private:
|
||||
static std::vector<not_null<UserData*>> GetParticipants(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPDchatInvite &data);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
Fn<void()> _submit;
|
||||
object_ptr<Ui::FlatLabel> _title;
|
||||
object_ptr<Ui::FlatLabel> _status;
|
||||
|
|
|
@ -232,7 +232,7 @@ EditCaptionBox::EditCaptionBox(
|
|||
_thumbnailImageLoaded = _thumbnailImage
|
||||
? _thumbnailImage->loaded()
|
||||
: true;
|
||||
subscribe(Auth().downloaderTaskFinished(), [=] {
|
||||
subscribe(_controller->session().downloaderTaskFinished(), [=] {
|
||||
if (!_thumbnailImageLoaded
|
||||
&& _thumbnailImage
|
||||
&& _thumbnailImage->loaded()) {
|
||||
|
@ -876,7 +876,7 @@ void EditCaptionBox::setInnerFocus() {
|
|||
void EditCaptionBox::save() {
|
||||
if (_saveRequestId) return;
|
||||
|
||||
const auto item = Auth().data().message(_msgId);
|
||||
const auto item = _controller->session().data().message(_msgId);
|
||||
if (!item) {
|
||||
_error = tr::lng_edit_deleted(tr::now);
|
||||
update();
|
||||
|
@ -894,7 +894,7 @@ void EditCaptionBox::save() {
|
|||
};
|
||||
const auto prepareFlags = Ui::ItemTextOptions(
|
||||
item->history(),
|
||||
Auth().user()).flags;
|
||||
_controller->session().user()).flags;
|
||||
TextUtilities::PrepareForSending(sending, prepareFlags);
|
||||
TextUtilities::Trim(sending);
|
||||
|
||||
|
@ -913,7 +913,7 @@ void EditCaptionBox::save() {
|
|||
};
|
||||
item->setText(sending);
|
||||
|
||||
Auth().api().editMedia(
|
||||
_controller->session().api().editMedia(
|
||||
std::move(_preparedList),
|
||||
(!_asFile && _photo) ? SendMediaType::Photo : SendMediaType::File,
|
||||
_field->getTextWithAppliedMarkdown(),
|
||||
|
@ -938,21 +938,24 @@ void EditCaptionBox::save() {
|
|||
|
||||
void EditCaptionBox::saveDone(const MTPUpdates &updates) {
|
||||
_saveRequestId = 0;
|
||||
const auto controller = _controller;
|
||||
closeBox();
|
||||
Auth().api().applyUpdates(updates);
|
||||
controller->session().api().applyUpdates(updates);
|
||||
}
|
||||
|
||||
bool EditCaptionBox::saveFail(const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
_saveRequestId = 0;
|
||||
QString err = error.type();
|
||||
if (err == qstr("MESSAGE_ID_INVALID") || err == qstr("CHAT_ADMIN_REQUIRED") || err == qstr("MESSAGE_EDIT_TIME_EXPIRED")) {
|
||||
const auto &type = error.type();
|
||||
if (type == qstr("MESSAGE_ID_INVALID")
|
||||
|| type == qstr("CHAT_ADMIN_REQUIRED")
|
||||
|| type == qstr("MESSAGE_EDIT_TIME_EXPIRED")) {
|
||||
_error = tr::lng_edit_error(tr::now);
|
||||
} else if (err == qstr("MESSAGE_NOT_MODIFIED")) {
|
||||
} else if (type == qstr("MESSAGE_NOT_MODIFIED")) {
|
||||
closeBox();
|
||||
return true;
|
||||
} else if (err == qstr("MESSAGE_EMPTY")) {
|
||||
} else if (type == qstr("MESSAGE_EMPTY")) {
|
||||
_field->setFocus();
|
||||
_field->showError();
|
||||
} else {
|
||||
|
|
|
@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_user.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
|
@ -113,9 +114,11 @@ QString EditPrivacyController::optionLabel(Option option) {
|
|||
|
||||
EditPrivacyBox::EditPrivacyBox(
|
||||
QWidget*,
|
||||
not_null<Window::SessionController*> window,
|
||||
std::unique_ptr<EditPrivacyController> controller,
|
||||
const Value &value)
|
||||
: _controller(std::move(controller))
|
||||
: _window(window)
|
||||
, _controller(std::move(controller))
|
||||
, _value(value) {
|
||||
}
|
||||
|
||||
|
@ -350,7 +353,7 @@ void EditPrivacyBox::setupContent() {
|
|||
addLabel(content, _controller->exceptionsDescription());
|
||||
AddSkip(content);
|
||||
|
||||
if (auto below = _controller->setupBelowWidget(content)) {
|
||||
if (auto below = _controller->setupBelowWidget(_window, content)) {
|
||||
content->add(std::move(below));
|
||||
}
|
||||
|
||||
|
@ -358,7 +361,7 @@ void EditPrivacyBox::setupContent() {
|
|||
const auto someAreDisallowed = (_value.option != Option::Everyone)
|
||||
|| !_value.never.empty();
|
||||
_controller->confirmSave(someAreDisallowed, crl::guard(this, [=] {
|
||||
Auth().api().savePrivacy(
|
||||
_window->session().api().savePrivacy(
|
||||
_controller->apiKey(),
|
||||
collectResult());
|
||||
closeBox();
|
||||
|
|
|
@ -59,6 +59,7 @@ public:
|
|||
return { nullptr };
|
||||
}
|
||||
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupBelowWidget(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<QWidget*> parent) {
|
||||
return { nullptr };
|
||||
}
|
||||
|
@ -95,6 +96,7 @@ public:
|
|||
|
||||
EditPrivacyBox(
|
||||
QWidget*,
|
||||
not_null<Window::SessionController*> window,
|
||||
std::unique_ptr<EditPrivacyController> controller,
|
||||
const Value &value);
|
||||
|
||||
|
@ -117,6 +119,7 @@ private:
|
|||
void editExceptions(Exception exception, Fn<void()> done);
|
||||
std::vector<not_null<PeerData*>> &exceptions(Exception exception);
|
||||
|
||||
const not_null<Window::SessionController*> _window;
|
||||
std::unique_ptr<EditPrivacyController> _controller;
|
||||
Value _value;
|
||||
|
||||
|
|
|
@ -265,11 +265,11 @@ QString LocalStorageBox::Row::sizeText(const Database::TaggedSummary &data) cons
|
|||
|
||||
LocalStorageBox::LocalStorageBox(
|
||||
QWidget*,
|
||||
not_null<Database*> db,
|
||||
not_null<Database*> dbBig,
|
||||
not_null<Main::Session*> session,
|
||||
CreateTag)
|
||||
: _db(db)
|
||||
, _dbBig(dbBig) {
|
||||
: _session(session)
|
||||
, _db(&session->data().cache())
|
||||
, _dbBig(&session->data().cacheBigFile()) {
|
||||
const auto &settings = Local::cacheSettings();
|
||||
const auto &settingsBig = Local::cacheBigFileSettings();
|
||||
_totalSizeLimit = settings.totalSizeLimit + settingsBig.totalSizeLimit;
|
||||
|
@ -277,15 +277,13 @@ LocalStorageBox::LocalStorageBox(
|
|||
_timeLimit = settings.totalTimeLimit;
|
||||
}
|
||||
|
||||
void LocalStorageBox::Show(
|
||||
not_null<Database*> db,
|
||||
not_null<Database*> dbBig) {
|
||||
void LocalStorageBox::Show(not_null<::Main::Session*> session) {
|
||||
auto shared = std::make_shared<object_ptr<LocalStorageBox>>(
|
||||
Box<LocalStorageBox>(db, dbBig, CreateTag()));
|
||||
Box<LocalStorageBox>(session, CreateTag()));
|
||||
const auto weak = shared->data();
|
||||
rpl::combine(
|
||||
db->statsOnMain(),
|
||||
dbBig->statsOnMain()
|
||||
session->data().cache().statsOnMain(),
|
||||
session->data().cacheBigFile().statsOnMain()
|
||||
) | rpl::start_with_next([=](
|
||||
Database::Stats &&stats,
|
||||
Database::Stats &&statsBig) {
|
||||
|
@ -592,7 +590,7 @@ void LocalStorageBox::save() {
|
|||
updateBig.totalSizeLimit = _mediaSizeLimit;
|
||||
updateBig.totalTimeLimit = _timeLimit;
|
||||
Local::updateCacheSettings(update, updateBig);
|
||||
Auth().data().cache().updateSettings(update);
|
||||
_session->data().cache().updateSettings(update);
|
||||
closeBox();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/abstract_box.h"
|
||||
#include "storage/cache/storage_cache_database.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Storage {
|
||||
namespace Cache {
|
||||
class Database;
|
||||
|
@ -33,11 +37,10 @@ public:
|
|||
|
||||
LocalStorageBox(
|
||||
QWidget*,
|
||||
not_null<Database*> db,
|
||||
not_null<Database*> dbBig,
|
||||
not_null<Main::Session*> session,
|
||||
CreateTag);
|
||||
|
||||
static void Show(not_null<Database*> db, not_null<Database*> dbBig);
|
||||
static void Show(not_null<Main::Session*> session);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
@ -80,8 +83,10 @@ private:
|
|||
Value currentValue,
|
||||
Callback &&callback);
|
||||
|
||||
not_null<Storage::Cache::Database*> _db;
|
||||
not_null<Storage::Cache::Database*> _dbBig;
|
||||
const not_null<Main::Session*> _session;
|
||||
const not_null<Storage::Cache::Database*> _db;
|
||||
const not_null<Storage::Cache::Database*> _dbBig;
|
||||
|
||||
Database::Stats _stats;
|
||||
Database::Stats _statsBig;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ Copyright (C) 2017, Nicholas Guriev <guriev-ns@ya.ru>
|
|||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "ui/special_buttons.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
|
@ -73,7 +74,7 @@ void MuteSettingsBox::prepare() {
|
|||
|
||||
_save = [=] {
|
||||
const auto muteForSeconds = group->value() * 3600;
|
||||
Auth().data().updateNotifySettings(
|
||||
_peer->session().data().updateNotifySettings(
|
||||
_peer,
|
||||
muteForSeconds);
|
||||
closeBox();
|
||||
|
|
|
@ -40,8 +40,12 @@ PasscodeBox::CloudFields PasscodeBox::CloudFields::From(
|
|||
return result;
|
||||
}
|
||||
|
||||
PasscodeBox::PasscodeBox(QWidget*, bool turningOff)
|
||||
: _turningOff(turningOff)
|
||||
PasscodeBox::PasscodeBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
bool turningOff)
|
||||
: _session(session)
|
||||
, _turningOff(turningOff)
|
||||
, _about(st::boxWidth - st::boxPadding.left() * 1.5)
|
||||
, _oldPasscode(this, st::defaultInputField, tr::lng_passcode_enter_old())
|
||||
, _newPasscode(this, st::defaultInputField, Global::LocalPasscode() ? tr::lng_passcode_enter_new() : tr::lng_passcode_enter_first())
|
||||
|
@ -51,8 +55,12 @@ PasscodeBox::PasscodeBox(QWidget*, bool turningOff)
|
|||
, _recover(this, tr::lng_signin_recover(tr::now)) {
|
||||
}
|
||||
|
||||
PasscodeBox::PasscodeBox(QWidget*, const CloudFields &fields)
|
||||
: _turningOff(fields.turningOff)
|
||||
PasscodeBox::PasscodeBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const CloudFields &fields)
|
||||
: _session(session)
|
||||
, _turningOff(fields.turningOff)
|
||||
, _cloudPwd(true)
|
||||
, _cloudFields(fields)
|
||||
, _about(st::boxWidth - st::boxPadding.left() * 1.5)
|
||||
|
@ -506,7 +514,7 @@ void PasscodeBox::save(bool force) {
|
|||
const auto weak = make_weak(this);
|
||||
cSetPasscodeBadTries(0);
|
||||
Local::setPasscode(pwd.toUtf8());
|
||||
Auth().localPasscodeChanged();
|
||||
_session->localPasscodeChanged();
|
||||
if (weak) {
|
||||
closeBox();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "mtproto/sender.h"
|
||||
#include "core/core_cloud_password.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Ui {
|
||||
class InputField;
|
||||
class PasswordInput;
|
||||
|
@ -23,7 +27,7 @@ struct CloudPasswordState;
|
|||
|
||||
class PasscodeBox : public BoxContent, private MTP::Sender {
|
||||
public:
|
||||
PasscodeBox(QWidget*, bool turningOff);
|
||||
PasscodeBox(QWidget*, not_null<Main::Session*> session, bool turningOff);
|
||||
|
||||
struct CloudFields {
|
||||
static CloudFields From(const Core::CloudPasswordState ¤t);
|
||||
|
@ -42,7 +46,10 @@ public:
|
|||
std::optional<QString> customDescription;
|
||||
rpl::producer<QString> customSubmitButton;
|
||||
};
|
||||
PasscodeBox(QWidget*, const CloudFields &fields);
|
||||
PasscodeBox(
|
||||
QWidget*,
|
||||
not_null<Main::Session*> session,
|
||||
const CloudFields &fields);
|
||||
|
||||
rpl::producer<QByteArray> newPasswordSet() const;
|
||||
rpl::producer<> passwordReloadNeeded() const;
|
||||
|
@ -122,6 +129,8 @@ private:
|
|||
void passwordChecked();
|
||||
void serverError();
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
QString _pattern;
|
||||
|
||||
QPointer<BoxContent> _replacedBy;
|
||||
|
|
|
@ -57,7 +57,7 @@ void SetCloudPassword(not_null<GenericBox*> box, not_null<UserData*> user) {
|
|||
) | rpl::start_with_next([=] {
|
||||
using namespace Settings;
|
||||
const auto weak = make_weak(box);
|
||||
if (CheckEditCloudPassword()) {
|
||||
if (CheckEditCloudPassword(&user->session())) {
|
||||
box->getDelegate()->show(
|
||||
EditCloudPasswordBox(&user->session()));
|
||||
} else {
|
||||
|
@ -566,7 +566,9 @@ void EditAdminBox::requestTransferPassword(not_null<ChannelData*> channel) {
|
|||
const Core::CloudPasswordResult &result) {
|
||||
sendTransferRequestFrom(*box, channel, result);
|
||||
});
|
||||
*box = getDelegate()->show(Box<PasscodeBox>(fields));
|
||||
*box = getDelegate()->show(Box<PasscodeBox>(
|
||||
&channel->session(),
|
||||
fields));
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
|
|
|
@ -480,6 +480,17 @@ void Application::writeInstallBetaVersionsSetting() {
|
|||
_launcher->writeInstallBetaVersionsSetting();
|
||||
}
|
||||
|
||||
bool Application::exportPreventsQuit() {
|
||||
if (!activeAccount().sessionExists()
|
||||
|| !activeAccount().session().data().exportInProgress()) {
|
||||
return false;
|
||||
}
|
||||
activeAccount().session().data().stopExportWithConfirmation([] {
|
||||
App::quit();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
int Application::unreadBadge() const {
|
||||
return activeAccount().sessionExists()
|
||||
? activeAccount().session().data().unreadBadge()
|
||||
|
@ -551,12 +562,15 @@ bool Application::openLocalUrl(const QString &url, QVariant context) {
|
|||
}
|
||||
auto command = urlTrimmed.midRef(protocol.size());
|
||||
|
||||
const auto session = activeAccount().sessionExists()
|
||||
? &activeAccount().session()
|
||||
: nullptr;
|
||||
using namespace qthelp;
|
||||
const auto options = RegExOption::CaseInsensitive;
|
||||
for (const auto &[expression, handler] : LocalUrlHandlers()) {
|
||||
const auto match = regex_match(expression, command, options);
|
||||
if (match) {
|
||||
return handler(match, context);
|
||||
return handler(session, match, context);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -130,17 +130,18 @@ public:
|
|||
void badMtprotoConfigurationError();
|
||||
|
||||
// Databases.
|
||||
Storage::Databases &databases() {
|
||||
[[nodiscard]] Storage::Databases &databases() {
|
||||
return *_databases;
|
||||
}
|
||||
|
||||
// Account component.
|
||||
Main::Account &activeAccount() const {
|
||||
[[nodiscard]] Main::Account &activeAccount() const {
|
||||
return *_account;
|
||||
}
|
||||
[[nodiscard]] bool exportPreventsQuit();
|
||||
|
||||
// Main::Session component.
|
||||
int unreadBadge() const;
|
||||
[[nodiscard]] int unreadBadge() const;
|
||||
bool unreadBadgeMuted() const;
|
||||
|
||||
// Media component.
|
||||
|
|
|
@ -33,19 +33,22 @@ namespace {
|
|||
|
||||
using Match = qthelp::RegularExpressionMatch;
|
||||
|
||||
bool JoinGroupByHash(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool JoinGroupByHash(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
const auto hash = match->captured(1);
|
||||
Auth().api().checkChatInvite(hash, [=](const MTPChatInvite &result) {
|
||||
session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) {
|
||||
Core::App().hideMediaView();
|
||||
result.match([=](const MTPDchatInvite &data) {
|
||||
Ui::show(Box<ConfirmInviteBox>(data, [=] {
|
||||
Auth().api().importChatInvite(hash);
|
||||
Ui::show(Box<ConfirmInviteBox>(session, data, [=] {
|
||||
session->api().importChatInvite(hash);
|
||||
}));
|
||||
}, [=](const MTPDchatInviteAlready &data) {
|
||||
if (const auto chat = Auth().data().processChat(data.vchat())) {
|
||||
if (const auto chat = session->data().processChat(data.vchat())) {
|
||||
App::wnd()->sessionController()->showPeerHistory(
|
||||
chat,
|
||||
Window::SectionShow::Way::Forward);
|
||||
|
@ -61,8 +64,11 @@ bool JoinGroupByHash(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ShowStickerSet(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool ShowStickerSet(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
Core::App().hideMediaView();
|
||||
|
@ -72,14 +78,20 @@ bool ShowStickerSet(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SetLanguage(const Match &match, const QVariant &context) {
|
||||
bool SetLanguage(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
const auto languageId = match->captured(1);
|
||||
Lang::CurrentCloudManager().switchWithWarning(languageId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShareUrl(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool ShareUrl(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
auto params = url_parse_params(
|
||||
|
@ -93,8 +105,11 @@ bool ShareUrl(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ConfirmPhone(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool ConfirmPhone(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
auto params = url_parse_params(
|
||||
|
@ -109,8 +124,11 @@ bool ConfirmPhone(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ShareGameScore(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool ShareGameScore(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
const auto params = url_parse_params(
|
||||
|
@ -120,7 +138,10 @@ bool ShareGameScore(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ApplySocksProxy(const Match &match, const QVariant &context) {
|
||||
bool ApplySocksProxy(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
auto params = url_parse_params(
|
||||
match->captured(1),
|
||||
qthelp::UrlParamNameTransform::ToLower);
|
||||
|
@ -128,7 +149,10 @@ bool ApplySocksProxy(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ApplyMtprotoProxy(const Match &match, const QVariant &context) {
|
||||
bool ApplyMtprotoProxy(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
auto params = url_parse_params(
|
||||
match->captured(1),
|
||||
qthelp::UrlParamNameTransform::ToLower);
|
||||
|
@ -160,26 +184,36 @@ bool ShowPassportForm(const QMap<QString, QString> ¶ms) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ShowPassport(const Match &match, const QVariant &context) {
|
||||
bool ShowPassport(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
return ShowPassportForm(url_parse_params(
|
||||
match->captured(1),
|
||||
qthelp::UrlParamNameTransform::ToLower));
|
||||
}
|
||||
|
||||
bool ShowWallPaper(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool ShowWallPaper(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
const auto params = url_parse_params(
|
||||
match->captured(1),
|
||||
qthelp::UrlParamNameTransform::ToLower);
|
||||
return BackgroundPreviewBox::Start(
|
||||
session,
|
||||
params.value(qsl("slug")),
|
||||
params);
|
||||
}
|
||||
|
||||
bool ResolveUsername(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool ResolveUsername(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
const auto params = url_parse_params(
|
||||
|
@ -228,8 +262,11 @@ bool ResolveUsername(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ResolvePrivatePost(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool ResolvePrivatePost(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
const auto params = url_parse_params(
|
||||
|
@ -249,18 +286,17 @@ bool ResolvePrivatePost(const Match &match, const QVariant &context) {
|
|||
const auto fail = [=] {
|
||||
Ui::show(Box<InformBox>(tr::lng_error_post_link_invalid(tr::now)));
|
||||
};
|
||||
const auto auth = &Auth();
|
||||
if (const auto channel = auth->data().channelLoaded(channelId)) {
|
||||
if (const auto channel = session->data().channelLoaded(channelId)) {
|
||||
done(channel);
|
||||
return true;
|
||||
}
|
||||
auth->api().request(MTPchannels_GetChannels(
|
||||
session->api().request(MTPchannels_GetChannels(
|
||||
MTP_vector<MTPInputChannel>(
|
||||
1,
|
||||
MTP_inputChannel(MTP_int(channelId), MTP_long(0)))
|
||||
)).done([=](const MTPmessages_Chats &result) {
|
||||
result.match([&](const auto &data) {
|
||||
const auto peer = auth->data().processChats(data.vchats());
|
||||
const auto peer = session->data().processChats(data.vchats());
|
||||
if (peer && peer->id == peerFromChannel(channelId)) {
|
||||
done(peer);
|
||||
} else {
|
||||
|
@ -273,8 +309,11 @@ bool ResolvePrivatePost(const Match &match, const QVariant &context) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool HandleUnknown(const Match &match, const QVariant &context) {
|
||||
if (!Main::Session::Exists()) {
|
||||
bool HandleUnknown(
|
||||
Main::Session *session,
|
||||
const Match &match,
|
||||
const QVariant &context) {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
const auto request = match->captured(1);
|
||||
|
@ -298,7 +337,7 @@ bool HandleUnknown(const Match &match, const QVariant &context) {
|
|||
Ui::show(Box<InformBox>(text));
|
||||
}
|
||||
};
|
||||
Auth().api().requestDeepLinkInfo(request, callback);
|
||||
session->api().requestDeepLinkInfo(request, callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,16 @@ namespace qthelp {
|
|||
class RegularExpressionMatch;
|
||||
} // namespace qthelp
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Core {
|
||||
|
||||
struct LocalUrlHandler {
|
||||
QString expression;
|
||||
Fn<bool(
|
||||
Main::Session *session,
|
||||
const qthelp::RegularExpressionMatch &match,
|
||||
const QVariant &context)> handler;
|
||||
};
|
||||
|
|
|
@ -3012,6 +3012,7 @@ void HistoryInner::deleteAsGroup(FullMsgId itemId) {
|
|||
return deleteItem(item);
|
||||
}
|
||||
Ui::show(Box<DeleteMessagesBox>(
|
||||
&session(),
|
||||
session().data().itemsToIds(group->items)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6131,7 +6131,9 @@ void HistoryWidget::confirmDeleteSelected() {
|
|||
return;
|
||||
}
|
||||
const auto weak = make_weak(this);
|
||||
const auto box = Ui::show(Box<DeleteMessagesBox>(std::move(items)));
|
||||
const auto box = Ui::show(Box<DeleteMessagesBox>(
|
||||
&session(),
|
||||
std::move(items)));
|
||||
box->setDeleteConfirmedCallback([=] {
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->clearSelected();
|
||||
|
|
|
@ -298,10 +298,13 @@ bool AddDeleteSelectedAction(
|
|||
return false;
|
||||
}
|
||||
|
||||
const auto session = request.session;
|
||||
menu->addAction(tr::lng_context_delete_selected(tr::now), [=] {
|
||||
const auto weak = make_weak(list);
|
||||
auto items = ExtractIdsList(request.selectedItems);
|
||||
const auto box = Ui::show(Box<DeleteMessagesBox>(std::move(items)));
|
||||
const auto box = Ui::show(Box<DeleteMessagesBox>(
|
||||
session,
|
||||
std::move(items)));
|
||||
box->setDeleteConfirmedCallback([=] {
|
||||
if (const auto strong = weak.data()) {
|
||||
strong->cancelSelection();
|
||||
|
@ -338,6 +341,7 @@ bool AddDeleteMessageAction(
|
|||
if (asGroup) {
|
||||
if (const auto group = owner->groups().find(item)) {
|
||||
Ui::show(Box<DeleteMessagesBox>(
|
||||
&owner->session(),
|
||||
owner->itemsToIds(group->items)));
|
||||
return;
|
||||
}
|
||||
|
@ -439,6 +443,10 @@ void AddCopyLinkAction(
|
|||
|
||||
} // namespace
|
||||
|
||||
ContextMenuRequest::ContextMenuRequest(not_null<Main::Session*> session)
|
||||
: session(session) {
|
||||
}
|
||||
|
||||
base::unique_qptr<Ui::PopupMenu> FillContextMenu(
|
||||
not_null<ListWidget*> list,
|
||||
const ContextMenuRequest &request) {
|
||||
|
|
|
@ -13,6 +13,10 @@ namespace Ui {
|
|||
class PopupMenu;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace HistoryView {
|
||||
|
||||
enum class PointState : char;
|
||||
|
@ -22,6 +26,9 @@ struct SelectedItem;
|
|||
using SelectedItems = std::vector<SelectedItem>;
|
||||
|
||||
struct ContextMenuRequest {
|
||||
explicit ContextMenuRequest(not_null<Main::Session*> session);
|
||||
|
||||
const not_null<Main::Session*> session;
|
||||
ClickHandlerPtr link;
|
||||
Element *view = nullptr;
|
||||
HistoryItem *item = nullptr;
|
||||
|
|
|
@ -1611,7 +1611,8 @@ void ListWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
|||
mouseActionUpdate(e->globalPos());
|
||||
}
|
||||
|
||||
ContextMenuRequest request;
|
||||
auto request = ContextMenuRequest(&_controller->session());
|
||||
|
||||
request.link = ClickHandler::getActive();
|
||||
request.view = _overElement;
|
||||
request.item = _overItemExact
|
||||
|
|
|
@ -35,9 +35,11 @@ namespace Info {
|
|||
|
||||
TopBar::TopBar(
|
||||
QWidget *parent,
|
||||
not_null<Main::Session*> session,
|
||||
const style::InfoTopBar &st,
|
||||
SelectedItems &&selectedItems)
|
||||
: RpWidget(parent)
|
||||
, _session(session)
|
||||
, _st(st)
|
||||
, _selectedItems(Section::MediaType::kCount) {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
|
@ -516,8 +518,8 @@ MessageIdsList TopBar::collectItems() const {
|
|||
_selectedItems.list
|
||||
) | ranges::view::transform([](auto &&item) {
|
||||
return item.msgId;
|
||||
}) | ranges::view::filter([](FullMsgId msgId) {
|
||||
return Auth().data().message(msgId) != nullptr;
|
||||
}) | ranges::view::filter([&](FullMsgId msgId) {
|
||||
return _session->data().message(msgId) != nullptr;
|
||||
}) | ranges::to_vector;
|
||||
}
|
||||
|
||||
|
@ -541,7 +543,9 @@ void TopBar::performDelete() {
|
|||
if (items.empty()) {
|
||||
_cancelSelectionClicks.fire({});
|
||||
} else {
|
||||
const auto box = Ui::show(Box<DeleteMessagesBox>(std::move(items)));
|
||||
const auto box = Ui::show(Box<DeleteMessagesBox>(
|
||||
_session,
|
||||
std::move(items)));
|
||||
box->setDeleteConfirmedCallback([weak = make_weak(this)] {
|
||||
if (weak) {
|
||||
weak->_cancelSelectionClicks.fire({});
|
||||
|
|
|
@ -39,6 +39,7 @@ class TopBar : public Ui::RpWidget {
|
|||
public:
|
||||
TopBar(
|
||||
QWidget *parent,
|
||||
not_null<Main::Session*> session,
|
||||
const style::InfoTopBar &st,
|
||||
SelectedItems &&items);
|
||||
|
||||
|
@ -130,6 +131,8 @@ private:
|
|||
template <typename Widget, typename IsVisible>
|
||||
void registerToggleControlCallback(Widget *widget, IsVisible &&callback);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
const style::InfoTopBar &_st;
|
||||
Ui::Animations::Simple _a_highlight;
|
||||
bool _highlight = false;
|
||||
|
|
|
@ -353,7 +353,11 @@ void WrapWidget::createTopBar() {
|
|||
auto selectedItems = _topBar
|
||||
? _topBar->takeSelectedItems()
|
||||
: SelectedItems(Section::MediaType::kCount);
|
||||
_topBar.create(this, TopBarStyle(wrapValue), std::move(selectedItems));
|
||||
_topBar.create(
|
||||
this,
|
||||
&session(),
|
||||
TopBarStyle(wrapValue),
|
||||
std::move(selectedItems));
|
||||
_topBar->cancelSelectionRequests(
|
||||
) | rpl::start_with_next([this] {
|
||||
_content->cancelSelection();
|
||||
|
@ -582,7 +586,7 @@ void WrapWidget::showTopBarMenu() {
|
|||
_topBarMenu = nullptr;
|
||||
controller->showSettings(type);
|
||||
};
|
||||
::Settings::FillMenu(showOther, addAction);
|
||||
::Settings::FillMenu(&self->session(), showOther, addAction);
|
||||
} else {
|
||||
_topBarMenu = nullptr;
|
||||
return;
|
||||
|
|
|
@ -1422,7 +1422,9 @@ void ListWidget::deleteItem(UniversalMsgId universalId) {
|
|||
DeleteMessagesBox *ListWidget::deleteItems(MessageIdsList &&items) {
|
||||
if (!items.empty()) {
|
||||
const auto box = Ui::show(
|
||||
Box<DeleteMessagesBox>(std::move(items))).data();
|
||||
Box<DeleteMessagesBox>(
|
||||
&_controller->session(),
|
||||
std::move(items))).data();
|
||||
setActionBoxWeak(box);
|
||||
return box;
|
||||
}
|
||||
|
|
|
@ -45,8 +45,7 @@ Widget::Widget(
|
|||
, _inner(setInnerWidget(::Settings::CreateSection(
|
||||
_type,
|
||||
this,
|
||||
controller->parentController(),
|
||||
_self))) {
|
||||
controller->parentController()))) {
|
||||
_inner->sectionShowOther(
|
||||
) | rpl::start_with_next([=](Type type) {
|
||||
controller->showSettings(type);
|
||||
|
|
|
@ -325,6 +325,10 @@ public:
|
|||
not_null<Window::SessionController*> controller,
|
||||
const FormRequest &request);
|
||||
|
||||
not_null<Window::SessionController*> window() const {
|
||||
return _controller;
|
||||
}
|
||||
|
||||
void show();
|
||||
UserData *bot() const;
|
||||
QString privacyPolicyUrl() const;
|
||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/unixtime.h"
|
||||
#include "boxes/passcode_box.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/countryinput.h"
|
||||
|
@ -723,7 +724,7 @@ void PanelController::setupPassword() {
|
|||
auto fields = PasscodeBox::CloudFields();
|
||||
fields.newAlgo = settings.newAlgo;
|
||||
fields.newSecureSecretAlgo = settings.newSecureAlgo;
|
||||
auto box = show(Box<PasscodeBox>(fields));
|
||||
auto box = show(Box<PasscodeBox>(&_form->window()->session(), fields));
|
||||
box->newPasswordSet(
|
||||
) | rpl::filter([=](const QByteArray &password) {
|
||||
return !password.isEmpty();
|
||||
|
|
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "info/profile/info_profile_button.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "platform/platform_info.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "core/update_checker.h"
|
||||
#include "core/application.h"
|
||||
|
@ -418,7 +419,9 @@ void SetupAnimations(not_null<Ui::VerticalLayout*> container) {
|
|||
}, container->lifetime());
|
||||
}
|
||||
|
||||
void SetupPerformance(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupPerformance(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
SetupAnimations(container);
|
||||
|
||||
AddButton(
|
||||
|
@ -430,10 +433,10 @@ void SetupPerformance(not_null<Ui::VerticalLayout*> container) {
|
|||
)->toggledValue(
|
||||
) | rpl::filter([](bool enabled) {
|
||||
return (enabled != cAutoPlayGif());
|
||||
}) | rpl::start_with_next([](bool enabled) {
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
cSetAutoPlayGif(enabled);
|
||||
if (!cAutoPlayGif()) {
|
||||
Auth().data().stopAutoplayAnimations();
|
||||
controller->session().data().stopAutoplayAnimations();
|
||||
}
|
||||
Local::writeUserSettings();
|
||||
}, container->lifetime());
|
||||
|
@ -456,16 +459,18 @@ void SetupSystemIntegration(
|
|||
AddSkip(container);
|
||||
}
|
||||
|
||||
Advanced::Advanced(QWidget *parent, UserData *self)
|
||||
Advanced::Advanced(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent) {
|
||||
setupContent();
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
rpl::producer<Type> Advanced::sectionShowOther() {
|
||||
return _showOther.events();
|
||||
}
|
||||
|
||||
void Advanced::setupContent() {
|
||||
void Advanced::setupContent(not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
auto empty = true;
|
||||
|
@ -495,8 +500,8 @@ void Advanced::setupContent() {
|
|||
SetupConnectionType(content);
|
||||
AddSkip(content);
|
||||
}
|
||||
SetupDataStorage(content);
|
||||
SetupAutoDownload(content);
|
||||
SetupDataStorage(controller, content);
|
||||
SetupAutoDownload(controller, content);
|
||||
SetupSystemIntegration(content, [=](Type type) {
|
||||
_showOther.fire_copy(type);
|
||||
});
|
||||
|
@ -504,7 +509,7 @@ void Advanced::setupContent() {
|
|||
AddDivider(content);
|
||||
AddSkip(content);
|
||||
AddSubsectionTitle(content, tr::lng_settings_performance());
|
||||
SetupPerformance(content);
|
||||
SetupPerformance(controller, content);
|
||||
AddSkip(content);
|
||||
|
||||
if (cAutoUpdate()) {
|
||||
|
|
|
@ -21,12 +21,14 @@ void SetupAnimations(not_null<Ui::VerticalLayout*> container);
|
|||
|
||||
class Advanced : public Section {
|
||||
public:
|
||||
explicit Advanced(QWidget *parent, UserData *self = nullptr);
|
||||
Advanced(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
rpl::producer<Type> sectionShowOther() override;
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
|
||||
rpl::event_stream<Type> _showOther;
|
||||
|
||||
|
|
|
@ -38,9 +38,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace Settings {
|
||||
|
||||
Calls::Calls(QWidget *parent, UserData *self)
|
||||
Calls::Calls(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent) {
|
||||
setupContent();
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
Calls::~Calls() {
|
||||
|
@ -56,7 +58,7 @@ void Calls::sectionSaveChanges(FnMut<void()> done) {
|
|||
done();
|
||||
}
|
||||
|
||||
void Calls::setupContent() {
|
||||
void Calls::setupContent(not_null<Window::SessionController*> controller) {
|
||||
using namespace tgvoip;
|
||||
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
|
|
@ -11,27 +11,28 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/timer.h"
|
||||
|
||||
namespace Calls {
|
||||
class Call;
|
||||
class Call;
|
||||
} // namespace Calls
|
||||
|
||||
namespace Ui {
|
||||
class LevelMeter;
|
||||
}
|
||||
class LevelMeter;
|
||||
} // namespace Ui
|
||||
|
||||
namespace tgvoip {
|
||||
class AudioInputTester;
|
||||
}
|
||||
class AudioInputTester;
|
||||
} // namespace tgvoip
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class Calls : public Section {
|
||||
public:
|
||||
explicit Calls(QWidget *parent, UserData *self = nullptr);
|
||||
virtual ~Calls();
|
||||
virtual void sectionSaveChanges(FnMut<void()> done) override;
|
||||
Calls(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||
~Calls();
|
||||
|
||||
void sectionSaveChanges(FnMut<void()> done) override;
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
void requestPermissionAndStartTestingMicrophone();
|
||||
void startTestingMicrophone();
|
||||
void stopTestingMicrophone();
|
||||
|
@ -43,6 +44,7 @@ private:
|
|||
std::unique_ptr<tgvoip::AudioInputTester> _micTester;
|
||||
Ui::LevelMeter *_micTestLevel = nullptr;
|
||||
base::Timer _levelUpdateTimer;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Settings
|
||||
|
|
|
@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_keys.h"
|
||||
#include "window/themes/window_theme_editor.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "info/profile/info_profile_button.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
@ -44,7 +45,9 @@ namespace Settings {
|
|||
|
||||
class BackgroundRow : public Ui::RpWidget {
|
||||
public:
|
||||
BackgroundRow(QWidget *parent);
|
||||
BackgroundRow(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
@ -106,9 +109,14 @@ private:
|
|||
|
||||
};
|
||||
|
||||
void ChooseFromFile(not_null<QWidget*> parent);
|
||||
void ChooseFromFile(
|
||||
not_null<::Main::Session*> session,
|
||||
not_null<QWidget*> parent);
|
||||
|
||||
BackgroundRow::BackgroundRow(QWidget *parent) : RpWidget(parent)
|
||||
BackgroundRow::BackgroundRow(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: RpWidget(parent)
|
||||
, _chooseFromGallery(
|
||||
this,
|
||||
tr::lng_settings_bg_from_gallery(tr::now),
|
||||
|
@ -117,11 +125,11 @@ BackgroundRow::BackgroundRow(QWidget *parent) : RpWidget(parent)
|
|||
, _radial([=](crl::time now) { radialAnimationCallback(now); }) {
|
||||
updateImage();
|
||||
|
||||
_chooseFromGallery->addClickHandler([] {
|
||||
Ui::show(Box<BackgroundBox>());
|
||||
_chooseFromGallery->addClickHandler([=] {
|
||||
Ui::show(Box<BackgroundBox>(&controller->session()));
|
||||
});
|
||||
_chooseFromFile->addClickHandler([=] {
|
||||
ChooseFromFile(this);
|
||||
ChooseFromFile(&controller->session(), this);
|
||||
});
|
||||
|
||||
using Update = const Window::Theme::BackgroundUpdate;
|
||||
|
@ -361,14 +369,17 @@ void DefaultTheme::checkedChangedHook(anim::type animated) {
|
|||
_radio.setChecked(checked(), animated);
|
||||
}
|
||||
|
||||
void ChooseFromFile(not_null<QWidget*> parent) {
|
||||
void ChooseFromFile(
|
||||
not_null<::Main::Session*> session,
|
||||
not_null<QWidget*> parent) {
|
||||
const auto &imgExtensions = cImgExtensions();
|
||||
auto filters = QStringList(
|
||||
qsl("Theme files (*.tdesktop-theme *.tdesktop-palette *")
|
||||
+ imgExtensions.join(qsl(" *"))
|
||||
+ qsl(")"));
|
||||
filters.push_back(FileDialog::AllFilesFilter());
|
||||
const auto callback = [=](const FileDialog::OpenResult &result) {
|
||||
const auto callback = crl::guard(session, [=](
|
||||
const FileDialog::OpenResult &result) {
|
||||
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -396,8 +407,8 @@ void ChooseFromFile(not_null<QWidget*> parent) {
|
|||
std::make_unique<Images::ImageSource>(
|
||||
std::move(image),
|
||||
"JPG")));
|
||||
Ui::show(Box<BackgroundPreviewBox>(local));
|
||||
};
|
||||
Ui::show(Box<BackgroundPreviewBox>(session, local));
|
||||
});
|
||||
FileDialog::GetOpenPath(
|
||||
parent.get(),
|
||||
tr::lng_choose_image(tr::now),
|
||||
|
@ -492,7 +503,9 @@ void SetupStickersEmoji(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
}
|
||||
|
||||
void SetupMessages(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupMessages(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
|
||||
|
@ -512,7 +525,7 @@ void SetupMessages(not_null<Ui::VerticalLayout*> container) {
|
|||
QMargins(0, skip, 0, skip)));
|
||||
|
||||
const auto group = std::make_shared<Ui::RadioenumGroup<SendByType>>(
|
||||
Auth().settings().sendSubmitWay());
|
||||
controller->session().settings().sendSubmitWay());
|
||||
const auto add = [&](SendByType value, const QString &text) {
|
||||
inner->add(
|
||||
object_ptr<Ui::Radioenum<SendByType>>(
|
||||
|
@ -532,8 +545,8 @@ void SetupMessages(not_null<Ui::VerticalLayout*> container) {
|
|||
? tr::lng_settings_send_cmdenter(tr::now)
|
||||
: tr::lng_settings_send_ctrlenter(tr::now)));
|
||||
|
||||
group->setChangedCallback([](SendByType value) {
|
||||
Auth().settings().setSendSubmitWay(value);
|
||||
group->setChangedCallback([=](SendByType value) {
|
||||
controller->session().settings().setSendSubmitWay(value);
|
||||
if (App::main()) {
|
||||
App::main()->ctrlEnterSubmitUpdated();
|
||||
}
|
||||
|
@ -543,33 +556,38 @@ void SetupMessages(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(inner, st::settingsCheckboxesSkip);
|
||||
}
|
||||
|
||||
void SetupExport(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupExport(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
tr::lng_settings_export_data(),
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
)->addClickHandler([=] {
|
||||
const auto session = &controller->session();
|
||||
Ui::hideSettingsAndLayer();
|
||||
App::CallDelayed(
|
||||
st::boxDuration,
|
||||
&Auth(),
|
||||
[] { Auth().data().startExport(); });
|
||||
session,
|
||||
[=] { session->data().startExport(); });
|
||||
});
|
||||
}
|
||||
|
||||
void SetupLocalStorage(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupLocalStorage(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
tr::lng_settings_manage_local_storage(),
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
LocalStorageBox::Show(
|
||||
&Auth().data().cache(),
|
||||
&Auth().data().cacheBigFile());
|
||||
)->addClickHandler([=] {
|
||||
LocalStorageBox::Show(&controller->session());
|
||||
});
|
||||
}
|
||||
|
||||
void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupDataStorage(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
using namespace rpl::mappers;
|
||||
|
||||
AddDivider(container);
|
||||
|
@ -623,13 +641,15 @@ void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
}, ask->lifetime());
|
||||
|
||||
SetupLocalStorage(container);
|
||||
SetupExport(container);
|
||||
SetupLocalStorage(controller, container);
|
||||
SetupExport(controller, container);
|
||||
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
}
|
||||
|
||||
void SetupAutoDownload(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupAutoDownload(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
|
||||
|
@ -642,7 +662,7 @@ void SetupAutoDownload(not_null<Ui::VerticalLayout*> container) {
|
|||
std::move(label),
|
||||
st::settingsButton
|
||||
)->addClickHandler([=] {
|
||||
Ui::show(Box<AutoDownloadBox>(source));
|
||||
Ui::show(Box<AutoDownloadBox>(&controller->session(), source));
|
||||
});
|
||||
};
|
||||
add(tr::lng_media_auto_in_private(), Source::User);
|
||||
|
@ -652,14 +672,16 @@ void SetupAutoDownload(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
}
|
||||
|
||||
void SetupChatBackground(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupChatBackground(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
|
||||
AddSubsectionTitle(container, tr::lng_settings_section_background());
|
||||
|
||||
container->add(
|
||||
object_ptr<BackgroundRow>(container),
|
||||
object_ptr<BackgroundRow>(container, controller),
|
||||
st::settingsBackgroundPadding);
|
||||
|
||||
const auto skipTop = st::settingsCheckbox.margin.top();
|
||||
|
@ -925,10 +947,12 @@ void SetupThemeOptions(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container);
|
||||
}
|
||||
|
||||
void SetupSupportSwitchSettings(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupSupportSwitchSettings(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
using SwitchType = Support::SwitchSettings;
|
||||
const auto group = std::make_shared<Ui::RadioenumGroup<SwitchType>>(
|
||||
Auth().settings().supportSwitch());
|
||||
controller->session().settings().supportSwitch());
|
||||
const auto add = [&](SwitchType value, const QString &label) {
|
||||
container->add(
|
||||
object_ptr<Ui::Radioenum<SwitchType>>(
|
||||
|
@ -942,13 +966,15 @@ void SetupSupportSwitchSettings(not_null<Ui::VerticalLayout*> container) {
|
|||
add(SwitchType::None, "Just send the reply");
|
||||
add(SwitchType::Next, "Send and switch to next");
|
||||
add(SwitchType::Previous, "Send and switch to previous");
|
||||
group->setChangedCallback([](SwitchType value) {
|
||||
Auth().settings().setSupportSwitch(value);
|
||||
group->setChangedCallback([=](SwitchType value) {
|
||||
controller->session().settings().setSupportSwitch(value);
|
||||
Local::writeUserSettings();
|
||||
});
|
||||
}
|
||||
|
||||
void SetupSupportChatsLimitSlice(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupSupportChatsLimitSlice(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
constexpr auto kDayDuration = 24 * 60 * 60;
|
||||
struct Option {
|
||||
int days = 0;
|
||||
|
@ -961,7 +987,7 @@ void SetupSupportChatsLimitSlice(not_null<Ui::VerticalLayout*> container) {
|
|||
{ 365, "1 year" },
|
||||
{ 0, "All of them" },
|
||||
};
|
||||
const auto current = Auth().settings().supportChatsTimeSlice();
|
||||
const auto current = controller->session().settings().supportChatsTimeSlice();
|
||||
const auto days = current / kDayDuration;
|
||||
const auto best = ranges::min_element(
|
||||
options,
|
||||
|
@ -980,12 +1006,15 @@ void SetupSupportChatsLimitSlice(not_null<Ui::VerticalLayout*> container) {
|
|||
st::settingsSendTypePadding);
|
||||
}
|
||||
group->setChangedCallback([=](int days) {
|
||||
Auth().settings().setSupportChatsTimeSlice(days * kDayDuration);
|
||||
controller->session().settings().setSupportChatsTimeSlice(
|
||||
days * kDayDuration);
|
||||
Local::writeUserSettings();
|
||||
});
|
||||
}
|
||||
|
||||
void SetupSupport(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupSupport(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container);
|
||||
|
||||
AddSubsectionTitle(container, rpl::single(qsl("Support settings")));
|
||||
|
@ -1001,7 +1030,7 @@ void SetupSupport(not_null<Ui::VerticalLayout*> container) {
|
|||
std::move(wrap),
|
||||
QMargins(0, skip, 0, skip)));
|
||||
|
||||
SetupSupportSwitchSettings(inner);
|
||||
SetupSupportSwitchSettings(controller, inner);
|
||||
|
||||
AddSkip(inner, st::settingsCheckboxesSkip);
|
||||
|
||||
|
@ -1009,12 +1038,13 @@ void SetupSupport(not_null<Ui::VerticalLayout*> container) {
|
|||
object_ptr<Ui::Checkbox>(
|
||||
inner,
|
||||
"Enable templates autocomplete",
|
||||
Auth().settings().supportTemplatesAutocomplete(),
|
||||
controller->session().settings().supportTemplatesAutocomplete(),
|
||||
st::settingsCheckbox),
|
||||
st::settingsSendTypePadding
|
||||
)->checkedChanges(
|
||||
) | rpl::start_with_next([=](bool checked) {
|
||||
Auth().settings().setSupportTemplatesAutocomplete(checked);
|
||||
controller->session().settings().setSupportTemplatesAutocomplete(
|
||||
checked);
|
||||
Local::writeUserSettings();
|
||||
}, inner->lifetime());
|
||||
|
||||
|
@ -1022,26 +1052,25 @@ void SetupSupport(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
AddSubsectionTitle(inner, rpl::single(qsl("Load chats for a period")));
|
||||
|
||||
SetupSupportChatsLimitSlice(inner);
|
||||
SetupSupportChatsLimitSlice(controller, inner);
|
||||
|
||||
AddSkip(inner, st::settingsCheckboxesSkip);
|
||||
|
||||
AddSkip(inner);
|
||||
}
|
||||
|
||||
Chat::Chat(QWidget *parent, not_null<UserData*> self)
|
||||
: Section(parent)
|
||||
, _self(self) {
|
||||
setupContent();
|
||||
Chat::Chat(QWidget *parent, not_null<Window::SessionController*> controller)
|
||||
: Section(parent) {
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
void Chat::setupContent() {
|
||||
void Chat::setupContent(not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
SetupThemeOptions(content);
|
||||
SetupChatBackground(content);
|
||||
SetupChatBackground(controller, content);
|
||||
SetupStickersEmoji(content);
|
||||
SetupMessages(content);
|
||||
SetupMessages(controller, content);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
|
|
@ -11,19 +11,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace Settings {
|
||||
|
||||
void SetupDataStorage(not_null<Ui::VerticalLayout*> container);
|
||||
void SetupAutoDownload(not_null<Ui::VerticalLayout*> container);
|
||||
void SetupDataStorage(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
void SetupAutoDownload(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
void SetupDefaultThemes(not_null<Ui::VerticalLayout*> container);
|
||||
void SetupSupport(not_null<Ui::VerticalLayout*> container);
|
||||
void SetupSupport(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
class Chat : public Section {
|
||||
public:
|
||||
Chat(QWidget *parent, not_null<UserData*> self);
|
||||
Chat(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
|
||||
not_null<UserData*> _self;
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace Settings {
|
||||
|
||||
auto GenerateCodes() {
|
||||
auto codes = std::map<QString, Fn<void()>>();
|
||||
codes.emplace(qsl("debugmode"), [] {
|
||||
auto codes = std::map<QString, Fn<void(::Main::Session*)>>();
|
||||
codes.emplace(qsl("debugmode"), [](::Main::Session *session) {
|
||||
QString text = Logs::DebugEnabled()
|
||||
? qsl("Do you want to disable DEBUG logs?")
|
||||
: qsl("Do you want to enable DEBUG logs?\n\n"
|
||||
|
@ -37,24 +37,24 @@ auto GenerateCodes() {
|
|||
Core::App().switchDebugMode();
|
||||
}));
|
||||
});
|
||||
codes.emplace(qsl("viewlogs"), [] {
|
||||
codes.emplace(qsl("viewlogs"), [](::Main::Session *session) {
|
||||
File::ShowInFolder(cWorkingDir() + "log.txt");
|
||||
});
|
||||
codes.emplace(qsl("testmode"), [] {
|
||||
codes.emplace(qsl("testmode"), [](::Main::Session *session) {
|
||||
auto text = cTestMode() ? qsl("Do you want to disable TEST mode?") : qsl("Do you want to enable TEST mode?\n\nYou will be switched to test cloud.");
|
||||
Ui::show(Box<ConfirmBox>(text, [] {
|
||||
Core::App().switchTestMode();
|
||||
}));
|
||||
});
|
||||
if (!Core::UpdaterDisabled()) {
|
||||
codes.emplace(qsl("testupdate"), [] {
|
||||
codes.emplace(qsl("testupdate"), [](::Main::Session *session) {
|
||||
Core::UpdateChecker().test();
|
||||
});
|
||||
}
|
||||
codes.emplace(qsl("loadlang"), [] {
|
||||
codes.emplace(qsl("loadlang"), [](::Main::Session *session) {
|
||||
Lang::CurrentCloudManager().switchToLanguage({ qsl("#custom") });
|
||||
});
|
||||
codes.emplace(qsl("debugfiles"), [] {
|
||||
codes.emplace(qsl("debugfiles"), [](::Main::Session *session) {
|
||||
if (!Logs::DebugEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
@ -65,39 +65,39 @@ auto GenerateCodes() {
|
|||
}
|
||||
Ui::show(Box<InformBox>(DebugLogging::FileLoader() ? qsl("Enabled file download logging") : qsl("Disabled file download logging")));
|
||||
});
|
||||
codes.emplace(qsl("crashplease"), [] {
|
||||
codes.emplace(qsl("crashplease"), [](::Main::Session *session) {
|
||||
Unexpected("Crashed in Settings!");
|
||||
});
|
||||
codes.emplace(qsl("workmode"), [] {
|
||||
codes.emplace(qsl("workmode"), [](::Main::Session *session) {
|
||||
auto text = Global::DialogsModeEnabled() ? qsl("Disable work mode?") : qsl("Enable work mode?");
|
||||
Ui::show(Box<ConfirmBox>(text, [] {
|
||||
Core::App().switchWorkMode();
|
||||
}));
|
||||
});
|
||||
codes.emplace(qsl("moderate"), [] {
|
||||
codes.emplace(qsl("moderate"), [](::Main::Session *session) {
|
||||
auto text = Global::ModerateModeEnabled() ? qsl("Disable moderate mode?") : qsl("Enable moderate mode?");
|
||||
Ui::show(Box<ConfirmBox>(text, []() {
|
||||
Ui::show(Box<ConfirmBox>(text, [] {
|
||||
Global::SetModerateModeEnabled(!Global::ModerateModeEnabled());
|
||||
Local::writeUserSettings();
|
||||
Ui::hideLayer();
|
||||
}));
|
||||
});
|
||||
codes.emplace(qsl("getdifference"), [] {
|
||||
codes.emplace(qsl("getdifference"), [](::Main::Session *session) {
|
||||
if (auto main = App::main()) {
|
||||
main->getDifference();
|
||||
}
|
||||
});
|
||||
codes.emplace(qsl("loadcolors"), [] {
|
||||
codes.emplace(qsl("loadcolors"), [](::Main::Session *session) {
|
||||
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open palette file", "Palette (*.tdesktop-palette)", [](const FileDialog::OpenResult &result) {
|
||||
if (!result.paths.isEmpty()) {
|
||||
Window::Theme::Apply(result.paths.front());
|
||||
}
|
||||
});
|
||||
});
|
||||
codes.emplace(qsl("edittheme"), [] {
|
||||
codes.emplace(qsl("edittheme"), [](::Main::Session *session) {
|
||||
Window::Theme::Editor::Start();
|
||||
});
|
||||
codes.emplace(qsl("videoplayer"), [] {
|
||||
codes.emplace(qsl("videoplayer"), [](::Main::Session *session) {
|
||||
auto text = cUseExternalVideoPlayer() ? qsl("Use internal video player?") : qsl("Use external video player?");
|
||||
Ui::show(Box<ConfirmBox>(text, [] {
|
||||
cSetUseExternalVideoPlayer(!cUseExternalVideoPlayer());
|
||||
|
@ -105,7 +105,7 @@ auto GenerateCodes() {
|
|||
Ui::hideLayer();
|
||||
}));
|
||||
});
|
||||
codes.emplace(qsl("endpoints"), [] {
|
||||
codes.emplace(qsl("endpoints"), [](::Main::Session *session) {
|
||||
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open DC endpoints", "DC Endpoints (*.tdesktop-endpoints)", [](const FileDialog::OpenResult &result) {
|
||||
if (!result.paths.isEmpty()) {
|
||||
if (!Core::App().dcOptions()->loadFromFile(result.paths.front())) {
|
||||
|
@ -114,12 +114,12 @@ auto GenerateCodes() {
|
|||
}
|
||||
});
|
||||
});
|
||||
codes.emplace(qsl("registertg"), [] {
|
||||
codes.emplace(qsl("registertg"), [](::Main::Session *session) {
|
||||
Platform::RegisterCustomScheme();
|
||||
Ui::Toast::Show("Forced custom scheme register.");
|
||||
});
|
||||
codes.emplace(qsl("export"), [] {
|
||||
Auth().data().startExport();
|
||||
codes.emplace(qsl("export"), [](::Main::Session *session) {
|
||||
session->data().startExport();
|
||||
});
|
||||
|
||||
auto audioFilters = qsl("Audio files (*.wav *.mp3);;") + FileDialog::AllFilesFilter();
|
||||
|
@ -132,28 +132,28 @@ auto GenerateCodes() {
|
|||
qsl("call_end"),
|
||||
};
|
||||
for (auto &key : audioKeys) {
|
||||
codes.emplace(key, [audioFilters, key] {
|
||||
if (!Main::Session::Exists()) {
|
||||
codes.emplace(key, [=](::Main::Session *session) {
|
||||
if (!session) {
|
||||
return;
|
||||
}
|
||||
|
||||
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, [key](const FileDialog::OpenResult &result) {
|
||||
FileDialog::GetOpenPath(Core::App().getFileDialogParent(), "Open audio file", audioFilters, crl::guard(session, [=](const FileDialog::OpenResult &result) {
|
||||
if (Main::Session::Exists() && !result.paths.isEmpty()) {
|
||||
auto track = Media::Audio::Current().createTrack();
|
||||
track->fillFromFile(result.paths.front());
|
||||
if (track->failed()) {
|
||||
Ui::show(Box<InformBox>("Could not audio :( Errors in 'log.txt'."));
|
||||
} else {
|
||||
Auth().settings().setSoundOverride(key, result.paths.front());
|
||||
session->settings().setSoundOverride(key, result.paths.front());
|
||||
Local::writeUserSettings();
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
codes.emplace(qsl("sounds_reset"), [] {
|
||||
if (Main::Session::Exists()) {
|
||||
Auth().settings().clearSoundOverrides();
|
||||
codes.emplace(qsl("sounds_reset"), [](::Main::Session *session) {
|
||||
if (session) {
|
||||
session->settings().clearSoundOverrides();
|
||||
Local::writeUserSettings();
|
||||
Ui::show(Box<InformBox>("All sound overrides were reset."));
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ auto GenerateCodes() {
|
|||
return codes;
|
||||
}
|
||||
|
||||
void CodesFeedString(const QString &text) {
|
||||
void CodesFeedString(::Main::Session *session, const QString &text) {
|
||||
static const auto codes = GenerateCodes();
|
||||
static auto secret = QString();
|
||||
|
||||
|
@ -172,7 +172,7 @@ void CodesFeedString(const QString &text) {
|
|||
auto found = false;
|
||||
for (const auto &[key, method] : codes) {
|
||||
if (piece == key) {
|
||||
method();
|
||||
method(session);
|
||||
from = size;
|
||||
found = true;
|
||||
break;
|
||||
|
|
|
@ -7,8 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Settings {
|
||||
|
||||
void CodesFeedString(const QString &text);
|
||||
void CodesFeedString(::Main::Session *session, const QString &text);
|
||||
|
||||
} // namespace Settings
|
||||
|
|
|
@ -30,23 +30,22 @@ namespace Settings {
|
|||
object_ptr<Section> CreateSection(
|
||||
Type type,
|
||||
not_null<QWidget*> parent,
|
||||
Window::SessionController *controller,
|
||||
UserData *self) {
|
||||
not_null<Window::SessionController*> controller) {
|
||||
switch (type) {
|
||||
case Type::Main:
|
||||
return object_ptr<Main>(parent, controller, self);
|
||||
return object_ptr<Main>(parent, controller);
|
||||
case Type::Information:
|
||||
return object_ptr<Information>(parent, controller, self);
|
||||
return object_ptr<Information>(parent, controller);
|
||||
case Type::Notifications:
|
||||
return object_ptr<Notifications>(parent, self);
|
||||
return object_ptr<Notifications>(parent, controller);
|
||||
case Type::PrivacySecurity:
|
||||
return object_ptr<PrivacySecurity>(parent, self);
|
||||
return object_ptr<PrivacySecurity>(parent, controller);
|
||||
case Type::Advanced:
|
||||
return object_ptr<Advanced>(parent, self);
|
||||
return object_ptr<Advanced>(parent, controller);
|
||||
case Type::Chat:
|
||||
return object_ptr<Chat>(parent, self);
|
||||
return object_ptr<Chat>(parent, controller);
|
||||
case Type::Calls:
|
||||
return object_ptr<Calls>(parent, self);
|
||||
return object_ptr<Calls>(parent, controller);
|
||||
}
|
||||
Unexpected("Settings section type in Widget::createInnerWidget.");
|
||||
}
|
||||
|
@ -170,8 +169,11 @@ void AddSubsectionTitle(
|
|||
st::settingsSubsectionTitlePadding);
|
||||
}
|
||||
|
||||
void FillMenu(Fn<void(Type)> showOther, MenuCallback addAction) {
|
||||
if (!Auth().supportMode()) {
|
||||
void FillMenu(
|
||||
not_null<::Main::Session*> session,
|
||||
Fn<void(Type)> showOther,
|
||||
MenuCallback addAction) {
|
||||
if (!session->supportMode()) {
|
||||
addAction(
|
||||
tr::lng_settings_information(tr::now),
|
||||
[=] { showOther(Type::Information); });
|
||||
|
|
|
@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
@ -60,8 +64,7 @@ public:
|
|||
object_ptr<Section> CreateSection(
|
||||
Type type,
|
||||
not_null<QWidget*> parent,
|
||||
Window::SessionController *controller = nullptr,
|
||||
UserData *self = nullptr);
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
void AddSkip(not_null<Ui::VerticalLayout*> container);
|
||||
void AddSkip(not_null<Ui::VerticalLayout*> container, int skip);
|
||||
|
@ -96,6 +99,7 @@ using MenuCallback = Fn<QAction*(
|
|||
Fn<void()> handler)>;
|
||||
|
||||
void FillMenu(
|
||||
not_null<::Main::Session*> session,
|
||||
Fn<void(Type)> showOther,
|
||||
MenuCallback addAction);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "info/profile/info_profile_button.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "apiwrap.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
@ -79,7 +80,9 @@ void SetupPhoto(
|
|||
Box<PhotoCropBox>(image, tr::lng_settings_crop_profile(tr::now)));
|
||||
box->ready(
|
||||
) | rpl::start_with_next([=](QImage &&image) {
|
||||
Auth().api().uploadPeerPhoto(self, std::move(image));
|
||||
self->session().api().uploadPeerPhoto(
|
||||
self,
|
||||
std::move(image));
|
||||
}, box->lifetime());
|
||||
};
|
||||
FileDialog::GetOpenPath(
|
||||
|
@ -229,7 +232,7 @@ void SetupRows(
|
|||
tr::lng_settings_phone_label(),
|
||||
Info::Profile::PhoneValue(self),
|
||||
tr::lng_profile_copy_phone(tr::now),
|
||||
[] { Ui::show(Box<ChangePhoneBox>()); },
|
||||
[=] { Ui::show(Box<ChangePhoneBox>(&self->session())); },
|
||||
st::settingsInfoPhone);
|
||||
|
||||
auto username = Info::Profile::UsernameValue(self);
|
||||
|
@ -333,7 +336,7 @@ BioManager SetupBio(
|
|||
countdown->setText(QString::number(countLeft));
|
||||
};
|
||||
const auto save = [=](FnMut<void()> done) {
|
||||
Auth().api().saveSelfBio(
|
||||
self->session().api().saveSelfBio(
|
||||
TextUtilities::PrepareForSending(bio->getLastText()),
|
||||
std::move(done));
|
||||
};
|
||||
|
@ -408,10 +411,8 @@ BioManager SetupBio(
|
|||
|
||||
Information::Information(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<UserData*> self)
|
||||
: Section(parent)
|
||||
, _self(self) {
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent) {
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
|
@ -423,13 +424,15 @@ Information::Information(
|
|||
// _save(std::move(done));
|
||||
//}
|
||||
|
||||
void Information::setupContent(not_null<Window::SessionController*> controller) {
|
||||
void Information::setupContent(
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
SetupPhoto(content, controller, _self);
|
||||
SetupRows(content, _self);
|
||||
SetupBio(content, _self);
|
||||
//auto manager = SetupBio(content, _self);
|
||||
const auto self = controller->session().user();
|
||||
SetupPhoto(content, controller, self);
|
||||
SetupRows(content, self);
|
||||
SetupBio(content, self);
|
||||
//auto manager = SetupBio(content, self);
|
||||
//_canSaveChanges = std::move(manager.canSave);
|
||||
//_save = std::move(manager.save);
|
||||
|
||||
|
|
|
@ -15,13 +15,11 @@ class Information : public Section {
|
|||
public:
|
||||
Information(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<UserData*> self);
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
private:
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
|
||||
not_null<UserData*> _self;
|
||||
//rpl::variable<bool> _canSaveChanges;
|
||||
//Fn<void(FnMut<void()> done)> _save;
|
||||
|
||||
|
|
|
@ -345,7 +345,7 @@ void IntroWidget::resizeEvent(QResizeEvent *e) {
|
|||
}
|
||||
|
||||
void IntroWidget::keyPressEvent(QKeyEvent *e) {
|
||||
CodesFeedString(e->text());
|
||||
CodesFeedString(nullptr, e->text());
|
||||
return RpWidget::keyPressEvent(e);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ void SetupLanguageButton(
|
|||
}
|
||||
|
||||
void SetupSections(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(Type)> showOther) {
|
||||
AddDivider(container);
|
||||
|
@ -71,8 +72,8 @@ void SetupSections(
|
|||
icon
|
||||
)->addClickHandler([=] { showOther(type); });
|
||||
};
|
||||
if (Auth().supportMode()) {
|
||||
SetupSupport(container);
|
||||
if (controller->session().supportMode()) {
|
||||
SetupSupport(controller, container);
|
||||
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
|
@ -227,51 +228,50 @@ void SetupFaq(not_null<Ui::VerticalLayout*> container, bool icon) {
|
|||
)->addClickHandler(OpenFaq);
|
||||
}
|
||||
|
||||
void SetupHelp(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupHelp(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
|
||||
SetupFaq(container);
|
||||
|
||||
if (::Main::Session::Exists()) {
|
||||
const auto button = AddButton(
|
||||
container,
|
||||
tr::lng_settings_ask_question(),
|
||||
st::settingsSectionButton);
|
||||
button->addClickHandler([=] {
|
||||
const auto ready = crl::guard(button, [](const MTPUser &data) {
|
||||
if (const auto user = Auth().data().processUser(data)) {
|
||||
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
|
||||
}
|
||||
});
|
||||
const auto sure = crl::guard(button, [=] {
|
||||
Auth().api().requestSupportContact(ready);
|
||||
});
|
||||
auto box = Box<ConfirmBox>(
|
||||
tr::lng_settings_ask_sure(tr::now),
|
||||
tr::lng_settings_ask_ok(tr::now),
|
||||
tr::lng_settings_faq_button(tr::now),
|
||||
sure,
|
||||
OpenFaq);
|
||||
box->setStrictCancel(true);
|
||||
Ui::show(std::move(box));
|
||||
const auto button = AddButton(
|
||||
container,
|
||||
tr::lng_settings_ask_question(),
|
||||
st::settingsSectionButton);
|
||||
button->addClickHandler([=] {
|
||||
const auto ready = crl::guard(button, [=](const MTPUser &data) {
|
||||
if (const auto user = controller->session().data().processUser(data)) {
|
||||
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
|
||||
}
|
||||
});
|
||||
}
|
||||
const auto sure = crl::guard(button, [=] {
|
||||
controller->session().api().requestSupportContact(ready);
|
||||
});
|
||||
auto box = Box<ConfirmBox>(
|
||||
tr::lng_settings_ask_sure(tr::now),
|
||||
tr::lng_settings_ask_ok(tr::now),
|
||||
tr::lng_settings_faq_button(tr::now),
|
||||
sure,
|
||||
OpenFaq);
|
||||
box->setStrictCancel(true);
|
||||
Ui::show(std::move(box));
|
||||
});
|
||||
|
||||
AddSkip(container);
|
||||
}
|
||||
|
||||
Main::Main(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<UserData*> self)
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent)
|
||||
, _self(self) {
|
||||
, _controller(controller) {
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
void Main::keyPressEvent(QKeyEvent *e) {
|
||||
CodesFeedString(e->text());
|
||||
CodesFeedString(&_controller->session(), e->text());
|
||||
return Section::keyPressEvent(e);
|
||||
}
|
||||
|
||||
|
@ -280,11 +280,11 @@ void Main::setupContent(not_null<Window::SessionController*> controller) {
|
|||
|
||||
const auto cover = content->add(object_ptr<Info::Profile::Cover>(
|
||||
content,
|
||||
_self,
|
||||
controller->session().user(),
|
||||
controller));
|
||||
cover->setOnlineCount(rpl::single(0));
|
||||
|
||||
SetupSections(content, [=](Type type) {
|
||||
SetupSections(controller, content, [=](Type type) {
|
||||
_showOther.fire_copy(type);
|
||||
});
|
||||
if (HasInterfaceScale()) {
|
||||
|
@ -293,7 +293,7 @@ void Main::setupContent(not_null<Window::SessionController*> controller) {
|
|||
SetupInterfaceScale(content);
|
||||
AddSkip(content);
|
||||
}
|
||||
SetupHelp(content);
|
||||
SetupHelp(controller, content);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
|
||||
|
|
|
@ -32,10 +32,7 @@ void SetupFaq(
|
|||
|
||||
class Main : public Section {
|
||||
public:
|
||||
Main(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<UserData*> self);
|
||||
Main(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||
|
||||
rpl::producer<Type> sectionShowOther() override;
|
||||
|
||||
|
@ -45,7 +42,7 @@ protected:
|
|||
private:
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
|
||||
not_null<UserData*> _self;
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
rpl::event_stream<Type> _showOther;
|
||||
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "info/profile/info_profile_button.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "window/notifications_manager.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "platform/platform_notifications_manager.h"
|
||||
#include "platform/platform_info.h"
|
||||
#include "mainwindow.h"
|
||||
|
@ -42,7 +43,9 @@ using ChangeType = Window::Notifications::ChangeType;
|
|||
|
||||
class NotificationsCount : public Ui::RpWidget {
|
||||
public:
|
||||
NotificationsCount(QWidget *parent);
|
||||
NotificationsCount(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
void setCount(int count);
|
||||
|
||||
|
@ -72,6 +75,8 @@ private:
|
|||
void prepareNotificationSampleLarge();
|
||||
void prepareNotificationSampleUserpic();
|
||||
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
|
||||
QPixmap _notificationSampleUserpic;
|
||||
QPixmap _notificationSampleSmall;
|
||||
QPixmap _notificationSampleLarge;
|
||||
|
@ -114,8 +119,11 @@ private:
|
|||
|
||||
};
|
||||
|
||||
NotificationsCount::NotificationsCount(QWidget *parent)
|
||||
: _chosenCorner(Global::NotificationsCorner())
|
||||
NotificationsCount::NotificationsCount(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: _controller(controller)
|
||||
, _chosenCorner(Global::NotificationsCorner())
|
||||
, _oldCount(CurrentCount()) {
|
||||
setMouseTracking(true);
|
||||
|
||||
|
@ -176,7 +184,8 @@ void NotificationsCount::setCount(int count) {
|
|||
|
||||
if (count != Global::NotificationsCount()) {
|
||||
Global::SetNotificationsCount(count);
|
||||
Auth().notifications().settingsChanged().notify(ChangeType::MaxCount);
|
||||
_controller->session().notifications().settingsChanged().notify(
|
||||
ChangeType::MaxCount);
|
||||
Local::writeUserSettings();
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +349,8 @@ void NotificationsCount::setOverCorner(Notify::ScreenCorner corner) {
|
|||
_isOverCorner = true;
|
||||
setCursor(style::cur_pointer);
|
||||
Global::SetNotificationsDemoIsShown(true);
|
||||
Auth().notifications().settingsChanged().notify(ChangeType::DemoIsShown);
|
||||
_controller->session().notifications().settingsChanged().notify(
|
||||
ChangeType::DemoIsShown);
|
||||
}
|
||||
_overCorner = corner;
|
||||
|
||||
|
@ -375,10 +385,10 @@ void NotificationsCount::clearOverCorner() {
|
|||
_isOverCorner = false;
|
||||
setCursor(style::cur_default);
|
||||
Global::SetNotificationsDemoIsShown(false);
|
||||
Auth().notifications().settingsChanged().notify(ChangeType::DemoIsShown);
|
||||
_controller->session().notifications().settingsChanged().notify(ChangeType::DemoIsShown);
|
||||
|
||||
for_const (auto &samples, _cornerSamples) {
|
||||
for_const (auto widget, samples) {
|
||||
for_const (const auto &samples, _cornerSamples) {
|
||||
for_const (const auto widget, samples) {
|
||||
widget->hideFast();
|
||||
}
|
||||
}
|
||||
|
@ -392,13 +402,17 @@ void NotificationsCount::mousePressEvent(QMouseEvent *e) {
|
|||
|
||||
void NotificationsCount::mouseReleaseEvent(QMouseEvent *e) {
|
||||
auto isDownCorner = base::take(_isDownCorner);
|
||||
if (isDownCorner && _isOverCorner && _downCorner == _overCorner && _downCorner != _chosenCorner) {
|
||||
if (isDownCorner
|
||||
&& _isOverCorner
|
||||
&& _downCorner == _overCorner
|
||||
&& _downCorner != _chosenCorner) {
|
||||
_chosenCorner = _downCorner;
|
||||
update();
|
||||
|
||||
if (_chosenCorner != Global::NotificationsCorner()) {
|
||||
Global::SetNotificationsCorner(_chosenCorner);
|
||||
Auth().notifications().settingsChanged().notify(ChangeType::Corner);
|
||||
_controller->session().notifications().settingsChanged().notify(
|
||||
ChangeType::Corner);
|
||||
Local::writeUserSettings();
|
||||
}
|
||||
}
|
||||
|
@ -487,7 +501,9 @@ void NotificationsCount::SampleWidget::destroyDelayed() {
|
|||
#endif // Q_OS_LINUX32 || Q_OS_LINUX64
|
||||
}
|
||||
|
||||
void SetupAdvancedNotifications(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupAdvancedNotifications(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddDivider(container);
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
|
@ -495,7 +511,7 @@ void SetupAdvancedNotifications(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
|
||||
const auto position = container->add(
|
||||
object_ptr<NotificationsCount>(container));
|
||||
object_ptr<NotificationsCount>(container, controller));
|
||||
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddSubsectionTitle(container, tr::lng_settings_notifications_count());
|
||||
|
@ -514,9 +530,12 @@ void SetupAdvancedNotifications(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
}
|
||||
|
||||
void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupNotificationsContent(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSubsectionTitle(container, tr::lng_settings_notify_title());
|
||||
|
||||
const auto session = &controller->session();
|
||||
const auto checkbox = [&](const QString &label, bool checked) {
|
||||
return object_ptr<Ui::Checkbox>(
|
||||
container,
|
||||
|
@ -556,10 +575,10 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
const auto muted = addCheckbox(
|
||||
tr::lng_settings_include_muted(tr::now),
|
||||
Auth().settings().includeMutedCounter());
|
||||
session->settings().includeMutedCounter());
|
||||
const auto count = addCheckbox(
|
||||
tr::lng_settings_count_unread(tr::now),
|
||||
Auth().settings().countUnreadMessages());
|
||||
session->settings().countUnreadMessages());
|
||||
|
||||
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
|
@ -569,32 +588,32 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
const auto joined = addCheckbox(
|
||||
tr::lng_settings_events_joined(tr::now),
|
||||
!Auth().api().contactSignupSilentCurrent().value_or(false));
|
||||
Auth().api().contactSignupSilent(
|
||||
!session->api().contactSignupSilentCurrent().value_or(false));
|
||||
session->api().contactSignupSilent(
|
||||
) | rpl::start_with_next([=](bool silent) {
|
||||
joined->setChecked(!silent);
|
||||
}, joined->lifetime());
|
||||
joined->checkedChanges(
|
||||
) | rpl::filter([](bool enabled) {
|
||||
const auto silent = Auth().api().contactSignupSilentCurrent();
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
const auto silent = session->api().contactSignupSilentCurrent();
|
||||
return (enabled == silent.value_or(false));
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
Auth().api().saveContactSignupSilent(!enabled);
|
||||
session->api().saveContactSignupSilent(!enabled);
|
||||
}, joined->lifetime());
|
||||
|
||||
const auto pinned = addCheckbox(
|
||||
tr::lng_settings_events_pinned(tr::now),
|
||||
Auth().settings().notifyAboutPinned());
|
||||
Auth().settings().notifyAboutPinnedChanges(
|
||||
session->settings().notifyAboutPinned());
|
||||
session->settings().notifyAboutPinnedChanges(
|
||||
) | rpl::start_with_next([=](bool notify) {
|
||||
pinned->setChecked(notify);
|
||||
}, pinned->lifetime());
|
||||
pinned->checkedChanges(
|
||||
) | rpl::filter([](bool notify) {
|
||||
return (notify != Auth().settings().notifyAboutPinned());
|
||||
) | rpl::filter([=](bool notify) {
|
||||
return (notify != session->settings().notifyAboutPinned());
|
||||
}) | rpl::start_with_next([=](bool notify) {
|
||||
Auth().settings().setNotifyAboutPinned(notify);
|
||||
Auth().saveSettingsDelayed();
|
||||
session->settings().setNotifyAboutPinned(notify);
|
||||
session->saveSettingsDelayed();
|
||||
}, joined->lifetime());
|
||||
|
||||
const auto nativeText = [&] {
|
||||
|
@ -629,7 +648,7 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
? advancedSlide->entity()
|
||||
: nullptr;
|
||||
if (advancedWrap) {
|
||||
SetupAdvancedNotifications(advancedWrap);
|
||||
SetupAdvancedNotifications(controller, advancedWrap);
|
||||
}
|
||||
|
||||
if (!name->entity()->checked()) {
|
||||
|
@ -644,9 +663,9 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
|
||||
using Change = Window::Notifications::ChangeType;
|
||||
const auto changed = [](Change change) {
|
||||
const auto changed = [=](Change change) {
|
||||
Local::writeUserSettings();
|
||||
Auth().notifications().settingsChanged().notify(change);
|
||||
session->notifications().settingsChanged().notify(change);
|
||||
};
|
||||
desktop->checkedChanges(
|
||||
) | rpl::filter([](bool checked) {
|
||||
|
@ -695,23 +714,23 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
}, sound->lifetime());
|
||||
|
||||
muted->checkedChanges(
|
||||
) | rpl::filter([](bool checked) {
|
||||
return (checked != Auth().settings().includeMutedCounter());
|
||||
) | rpl::filter([=](bool checked) {
|
||||
return (checked != session->settings().includeMutedCounter());
|
||||
}) | rpl::start_with_next([=](bool checked) {
|
||||
Auth().settings().setIncludeMutedCounter(checked);
|
||||
session->settings().setIncludeMutedCounter(checked);
|
||||
changed(Change::IncludeMuted);
|
||||
}, muted->lifetime());
|
||||
|
||||
count->checkedChanges(
|
||||
) | rpl::filter([](bool checked) {
|
||||
return (checked != Auth().settings().countUnreadMessages());
|
||||
) | rpl::filter([=](bool checked) {
|
||||
return (checked != session->settings().countUnreadMessages());
|
||||
}) | rpl::start_with_next([=](bool checked) {
|
||||
Auth().settings().setCountUnreadMessages(checked);
|
||||
session->settings().setCountUnreadMessages(checked);
|
||||
changed(Change::CountMessages);
|
||||
}, count->lifetime());
|
||||
|
||||
base::ObservableViewer(
|
||||
Auth().notifications().settingsChanged()
|
||||
session->notifications().settingsChanged()
|
||||
) | rpl::start_with_next([=](Change change) {
|
||||
if (change == Change::DesktopEnabled) {
|
||||
desktop->setChecked(Global::DesktopNotify());
|
||||
|
@ -734,7 +753,7 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
Global::SetNativeNotifications(checked);
|
||||
Local::writeUserSettings();
|
||||
|
||||
Auth().notifications().createManager();
|
||||
session->notifications().createManager();
|
||||
|
||||
if (advancedSlide) {
|
||||
advancedSlide->toggle(
|
||||
|
@ -745,11 +764,13 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
}
|
||||
|
||||
void SetupNotifications(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupNotifications(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
|
||||
auto wrap = object_ptr<Ui::VerticalLayout>(container);
|
||||
SetupNotificationsContent(wrap.data());
|
||||
SetupNotificationsContent(controller, wrap.data());
|
||||
|
||||
container->add(object_ptr<Ui::OverrideMargins>(
|
||||
container,
|
||||
|
@ -760,16 +781,18 @@ void SetupNotifications(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
} // namespace
|
||||
|
||||
Notifications::Notifications(QWidget *parent, not_null<UserData*> self)
|
||||
: Section(parent)
|
||||
, _self(self) {
|
||||
setupContent();
|
||||
Notifications::Notifications(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent) {
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
void Notifications::setupContent() {
|
||||
void Notifications::setupContent(
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
SetupNotifications(content);
|
||||
SetupNotifications(controller, content);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ namespace Settings {
|
|||
|
||||
class Notifications : public Section {
|
||||
public:
|
||||
Notifications(QWidget *parent, not_null<UserData*> self);
|
||||
Notifications(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
|
||||
not_null<UserData*> _self;
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/image/image_prepare.h"
|
||||
#include "window/section_widget.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "boxes/peer_list_controllers.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "settings/settings_privacy_security.h"
|
||||
|
@ -154,6 +155,11 @@ AdminLog::OwnedItem GenerateForwardedItem(
|
|||
|
||||
} // namespace
|
||||
|
||||
BlockedBoxController::BlockedBoxController(
|
||||
not_null<Window::SessionController*> window)
|
||||
: _window(window) {
|
||||
}
|
||||
|
||||
void BlockedBoxController::prepare() {
|
||||
delegate()->peerListSetTitle(tr::lng_blocked_list_title());
|
||||
setDescriptionText(tr::lng_contacts_loading(tr::now));
|
||||
|
@ -166,7 +172,7 @@ void BlockedBoxController::prepare() {
|
|||
}));
|
||||
|
||||
_loadRequestId = -1;
|
||||
Auth().api().blockedUsersSlice(
|
||||
_window->session().api().blockedUsersSlice(
|
||||
) | rpl::take(
|
||||
1
|
||||
) | rpl::start_with_next([=](const ApiWrap::BlockedUsersSlice &result) {
|
||||
|
@ -193,8 +199,8 @@ void BlockedBoxController::loadMoreRows() {
|
|||
)).done([=](const MTPcontacts_Blocked &result) {
|
||||
_loadRequestId = 0;
|
||||
|
||||
auto handleContactsBlocked = [](auto &list) {
|
||||
Auth().data().processUsers(list.vusers());
|
||||
auto handleContactsBlocked = [&](auto &list) {
|
||||
_window->session().data().processUsers(list.vusers());
|
||||
return list.vblocked().v;
|
||||
};
|
||||
switch (result.type()) {
|
||||
|
@ -222,7 +228,7 @@ void BlockedBoxController::rowActionClicked(not_null<PeerListRow*> row) {
|
|||
auto user = row->peer()->asUser();
|
||||
Expects(user != nullptr);
|
||||
|
||||
Auth().api().unblockUser(user);
|
||||
_window->session().api().unblockUser(user);
|
||||
}
|
||||
|
||||
void BlockedBoxController::receivedUsers(const QVector<MTPContactBlocked> &result) {
|
||||
|
@ -233,7 +239,7 @@ void BlockedBoxController::receivedUsers(const QVector<MTPContactBlocked> &resul
|
|||
_offset += result.size();
|
||||
for (const auto &item : result) {
|
||||
item.match([&](const MTPDcontactBlocked &data) {
|
||||
if (const auto user = Auth().data().userLoaded(data.vuser_id().v)) {
|
||||
if (const auto user = _window->session().data().userLoaded(data.vuser_id().v)) {
|
||||
appendRow(user);
|
||||
user->setIsBlocked(true);
|
||||
}
|
||||
|
@ -254,11 +260,13 @@ void BlockedBoxController::handleBlockedEvent(not_null<UserData*> user) {
|
|||
}
|
||||
}
|
||||
|
||||
void BlockedBoxController::BlockNewUser() {
|
||||
void BlockedBoxController::BlockNewUser(
|
||||
not_null<Window::SessionController*> window) {
|
||||
auto controller = std::make_unique<BlockUserBoxController>();
|
||||
auto initBox = [controller = controller.get()](not_null<PeerListBox*> box) {
|
||||
controller->setBlockUserCallback([box](not_null<UserData*> user) {
|
||||
Auth().api().blockUser(user);
|
||||
auto initBox = [=, controller = controller.get()](
|
||||
not_null<PeerListBox*> box) {
|
||||
controller->setBlockUserCallback([=](not_null<UserData*> user) {
|
||||
window->session().api().blockUser(user);
|
||||
box->closeBox();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [box] { box->closeBox(); });
|
||||
|
@ -346,6 +354,11 @@ rpl::producer<QString> PhoneNumberPrivacyController::exceptionsDescription() {
|
|||
return tr::lng_edit_privacy_phone_number_exceptions();
|
||||
}
|
||||
|
||||
LastSeenPrivacyController::LastSeenPrivacyController(
|
||||
not_null<::Main::Session*> session)
|
||||
: _session(session) {
|
||||
}
|
||||
|
||||
ApiWrap::Privacy::Key LastSeenPrivacyController::key() {
|
||||
return Key::LastSeen;
|
||||
}
|
||||
|
@ -391,14 +404,15 @@ rpl::producer<QString> LastSeenPrivacyController::exceptionsDescription() {
|
|||
}
|
||||
|
||||
void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, FnMut<void()> saveCallback) {
|
||||
if (someAreDisallowed && !Auth().settings().lastSeenWarningSeen()) {
|
||||
if (someAreDisallowed && !_session->settings().lastSeenWarningSeen()) {
|
||||
const auto session = _session;
|
||||
auto weakBox = std::make_shared<QPointer<ConfirmBox>>();
|
||||
auto callback = [weakBox, saveCallback = std::move(saveCallback)]() mutable {
|
||||
auto callback = [=, saveCallback = std::move(saveCallback)]() mutable {
|
||||
if (auto box = *weakBox) {
|
||||
box->closeBox();
|
||||
}
|
||||
saveCallback();
|
||||
Auth().settings().setLastSeenWarningSeen(true);
|
||||
session->settings().setLastSeenWarningSeen(true);
|
||||
Local::writeUserSettings();
|
||||
};
|
||||
auto box = Box<ConfirmBox>(
|
||||
|
@ -494,6 +508,7 @@ rpl::producer<QString> CallsPrivacyController::exceptionsDescription() {
|
|||
}
|
||||
|
||||
object_ptr<Ui::RpWidget> CallsPrivacyController::setupBelowWidget(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<QWidget*> parent) {
|
||||
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
||||
const auto content = result.data();
|
||||
|
@ -502,6 +517,7 @@ object_ptr<Ui::RpWidget> CallsPrivacyController::setupBelowWidget(
|
|||
AddSkip(content);
|
||||
AddSubsectionTitle(content, tr::lng_settings_calls_peer_to_peer_title());
|
||||
Settings::AddPrivacyButton(
|
||||
controller,
|
||||
content,
|
||||
tr::lng_settings_calls_peer_to_peer_button(),
|
||||
ApiWrap::Privacy::Key::CallsPeer2Peer,
|
||||
|
@ -563,6 +579,11 @@ rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionsDescription()
|
|||
return tr::lng_edit_privacy_calls_p2p_exceptions();
|
||||
}
|
||||
|
||||
ForwardsPrivacyController::ForwardsPrivacyController(
|
||||
not_null<::Main::Session*> session)
|
||||
: _session(session) {
|
||||
}
|
||||
|
||||
ApiWrap::Privacy::Key ForwardsPrivacyController::key() {
|
||||
return Key::Forwards;
|
||||
}
|
||||
|
@ -613,7 +634,7 @@ object_ptr<Ui::RpWidget> ForwardsPrivacyController::setupAboveWidget(
|
|||
|
||||
auto message = GenerateForwardedItem(
|
||||
delegate(),
|
||||
Auth().data().history(
|
||||
_session->data().history(
|
||||
peerFromUser(PeerData::kServiceNotificationsId)),
|
||||
tr::lng_edit_privacy_forwards_sample_message(tr::now));
|
||||
const auto view = message.get();
|
||||
|
|
|
@ -16,12 +16,15 @@ namespace Settings {
|
|||
|
||||
class BlockedBoxController : public PeerListController, private base::Subscriber, private MTP::Sender {
|
||||
public:
|
||||
explicit BlockedBoxController(
|
||||
not_null<Window::SessionController*> window);
|
||||
|
||||
void prepare() override;
|
||||
void rowClicked(not_null<PeerListRow*> row) override;
|
||||
void rowActionClicked(not_null<PeerListRow*> row) override;
|
||||
void loadMoreRows() override;
|
||||
|
||||
static void BlockNewUser();
|
||||
static void BlockNewUser(not_null<Window::SessionController*> window);
|
||||
|
||||
private:
|
||||
void receivedUsers(const QVector<MTPContactBlocked> &result);
|
||||
|
@ -31,6 +34,8 @@ private:
|
|||
bool prependRow(not_null<UserData*> user);
|
||||
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const;
|
||||
|
||||
const not_null<Window::SessionController*> _window;
|
||||
|
||||
int _offset = 0;
|
||||
mtpRequestId _loadRequestId = 0;
|
||||
bool _allLoaded = false;
|
||||
|
@ -60,6 +65,8 @@ public:
|
|||
using Option = EditPrivacyBox::Option;
|
||||
using Exception = EditPrivacyBox::Exception;
|
||||
|
||||
explicit LastSeenPrivacyController(not_null<::Main::Session*> session);
|
||||
|
||||
Key key() override;
|
||||
MTPInputPrivacyKey apiKey() override;
|
||||
|
||||
|
@ -75,6 +82,9 @@ public:
|
|||
bool someAreDisallowed,
|
||||
FnMut<void()> saveCallback) override;
|
||||
|
||||
private:
|
||||
const not_null<::Main::Session*> _session;
|
||||
|
||||
};
|
||||
|
||||
class GroupsInvitePrivacyController : public EditPrivacyController {
|
||||
|
@ -111,6 +121,7 @@ public:
|
|||
rpl::producer<QString> exceptionsDescription() override;
|
||||
|
||||
object_ptr<Ui::RpWidget> setupBelowWidget(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<QWidget*> parent) override;
|
||||
|
||||
};
|
||||
|
@ -141,6 +152,8 @@ public:
|
|||
using Option = EditPrivacyBox::Option;
|
||||
using Exception = EditPrivacyBox::Exception;
|
||||
|
||||
explicit ForwardsPrivacyController(not_null<::Main::Session*> session);
|
||||
|
||||
Key key() override;
|
||||
MTPInputPrivacyKey apiKey() override;
|
||||
|
||||
|
@ -166,6 +179,8 @@ private:
|
|||
not_null<HistoryView::Element*> view,
|
||||
Option value);
|
||||
|
||||
const not_null<::Main::Session*> _session;
|
||||
|
||||
};
|
||||
|
||||
class ProfilePhotoPrivacyController : public EditPrivacyController {
|
||||
|
|
|
@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_chat.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "main/main_session.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
@ -72,9 +73,11 @@ QString PrivacyBase(Privacy::Key key, Privacy::Option option) {
|
|||
}
|
||||
}
|
||||
|
||||
rpl::producer<QString> PrivacyString(Privacy::Key key) {
|
||||
Auth().api().reloadPrivacy(key);
|
||||
return Auth().api().privacyValue(
|
||||
rpl::producer<QString> PrivacyString(
|
||||
not_null<::Main::Session*> session,
|
||||
Privacy::Key key) {
|
||||
session->api().reloadPrivacy(key);
|
||||
return session->api().privacyValue(
|
||||
key
|
||||
) | rpl::map([=](const Privacy &value) {
|
||||
auto add = QStringList();
|
||||
|
@ -93,20 +96,23 @@ rpl::producer<QString> PrivacyString(Privacy::Key key) {
|
|||
});
|
||||
}
|
||||
|
||||
rpl::producer<int> BlockedUsersCount() {
|
||||
Auth().api().reloadBlockedUsers();
|
||||
return Auth().api().blockedUsersSlice(
|
||||
rpl::producer<int> BlockedUsersCount(not_null<::Main::Session*> session) {
|
||||
session->api().reloadBlockedUsers();
|
||||
return session->api().blockedUsersSlice(
|
||||
) | rpl::map([=](const ApiWrap::BlockedUsersSlice &data) {
|
||||
return data.total;
|
||||
});
|
||||
}
|
||||
|
||||
void SetupPrivacy(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupPrivacy(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container, st::settingsPrivacySkip);
|
||||
AddSubsectionTitle(container, tr::lng_settings_privacy_title());
|
||||
|
||||
const auto session = &controller->session();
|
||||
auto count = rpl::combine(
|
||||
BlockedUsersCount(),
|
||||
BlockedUsersCount(session),
|
||||
tr::lng_settings_no_blocked_users()
|
||||
) | rpl::map([](int count, const QString &none) {
|
||||
return count ? QString::number(count) : none;
|
||||
|
@ -116,17 +122,17 @@ void SetupPrivacy(not_null<Ui::VerticalLayout*> container) {
|
|||
tr::lng_settings_blocked_users(),
|
||||
std::move(count),
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
const auto initBox = [](not_null<PeerListBox*> box) {
|
||||
)->addClickHandler([=] {
|
||||
const auto initBox = [=](not_null<PeerListBox*> box) {
|
||||
box->addButton(tr::lng_close(), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
box->addLeftButton(tr::lng_blocked_list_add(), [] {
|
||||
BlockedBoxController::BlockNewUser();
|
||||
box->addLeftButton(tr::lng_blocked_list_add(), [=] {
|
||||
BlockedBoxController::BlockNewUser(controller);
|
||||
});
|
||||
};
|
||||
Ui::show(Box<PeerListBox>(
|
||||
std::make_unique<BlockedBoxController>(),
|
||||
std::make_unique<BlockedBoxController>(controller),
|
||||
initBox));
|
||||
});
|
||||
|
||||
|
@ -134,8 +140,13 @@ void SetupPrivacy(not_null<Ui::VerticalLayout*> container) {
|
|||
const auto add = [&](
|
||||
rpl::producer<QString> label,
|
||||
Key key,
|
||||
auto controller) {
|
||||
AddPrivacyButton(container, std::move(label), key, controller);
|
||||
auto controllerFactory) {
|
||||
AddPrivacyButton(
|
||||
controller,
|
||||
container,
|
||||
std::move(label),
|
||||
key,
|
||||
controllerFactory);
|
||||
};
|
||||
add(
|
||||
tr::lng_settings_phone_number_privacy(),
|
||||
|
@ -144,11 +155,11 @@ void SetupPrivacy(not_null<Ui::VerticalLayout*> container) {
|
|||
add(
|
||||
tr::lng_settings_last_seen(),
|
||||
Key::LastSeen,
|
||||
[] { return std::make_unique<LastSeenPrivacyController>(); });
|
||||
[=] { return std::make_unique<LastSeenPrivacyController>(session); });
|
||||
add(
|
||||
tr::lng_settings_forwards_privacy(),
|
||||
Key::Forwards,
|
||||
[] { return std::make_unique<ForwardsPrivacyController>(); });
|
||||
[=] { return std::make_unique<ForwardsPrivacyController>(session); });
|
||||
add(
|
||||
tr::lng_settings_profile_photo_privacy(),
|
||||
Key::ProfilePhoto,
|
||||
|
@ -175,7 +186,9 @@ not_null<Ui::SlideWrap<Ui::PlainShadow>*> AddSeparator(
|
|||
st::settingsSeparatorPadding));
|
||||
}
|
||||
|
||||
void SetupLocalPasscode(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupLocalPasscode(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container);
|
||||
AddSubsectionTitle(container, tr::lng_settings_passcode_title());
|
||||
|
||||
|
@ -195,8 +208,8 @@ void SetupLocalPasscode(not_null<Ui::VerticalLayout*> container) {
|
|||
container,
|
||||
std::move(text),
|
||||
st::settingsButton)
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<PasscodeBox>(false));
|
||||
)->addClickHandler([=] {
|
||||
Ui::show(Box<PasscodeBox>(&controller->session(), false));
|
||||
});
|
||||
|
||||
const auto wrap = container->add(
|
||||
|
@ -209,8 +222,8 @@ void SetupLocalPasscode(not_null<Ui::VerticalLayout*> container) {
|
|||
inner,
|
||||
tr::lng_settings_passcode_disable(),
|
||||
st::settingsButton)
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<PasscodeBox>(true));
|
||||
)->addClickHandler([=] {
|
||||
Ui::show(Box<PasscodeBox>(&controller->session(), true));
|
||||
});
|
||||
|
||||
const auto label = Platform::LastUserInputTimeSupported()
|
||||
|
@ -229,8 +242,8 @@ void SetupLocalPasscode(not_null<Ui::VerticalLayout*> container) {
|
|||
label(),
|
||||
std::move(value),
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<AutoLockBox>());
|
||||
)->addClickHandler([=] {
|
||||
Ui::show(Box<AutoLockBox>(&controller->session()));
|
||||
});
|
||||
|
||||
wrap->toggleOn(base::duplicate(has));
|
||||
|
@ -238,7 +251,9 @@ void SetupLocalPasscode(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container);
|
||||
}
|
||||
|
||||
void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupCloudPassword(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
using namespace rpl::mappers;
|
||||
using State = Core::CloudPasswordState;
|
||||
|
||||
|
@ -246,15 +261,16 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container);
|
||||
AddSubsectionTitle(container, tr::lng_settings_password_title());
|
||||
|
||||
const auto session = &controller->session();
|
||||
auto has = rpl::single(
|
||||
false
|
||||
) | rpl::then(Auth().api().passwordState(
|
||||
) | rpl::then(controller->session().api().passwordState(
|
||||
) | rpl::map([](const State &state) {
|
||||
return state.request
|
||||
|| state.unknownAlgorithm
|
||||
|| !state.unconfirmedPattern.isEmpty();
|
||||
})) | rpl::distinct_until_changed();
|
||||
auto pattern = Auth().api().passwordState(
|
||||
auto pattern = session->api().passwordState(
|
||||
) | rpl::map([](const State &state) {
|
||||
return state.unconfirmedPattern;
|
||||
});
|
||||
|
@ -318,9 +334,9 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
|
|||
) | rpl::map(
|
||||
!_1
|
||||
))->setDuration(0);
|
||||
change->entity()->addClickHandler([] {
|
||||
if (CheckEditCloudPassword()) {
|
||||
Ui::show(EditCloudPasswordBox(&Auth()));
|
||||
change->entity()->addClickHandler([=] {
|
||||
if (CheckEditCloudPassword(session)) {
|
||||
Ui::show(EditCloudPasswordBox(session));
|
||||
} else {
|
||||
Ui::show(CloudPasswordAppOutdatedBox());
|
||||
}
|
||||
|
@ -338,8 +354,8 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
|
|||
) | rpl::then(rpl::duplicate(
|
||||
unconfirmed
|
||||
)))->setDuration(0);
|
||||
confirm->entity()->addClickHandler([] {
|
||||
const auto state = Auth().api().passwordStateCurrent();
|
||||
confirm->entity()->addClickHandler([=] {
|
||||
const auto state = session->api().passwordStateCurrent();
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
|
@ -347,22 +363,22 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
std::move(
|
||||
validation.reloadRequests
|
||||
) | rpl::start_with_next([] {
|
||||
Auth().api().reloadPasswordState();
|
||||
) | rpl::start_with_next([=] {
|
||||
session->api().reloadPasswordState();
|
||||
}, validation.box->lifetime());
|
||||
|
||||
std::move(
|
||||
validation.cancelRequests
|
||||
) | rpl::start_with_next([] {
|
||||
Auth().api().clearUnconfirmedPassword();
|
||||
) | rpl::start_with_next([=] {
|
||||
session->api().clearUnconfirmedPassword();
|
||||
}, validation.box->lifetime());
|
||||
|
||||
Ui::show(std::move(validation.box));
|
||||
});
|
||||
|
||||
const auto remove = [] {
|
||||
if (CheckEditCloudPassword()) {
|
||||
RemoveCloudPassword();
|
||||
const auto remove = [=] {
|
||||
if (CheckEditCloudPassword(session)) {
|
||||
RemoveCloudPassword(session);
|
||||
} else {
|
||||
Ui::show(CloudPasswordAppOutdatedBox());
|
||||
}
|
||||
|
@ -395,7 +411,7 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
const auto reloadOnActivation = [=](Qt::ApplicationState state) {
|
||||
if (label->toggled() && state == Qt::ApplicationActive) {
|
||||
Auth().api().reloadPasswordState();
|
||||
controller->session().api().reloadPasswordState();
|
||||
}
|
||||
};
|
||||
QObject::connect(
|
||||
|
@ -404,19 +420,23 @@ void SetupCloudPassword(not_null<Ui::VerticalLayout*> container) {
|
|||
label,
|
||||
reloadOnActivation);
|
||||
|
||||
Auth().api().reloadPasswordState();
|
||||
session->api().reloadPasswordState();
|
||||
|
||||
AddSkip(container);
|
||||
}
|
||||
|
||||
void SetupSelfDestruction(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupSelfDestruction(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
AddSubsectionTitle(container, tr::lng_settings_destroy_title());
|
||||
|
||||
Auth().api().reloadSelfDestruct();
|
||||
const auto label = [] {
|
||||
return Auth().api().selfDestructValue(
|
||||
const auto session = &controller->session();
|
||||
|
||||
session->api().reloadSelfDestruct();
|
||||
const auto label = [&] {
|
||||
return session->api().selfDestructValue(
|
||||
) | rpl::map(
|
||||
SelfDestructionBox::DaysLabel
|
||||
);
|
||||
|
@ -427,14 +447,16 @@ void SetupSelfDestruction(not_null<Ui::VerticalLayout*> container) {
|
|||
tr::lng_settings_destroy_if(),
|
||||
label(),
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<SelfDestructionBox>(Auth().api().selfDestructValue()));
|
||||
)->addClickHandler([=] {
|
||||
Ui::show(Box<SelfDestructionBox>(session->api().selfDestructValue()));
|
||||
});
|
||||
|
||||
AddSkip(container);
|
||||
}
|
||||
|
||||
void SetupSessionsList(not_null<Ui::VerticalLayout*> container) {
|
||||
void SetupSessionsList(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container);
|
||||
AddSubsectionTitle(container, tr::lng_settings_sessions_title());
|
||||
|
||||
|
@ -463,8 +485,8 @@ int ExceptionUsersCount(const std::vector<not_null<PeerData*>> &exceptions) {
|
|||
return ranges::accumulate(exceptions, 0, add);
|
||||
}
|
||||
|
||||
bool CheckEditCloudPassword() {
|
||||
const auto current = Auth().api().passwordStateCurrent();
|
||||
bool CheckEditCloudPassword(not_null<::Main::Session*> session) {
|
||||
const auto current = session->api().passwordStateCurrent();
|
||||
Assert(current.has_value());
|
||||
|
||||
if (!current->unknownAlgorithm
|
||||
|
@ -479,7 +501,9 @@ object_ptr<BoxContent> EditCloudPasswordBox(not_null<Main::Session*> session) {
|
|||
const auto current = session->api().passwordStateCurrent();
|
||||
Assert(current.has_value());
|
||||
|
||||
auto result = Box<PasscodeBox>(PasscodeBox::CloudFields::From(*current));
|
||||
auto result = Box<PasscodeBox>(
|
||||
session,
|
||||
PasscodeBox::CloudFields::From(*current));
|
||||
const auto box = result.data();
|
||||
|
||||
rpl::merge(
|
||||
|
@ -497,29 +521,29 @@ object_ptr<BoxContent> EditCloudPasswordBox(not_null<Main::Session*> session) {
|
|||
return std::move(result);
|
||||
}
|
||||
|
||||
void RemoveCloudPassword() {
|
||||
const auto current = Auth().api().passwordStateCurrent();
|
||||
void RemoveCloudPassword(not_null<::Main::Session*> session) {
|
||||
const auto current = session->api().passwordStateCurrent();
|
||||
Assert(current.has_value());
|
||||
|
||||
if (!current->request) {
|
||||
Auth().api().clearUnconfirmedPassword();
|
||||
session->api().clearUnconfirmedPassword();
|
||||
return;
|
||||
}
|
||||
auto fields = PasscodeBox::CloudFields::From(*current);
|
||||
fields.turningOff = true;
|
||||
const auto box = Ui::show(Box<PasscodeBox>(fields));
|
||||
const auto box = Ui::show(Box<PasscodeBox>(session, fields));
|
||||
|
||||
rpl::merge(
|
||||
box->newPasswordSet(
|
||||
) | rpl::map([] { return rpl::empty_value(); }),
|
||||
box->passwordReloadNeeded()
|
||||
) | rpl::start_with_next([=] {
|
||||
Auth().api().reloadPasswordState();
|
||||
session->api().reloadPasswordState();
|
||||
}, box->lifetime());
|
||||
|
||||
box->clearUnconfirmedPassword(
|
||||
) | rpl::start_with_next([=] {
|
||||
Auth().api().clearUnconfirmedPassword();
|
||||
session->api().clearUnconfirmedPassword();
|
||||
}, box->lifetime());
|
||||
}
|
||||
|
||||
|
@ -538,43 +562,47 @@ object_ptr<BoxContent> CloudPasswordAppOutdatedBox() {
|
|||
}
|
||||
|
||||
void AddPrivacyButton(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> label,
|
||||
Privacy::Key key,
|
||||
Fn<std::unique_ptr<EditPrivacyController>()> controller) {
|
||||
Fn<std::unique_ptr<EditPrivacyController>()> controllerFactory) {
|
||||
const auto shower = Ui::CreateChild<rpl::lifetime>(container.get());
|
||||
const auto session = &controller->session();
|
||||
AddButtonWithLabel(
|
||||
container,
|
||||
std::move(label),
|
||||
PrivacyString(key),
|
||||
PrivacyString(session, key),
|
||||
st::settingsButton
|
||||
)->addClickHandler([=] {
|
||||
*shower = Auth().api().privacyValue(
|
||||
*shower = session->api().privacyValue(
|
||||
key
|
||||
) | rpl::take(
|
||||
1
|
||||
) | rpl::start_with_next([=](const Privacy &value) {
|
||||
Ui::show(
|
||||
Box<EditPrivacyBox>(controller(), value),
|
||||
Box<EditPrivacyBox>(controller, controllerFactory(), value),
|
||||
LayerOption::KeepOther);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
PrivacySecurity::PrivacySecurity(QWidget *parent, not_null<UserData*> self)
|
||||
: Section(parent)
|
||||
, _self(self) {
|
||||
setupContent();
|
||||
PrivacySecurity::PrivacySecurity(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller)
|
||||
: Section(parent) {
|
||||
setupContent(controller);
|
||||
}
|
||||
|
||||
void PrivacySecurity::setupContent() {
|
||||
void PrivacySecurity::setupContent(
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
SetupPrivacy(content);
|
||||
SetupSessionsList(content);
|
||||
SetupLocalPasscode(content);
|
||||
SetupCloudPassword(content);
|
||||
SetupSelfDestruction(content);
|
||||
SetupPrivacy(controller, content);
|
||||
SetupSessionsList(controller, content);
|
||||
SetupLocalPasscode(controller, content);
|
||||
SetupCloudPassword(controller, content);
|
||||
SetupSelfDestruction(controller, content);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
|
|
@ -16,26 +16,27 @@ namespace Settings {
|
|||
|
||||
int ExceptionUsersCount(const std::vector<not_null<PeerData*>> &exceptions);
|
||||
|
||||
bool CheckEditCloudPassword();
|
||||
bool CheckEditCloudPassword(not_null<::Main::Session*> session);
|
||||
object_ptr<BoxContent> EditCloudPasswordBox(
|
||||
not_null<::Main::Session*> session);
|
||||
void RemoveCloudPassword();
|
||||
void RemoveCloudPassword(not_null<::Main::Session*> session);
|
||||
object_ptr<BoxContent> CloudPasswordAppOutdatedBox();
|
||||
|
||||
void AddPrivacyButton(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> label,
|
||||
ApiWrap::Privacy::Key key,
|
||||
Fn<std::unique_ptr<EditPrivacyController>()> controller);
|
||||
Fn<std::unique_ptr<EditPrivacyController>()> controllerFactory);
|
||||
|
||||
class PrivacySecurity : public Section {
|
||||
public:
|
||||
PrivacySecurity(QWidget *parent, not_null<UserData*> self);
|
||||
PrivacySecurity(
|
||||
QWidget *parent,
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
private:
|
||||
void setupContent();
|
||||
|
||||
not_null<UserData*> _self;
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue