Assign same identifier to the same local background.
This commit is contained in:
parent
0c3da400d9
commit
c3dcbfc967
@ -456,7 +456,7 @@ void BackgroundManager::start_up() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// then add selected backgrounds fixing their ID
|
// then add selected backgrounds fixing their identifiers
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
bool for_dark_theme = i != 0;
|
bool for_dark_theme = i != 0;
|
||||||
if (has_selected_background[i]) {
|
if (has_selected_background[i]) {
|
||||||
@ -465,7 +465,7 @@ void BackgroundManager::start_up() {
|
|||||||
bool need_resave = false;
|
bool need_resave = false;
|
||||||
if (!background.has_new_local_id && !background.type.has_file()) {
|
if (!background.has_new_local_id && !background.type.has_file()) {
|
||||||
background.has_new_local_id = true;
|
background.has_new_local_id = true;
|
||||||
background.id = get_next_local_background_id();
|
set_local_background_id(background);
|
||||||
need_resave = true;
|
need_resave = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,14 +669,23 @@ BackgroundId BackgroundManager::get_next_local_background_id() {
|
|||||||
return max_local_background_id_;
|
return max_local_background_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BackgroundManager::set_local_background_id(Background &background) {
|
||||||
|
CHECK(!background.name.empty() || background.type != BackgroundType());
|
||||||
|
auto &background_id = local_backgrounds_[background];
|
||||||
|
if (!background_id.is_valid()) {
|
||||||
|
background_id = get_next_local_background_id();
|
||||||
|
}
|
||||||
|
background.id = background_id;
|
||||||
|
}
|
||||||
|
|
||||||
BackgroundId BackgroundManager::add_local_background(const BackgroundType &type) {
|
BackgroundId BackgroundManager::add_local_background(const BackgroundType &type) {
|
||||||
Background background;
|
Background background;
|
||||||
background.id = get_next_local_background_id();
|
|
||||||
background.is_creator = true;
|
background.is_creator = true;
|
||||||
background.is_default = false;
|
background.is_default = false;
|
||||||
background.is_dark = type.is_dark();
|
background.is_dark = type.is_dark();
|
||||||
background.type = type;
|
background.type = type;
|
||||||
background.name = type.get_link();
|
background.name = type.get_link();
|
||||||
|
set_local_background_id(background);
|
||||||
add_background(background, true);
|
add_background(background, true);
|
||||||
|
|
||||||
return background.id;
|
return background.id;
|
||||||
@ -1286,9 +1295,6 @@ std::pair<BackgroundId, BackgroundType> BackgroundManager::on_get_background(
|
|||||||
LOG(ERROR) << "Receive " << to_string(wallpaper);
|
LOG(ERROR) << "Receive " << to_string(wallpaper);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (!background_id.is_valid()) {
|
|
||||||
background_id = get_next_local_background_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
Background background;
|
Background background;
|
||||||
background.id = background_id;
|
background.id = background_id;
|
||||||
@ -1297,9 +1303,12 @@ std::pair<BackgroundId, BackgroundType> BackgroundManager::on_get_background(
|
|||||||
background.is_dark = wallpaper->dark_;
|
background.is_dark = wallpaper->dark_;
|
||||||
background.type = BackgroundType(true, false, std::move(wallpaper->settings_));
|
background.type = BackgroundType(true, false, std::move(wallpaper->settings_));
|
||||||
background.name = background.type.get_link();
|
background.name = background.type.get_link();
|
||||||
|
if (!background.id.is_valid()) {
|
||||||
|
set_local_background_id(background);
|
||||||
|
}
|
||||||
add_background(background, replace_type);
|
add_background(background, replace_type);
|
||||||
|
|
||||||
return {background_id, background.type};
|
return {background.id, background.type};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto wallpaper = move_tl_object_as<telegram_api::wallPaper>(wallpaper_ptr);
|
auto wallpaper = move_tl_object_as<telegram_api::wallPaper>(wallpaper_ptr);
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/FlatHashMap.h"
|
#include "td/utils/FlatHashMap.h"
|
||||||
#include "td/utils/FlatHashSet.h"
|
#include "td/utils/FlatHashSet.h"
|
||||||
|
#include "td/utils/HashTableUtils.h"
|
||||||
#include "td/utils/Promise.h"
|
#include "td/utils/Promise.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
|
|
||||||
@ -97,6 +98,19 @@ class BackgroundManager final : public Actor {
|
|||||||
void parse(ParserT &parser);
|
void parse(ParserT &parser);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LocalBackgroundHash {
|
||||||
|
uint32 operator()(const Background &background) const {
|
||||||
|
return Hash<string>()(background.name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LocalBackgroundEquals {
|
||||||
|
bool operator()(const Background &lhs, const Background &rhs) const {
|
||||||
|
return lhs.name == rhs.name && lhs.type == rhs.type && lhs.is_creator == rhs.is_creator &&
|
||||||
|
lhs.is_default == rhs.is_default && lhs.is_dark == rhs.is_dark;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class BackgroundLogEvent;
|
class BackgroundLogEvent;
|
||||||
class BackgroundsLogEvent;
|
class BackgroundsLogEvent;
|
||||||
|
|
||||||
@ -128,6 +142,8 @@ class BackgroundManager final : public Actor {
|
|||||||
|
|
||||||
BackgroundId get_next_local_background_id();
|
BackgroundId get_next_local_background_id();
|
||||||
|
|
||||||
|
void set_local_background_id(Background &background);
|
||||||
|
|
||||||
BackgroundId add_local_background(const BackgroundType &type);
|
BackgroundId add_local_background(const BackgroundType &type);
|
||||||
|
|
||||||
void add_background(const Background &background, bool replace_type);
|
void add_background(const Background &background, bool replace_type);
|
||||||
@ -211,6 +227,8 @@ class BackgroundManager final : public Actor {
|
|||||||
};
|
};
|
||||||
FlatHashMap<FileId, UploadedFileInfo, FileIdHash> being_uploaded_files_;
|
FlatHashMap<FileId, UploadedFileInfo, FileIdHash> being_uploaded_files_;
|
||||||
|
|
||||||
|
FlatHashMap<Background, BackgroundId, LocalBackgroundHash, LocalBackgroundEquals> local_backgrounds_;
|
||||||
|
|
||||||
BackgroundId max_local_background_id_;
|
BackgroundId max_local_background_id_;
|
||||||
vector<BackgroundId> local_background_ids_[2];
|
vector<BackgroundId> local_background_ids_[2];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user