2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Sort backgrounds in the gallery.

This commit is contained in:
John Preston
2019-02-04 21:37:40 +03:00
parent 64afed0fb2
commit aae2101131
5 changed files with 73 additions and 47 deletions

View File

@@ -3064,23 +3064,13 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) {
_wallpapersHash = hash;
_wallpapers.clear();
_wallpapers.reserve(data.size() + 1);
_wallpapers.reserve(data.size() + 2);
const auto defaultBackground = Images::Create(
qsl(":/gui/art/bg.jpg"),
"JPG");
if (defaultBackground) {
_wallpapers.push_back(Data::DefaultWallPaper());
_wallpapers.back().setLocalImageAsThumbnail(
defaultBackground.get());
}
const auto oldBackground = Images::Create(
_wallpapers.push_back(Data::Legacy1DefaultWallPaper());
_wallpapers.back().setLocalImageAsThumbnail(Images::Create(
qsl(":/gui/art/bg_initial.jpg"),
"JPG");
if (oldBackground) {
_wallpapers.push_back(Data::Legacy1DefaultWallPaper());
_wallpapers.back().setLocalImageAsThumbnail(oldBackground.get());
}
"JPG"
).get());
for (const auto &paper : data) {
paper.match([&](const MTPDwallPaper &paper) {
if (paper.is_pattern()) {
@@ -3090,6 +3080,16 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) {
}
});
}
const auto defaultFound = ranges::find_if(
_wallpapers,
Data::IsDefaultWallPaper);
if (defaultFound == end(_wallpapers)) {
_wallpapers.push_back(Data::DefaultWallPaper());
_wallpapers.back().setLocalImageAsThumbnail(Images::Create(
qsl(":/gui/arg/bg.jpg"),
"JPG"
).get());
}
}
const std::vector<WallPaper> &Session::wallpapers() const {