Send installWallPaper requests.

This commit is contained in:
John Preston 2019-02-08 19:47:02 +03:00
parent 95565c39ed
commit f9d56eb4c1
4 changed files with 36 additions and 6 deletions

View file

@ -476,7 +476,15 @@ void BackgroundPreviewBox::createBlurCheckbox() {
}
void BackgroundPreviewBox::apply() {
const auto install = (_paper.id() != Window::Theme::Background()->id())
&& Data::IsCloudWallPaper(_paper);
App::main()->setChatBackground(_paper, std::move(_full));
if (install) {
Auth().api().request(MTPaccount_InstallWallPaper(
_paper.mtpInput(),
_paper.mtpSettings()
)).send();
}
closeBox();
}

View file

@ -206,6 +206,10 @@ FileOrigin WallPaper::fileOrigin() const {
return FileOriginWallpaper(_id, _accessHash);
}
MTPInputWallPaper WallPaper::mtpInput() const {
return MTP_inputWallPaper(MTP_long(_id), MTP_long(_accessHash));
}
MTPWallPaperSettings WallPaper::mtpSettings() const {
return MTP_wallPaperSettings(
MTP_flags(_settings),
@ -472,6 +476,17 @@ bool IsDefaultWallPaper(const WallPaper &paper) {
|| (paper.id() == kIncorrectDefaultBackground);
}
bool IsCloudWallPaper(const WallPaper &paper) {
return (paper.id() != kIncorrectDefaultBackground)
&& !IsThemeWallPaper(paper)
&& !IsCustomWallPaper(paper)
&& !IsLegacy1DefaultWallPaper(paper)
&& !details::IsUninitializedWallPaper(paper)
&& !details::IsTestingThemeWallPaper(paper)
&& !details::IsTestingDefaultWallPaper(paper)
&& !details::IsTestingEditorWallPaper(paper);
}
QColor PatternColor(QColor background) {
const auto hue = background.hueF();
const auto saturation = background.saturationF();

View file

@ -36,6 +36,8 @@ public:
void loadDocument() const;
void loadThumbnail() const;
[[nodiscard]] FileOrigin fileOrigin() const;
[[nodiscard]] MTPInputWallPaper mtpInput() const;
[[nodiscard]] MTPWallPaperSettings mtpSettings() const;
[[nodiscard]] WallPaper withUrlParams(
@ -89,6 +91,7 @@ private:
[[nodiscard]] bool IsLegacy1DefaultWallPaper(const WallPaper &paper);
[[nodiscard]] WallPaper DefaultWallPaper();
[[nodiscard]] bool IsDefaultWallPaper(const WallPaper &paper);
[[nodiscard]] bool IsCloudWallPaper(const WallPaper &paper);
QColor PatternColor(QColor background);
QImage PreparePatternImage(

View file

@ -317,12 +317,16 @@ void RoundCheckbox::setChecked(bool newChecked, SetStyle speed) {
return;
}
_checked = newChecked;
_checkedProgress.start(
_updateCallback,
_checked ? 0. : 1.,
_checked ? 1. : 0.,
_st.duration,
anim::linear);
if (speed == SetStyle::Animated) {
_checkedProgress.start(
_updateCallback,
_checked ? 0. : 1.,
_checked ? 1. : 0.,
_st.duration,
anim::linear);
} else {
_checkedProgress.finish();
}
}
void RoundCheckbox::invalidateCache() {