Initial background support.
GitOrigin-RevId: 14d3a1166f837069c55f40036a633295600524ca
This commit is contained in:
parent
db59a7f2cc
commit
85dd77b02c
@ -354,6 +354,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/AnimationsManager.cpp
|
td/telegram/AnimationsManager.cpp
|
||||||
td/telegram/AudiosManager.cpp
|
td/telegram/AudiosManager.cpp
|
||||||
td/telegram/AuthManager.cpp
|
td/telegram/AuthManager.cpp
|
||||||
|
td/telegram/BackgroundManager.cpp
|
||||||
td/telegram/CallActor.cpp
|
td/telegram/CallActor.cpp
|
||||||
td/telegram/CallDiscardReason.cpp
|
td/telegram/CallDiscardReason.cpp
|
||||||
td/telegram/CallManager.cpp
|
td/telegram/CallManager.cpp
|
||||||
@ -452,7 +453,6 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/VideoNotesManager.cpp
|
td/telegram/VideoNotesManager.cpp
|
||||||
td/telegram/VideosManager.cpp
|
td/telegram/VideosManager.cpp
|
||||||
td/telegram/VoiceNotesManager.cpp
|
td/telegram/VoiceNotesManager.cpp
|
||||||
td/telegram/WallpaperManager.cpp
|
|
||||||
td/telegram/WebPageBlock.cpp
|
td/telegram/WebPageBlock.cpp
|
||||||
td/telegram/WebPagesManager.cpp
|
td/telegram/WebPagesManager.cpp
|
||||||
|
|
||||||
@ -483,6 +483,8 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/AnimationsManager.h
|
td/telegram/AnimationsManager.h
|
||||||
td/telegram/AudiosManager.h
|
td/telegram/AudiosManager.h
|
||||||
td/telegram/AuthManager.h
|
td/telegram/AuthManager.h
|
||||||
|
td/telegram/BackgroundId.h
|
||||||
|
td/telegram/BackgroundManager.h
|
||||||
td/telegram/CallActor.h
|
td/telegram/CallActor.h
|
||||||
td/telegram/CallDiscardReason.h
|
td/telegram/CallDiscardReason.h
|
||||||
td/telegram/CallId.h
|
td/telegram/CallId.h
|
||||||
@ -619,7 +621,6 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/VideoNotesManager.h
|
td/telegram/VideoNotesManager.h
|
||||||
td/telegram/VideosManager.h
|
td/telegram/VideosManager.h
|
||||||
td/telegram/VoiceNotesManager.h
|
td/telegram/VoiceNotesManager.h
|
||||||
td/telegram/WallpaperManager.h
|
|
||||||
td/telegram/WebPageBlock.h
|
td/telegram/WebPageBlock.h
|
||||||
td/telegram/WebPageId.h
|
td/telegram/WebPageId.h
|
||||||
td/telegram/WebPagesManager.h
|
td/telegram/WebPagesManager.h
|
||||||
|
@ -91,7 +91,7 @@ authorizationStateWaitPhoneNumber = AuthorizationState;
|
|||||||
//@description TDLib needs the user's authentication code to finalize authorization @is_registered True, if the user is already registered @terms_of_service Telegram terms of service, which should be accepted before user can continue registration; may be null @code_info Information about the authorization code that was sent
|
//@description TDLib needs the user's authentication code to finalize authorization @is_registered True, if the user is already registered @terms_of_service Telegram terms of service, which should be accepted before user can continue registration; may be null @code_info Information about the authorization code that was sent
|
||||||
authorizationStateWaitCode is_registered:Bool terms_of_service:termsOfService code_info:authenticationCodeInfo = AuthorizationState;
|
authorizationStateWaitCode is_registered:Bool terms_of_service:termsOfService code_info:authenticationCodeInfo = AuthorizationState;
|
||||||
|
|
||||||
//@description The user has been authorized, but needs to enter a password to start using the application @password_hint Hint for the password; may be empty @has_recovery_email_address True if a recovery email address has been set up
|
//@description The user has been authorized, but needs to enter a password to start using the application @password_hint Hint for the password; may be empty @has_recovery_email_address True, if a recovery email address has been set up
|
||||||
//@recovery_email_address_pattern Pattern of the email address to which the recovery email was sent; empty until a recovery email has been sent
|
//@recovery_email_address_pattern Pattern of the email address to which the recovery email was sent; empty until a recovery email has been sent
|
||||||
authorizationStateWaitPassword password_hint:string has_recovery_email_address:Bool recovery_email_address_pattern:string = AuthorizationState;
|
authorizationStateWaitPassword password_hint:string has_recovery_email_address:Bool recovery_email_address_pattern:string = AuthorizationState;
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ animation duration:int32 width:int32 height:int32 file_name:string mime_type:str
|
|||||||
audio duration:int32 title:string performer:string file_name:string mime_type:string album_cover_minithumbnail:minithumbnail album_cover_thumbnail:photoSize audio:file = Audio;
|
audio duration:int32 title:string performer:string file_name:string mime_type:string album_cover_minithumbnail:minithumbnail album_cover_thumbnail:photoSize audio:file = Audio;
|
||||||
|
|
||||||
//@description Describes a document of any type @file_name Original name of the file; as defined by the sender @mime_type MIME type of the file; as defined by the sender
|
//@description Describes a document of any type @file_name Original name of the file; as defined by the sender @mime_type MIME type of the file; as defined by the sender
|
||||||
//@minithumbnail Document minithumbnail; may be null @thumbnail Document thumbnail; as defined by the sender; may be null @document File containing the document
|
//@minithumbnail Document minithumbnail; may be null @thumbnail Document thumbnail in JPEG or PNG format (PNG will be used only for background patterns); as defined by the sender; may be null @document File containing the document
|
||||||
document file_name:string mime_type:string minithumbnail:minithumbnail thumbnail:photoSize document:file = Document;
|
document file_name:string mime_type:string minithumbnail:minithumbnail thumbnail:photoSize document:file = Document;
|
||||||
|
|
||||||
//@description Describes a photo @has_stickers True, if stickers were added to the photo @minithumbnail Photo minithumbnail; may be null @sizes Available variants of the photo, in different sizes
|
//@description Describes a photo @has_stickers True, if stickers were added to the photo @minithumbnail Photo minithumbnail; may be null @sizes Available variants of the photo, in different sizes
|
||||||
@ -1939,11 +1939,34 @@ deviceTokenTizenPush reg_id:string = DeviceToken;
|
|||||||
pushReceiverId id:int64 = PushReceiverId;
|
pushReceiverId id:int64 = PushReceiverId;
|
||||||
|
|
||||||
|
|
||||||
//@description Contains information about a wallpaper @id Unique persistent wallpaper identifier @sizes Available variants of the wallpaper in different sizes. These photos can only be downloaded; they can't be sent in a message @color Main color of the wallpaper in RGB24 format; should be treated as background color if no photos are specified
|
//@class BackgroundType @description Describes a type of a background
|
||||||
wallpaper id:int32 sizes:vector<photoSize> color:int32 = Wallpaper;
|
|
||||||
|
|
||||||
//@description Contains a list of wallpapers @wallpapers A list of wallpapers
|
//@description A wallpaper in JPEG format
|
||||||
wallpapers wallpapers:vector<wallpaper> = Wallpapers;
|
//@is_blurred True, if the wallpaper must be downscaled to fit in 450x450 square and then box-blurred with radius 12
|
||||||
|
//@is_moving True, if the background needs to be slightly moved when device is rotated
|
||||||
|
backgroundTypeWallpaper is_blurred:Bool is_moving:Bool = BackgroundType;
|
||||||
|
|
||||||
|
//@description A PNG pattern to be combined with the chosen by the user color
|
||||||
|
//@is_moving True, if the background needs to be slightly moved when device is rotated
|
||||||
|
//@color Main color of the background in RGB24 format
|
||||||
|
//@intensity Intensity of the pattern when it is shown above the main background color, 0-100
|
||||||
|
backgroundTypePattern is_moving:Bool color:int32 intensity:int32 = BackgroundType;
|
||||||
|
|
||||||
|
//@description A solid background @color A color of the background in RGB24 format
|
||||||
|
backgroundTypeSolid color:int32 = BackgroundType;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Describes a chat background
|
||||||
|
//@id Unique background identifier
|
||||||
|
//@is_default True, if this is one of default backgrounds
|
||||||
|
//@is_dark True, if this background is dark and is recommended to be used with dark theme
|
||||||
|
//@name Unique background name
|
||||||
|
//@document Document with the background; may be null. Null only for solid backgrounds
|
||||||
|
//@type Type of the background
|
||||||
|
background id:int64 is_default:Bool is_dark:Bool name:string document:document type:BackgroundType = Background;
|
||||||
|
|
||||||
|
//@description Contains a list of backgrounds @backgrounds A list of backgrounds
|
||||||
|
backgrounds backgrounds:vector<background> = Backgrounds;
|
||||||
|
|
||||||
|
|
||||||
//@description Contains a list of hashtags @hashtags A list of hashtags
|
//@description Contains a list of hashtags @hashtags A list of hashtags
|
||||||
@ -2283,7 +2306,7 @@ fileTypeVideoNote = FileType;
|
|||||||
//@description The file is a voice note
|
//@description The file is a voice note
|
||||||
fileTypeVoiceNote = FileType;
|
fileTypeVoiceNote = FileType;
|
||||||
|
|
||||||
//@description The file is a wallpaper
|
//@description The file is a wallpaper or a background pattern
|
||||||
fileTypeWallpaper = FileType;
|
fileTypeWallpaper = FileType;
|
||||||
|
|
||||||
|
|
||||||
@ -3578,8 +3601,8 @@ deleteSavedCredentials = Ok;
|
|||||||
//@description Returns a user that can be contacted to get support
|
//@description Returns a user that can be contacted to get support
|
||||||
getSupportUser = User;
|
getSupportUser = User;
|
||||||
|
|
||||||
//@description Returns background wallpapers
|
//@description Returns backgrounds installed by the user
|
||||||
getWallpapers = Wallpapers;
|
getBackgrounds = Backgrounds;
|
||||||
|
|
||||||
|
|
||||||
//@description Returns information about the current localization target. This is an offline request if only_local is true. Can be called before authorization @only_local If true, returns only locally available information without sending network requests
|
//@description Returns information about the current localization target. This is an offline request if only_local is true. Can be called before authorization @only_local If true, returns only locally available information without sending network requests
|
||||||
|
Binary file not shown.
66
td/telegram/BackgroundId.h
Normal file
66
td/telegram/BackgroundId.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/StringBuilder.h"
|
||||||
|
#include "td/utils/tl_helpers.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class BackgroundId {
|
||||||
|
int64 id = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BackgroundId() = default;
|
||||||
|
|
||||||
|
explicit BackgroundId(int64 background_id) : id(background_id) {
|
||||||
|
}
|
||||||
|
template <class T, typename = std::enable_if_t<std::is_convertible<T, int64>::value>>
|
||||||
|
BackgroundId(T background_id) = delete;
|
||||||
|
|
||||||
|
int64 get() const {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const BackgroundId &other) const {
|
||||||
|
return id == other.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const BackgroundId &other) const {
|
||||||
|
return id != other.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_valid() const {
|
||||||
|
return id != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void store(StorerT &storer) const {
|
||||||
|
td::store(id, storer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ParserT>
|
||||||
|
void parse(ParserT &parser) {
|
||||||
|
td::parse(id, parser);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BackgroundIdHash {
|
||||||
|
std::size_t operator()(BackgroundId background_id) const {
|
||||||
|
return std::hash<int64>()(background_id.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline StringBuilder &operator<<(StringBuilder &string_builder, BackgroundId background_id) {
|
||||||
|
return string_builder << "background " << background_id.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
227
td/telegram/BackgroundManager.cpp
Normal file
227
td/telegram/BackgroundManager.cpp
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
#include "td/telegram/BackgroundManager.h"
|
||||||
|
|
||||||
|
#include "td/telegram/td_api.h"
|
||||||
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
|
#include "td/telegram/DialogId.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
|
#include "td/telegram/DocumentsManager.h"
|
||||||
|
#include "td/telegram/FileReferenceManager.h"
|
||||||
|
#include "td/telegram/files/FileManager.h"
|
||||||
|
#include "td/telegram/files/FileType.h"
|
||||||
|
#include "td/telegram/Global.h"
|
||||||
|
#include "td/telegram/Photo.h"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
|
||||||
|
#include "td/utils/buffer.h"
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/misc.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class GetBackgroundsQuery : public Td::ResultHandler {
|
||||||
|
Promise<telegram_api::object_ptr<telegram_api::account_WallPapers>> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetBackgroundsQuery(Promise<telegram_api::object_ptr<telegram_api::account_WallPapers>> &&promise)
|
||||||
|
: promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send() {
|
||||||
|
send_query(G()->net_query_creator().create(create_storer(telegram_api::account_getWallPapers(0))));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(uint64 id, BufferSlice packet) override {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::account_getWallPapers>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(id, result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
promise_.set_value(result_ptr.move_as_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(uint64 id, Status status) override {
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BackgroundManager::BackgroundManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void BackgroundManager::tear_down() {
|
||||||
|
parent_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BackgroundManager::get_backgrounds(Promise<Unit> &&promise) {
|
||||||
|
pending_get_backgrounds_queries_.push_back(std::move(promise));
|
||||||
|
if (pending_get_backgrounds_queries_.size() == 1) {
|
||||||
|
auto request_promise = PromiseCreator::lambda(
|
||||||
|
[actor_id = actor_id(this)](Result<telegram_api::object_ptr<telegram_api::account_WallPapers>> result) {
|
||||||
|
send_closure(actor_id, &BackgroundManager::on_get_backgrounds, std::move(result));
|
||||||
|
});
|
||||||
|
|
||||||
|
td_->create_handler<GetBackgroundsQuery>(std::move(request_promise))->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BackgroundManager::Background *BackgroundManager::add_background(BackgroundId background_id) {
|
||||||
|
CHECK(background_id.is_valid());
|
||||||
|
return &backgrounds_[background_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
const BackgroundManager::Background *BackgroundManager::get_background(BackgroundId background_id) const {
|
||||||
|
auto p = backgrounds_.find(background_id);
|
||||||
|
if (p == backgrounds_.end()) {
|
||||||
|
return nullptr;
|
||||||
|
} else {
|
||||||
|
return &p->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BackgroundManager::BackgroundType BackgroundManager::get_background_type(
|
||||||
|
bool is_pattern, telegram_api::object_ptr<telegram_api::wallPaperSettings> settings) {
|
||||||
|
bool is_blurred = false;
|
||||||
|
bool is_moving = false;
|
||||||
|
int32 color = 0;
|
||||||
|
int32 intensity = 0;
|
||||||
|
if (settings) {
|
||||||
|
auto flags = settings->flags_;
|
||||||
|
is_blurred = (flags & telegram_api::wallPaperSettings::BLUR_MASK) != 0;
|
||||||
|
is_moving = (flags & telegram_api::wallPaperSettings::MOTION_MASK) != 0;
|
||||||
|
if ((flags & telegram_api::wallPaperSettings::BACKGROUND_COLOR_MASK) != 0) {
|
||||||
|
color = settings->background_color_;
|
||||||
|
if (color < 0 || color > 0xFFFFFF) {
|
||||||
|
LOG(ERROR) << "Receive " << to_string(settings);
|
||||||
|
color = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((flags & telegram_api::wallPaperSettings::INTENSITY_MASK) != 0) {
|
||||||
|
intensity = settings->intensity_;
|
||||||
|
if (intensity < 0 || intensity > 100) {
|
||||||
|
LOG(ERROR) << "Receive " << to_string(settings);
|
||||||
|
intensity = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_pattern) {
|
||||||
|
return BackgroundType(is_moving, color, intensity);
|
||||||
|
} else {
|
||||||
|
return BackgroundType(is_blurred, is_moving);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BackgroundId BackgroundManager::on_get_background(telegram_api::object_ptr<telegram_api::wallPaper> wallpaper) {
|
||||||
|
CHECK(wallpaper != nullptr);
|
||||||
|
|
||||||
|
auto id = BackgroundId(wallpaper->id_);
|
||||||
|
if (!id.is_valid()) {
|
||||||
|
LOG(ERROR) << "Receive " << to_string(wallpaper);
|
||||||
|
return BackgroundId();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 document_id = wallpaper->document_->get_id();
|
||||||
|
if (document_id == telegram_api::documentEmpty::ID) {
|
||||||
|
LOG(ERROR) << "Receive " << to_string(wallpaper);
|
||||||
|
return BackgroundId();
|
||||||
|
}
|
||||||
|
CHECK(document_id == telegram_api::document::ID);
|
||||||
|
|
||||||
|
int32 flags = wallpaper->flags_;
|
||||||
|
bool is_pattern = (flags & telegram_api::wallPaper::PATTERN_MASK) != 0;
|
||||||
|
|
||||||
|
Document document = td_->documents_manager_->on_get_document(
|
||||||
|
telegram_api::move_object_as<telegram_api::document>(wallpaper->document_), DialogId(), nullptr,
|
||||||
|
Document::Type::General, true, is_pattern);
|
||||||
|
if (!document.file_id.is_valid()) {
|
||||||
|
LOG(ERROR) << "Receive wrong document in " << to_string(wallpaper);
|
||||||
|
return BackgroundId();
|
||||||
|
}
|
||||||
|
CHECK(document.type == Document::Type::General);
|
||||||
|
|
||||||
|
auto *background = add_background(id);
|
||||||
|
background->id = id;
|
||||||
|
background->access_hash = wallpaper->access_hash_;
|
||||||
|
background->name = std::move(wallpaper->slug_);
|
||||||
|
background->file_id = document.file_id;
|
||||||
|
background->is_creator = (flags & telegram_api::wallPaper::CREATOR_MASK) != 0;
|
||||||
|
background->is_default = (flags & telegram_api::wallPaper::DEFAULT_MASK) != 0;
|
||||||
|
background->is_dark = (flags & telegram_api::wallPaper::DARK_MASK) != 0;
|
||||||
|
background->type = get_background_type(is_pattern, std::move(wallpaper->settings_));
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BackgroundManager::on_get_backgrounds(Result<telegram_api::object_ptr<telegram_api::account_WallPapers>> result) {
|
||||||
|
auto promises = std::move(pending_get_backgrounds_queries_);
|
||||||
|
CHECK(!promises.empty());
|
||||||
|
reset_to_empty(pending_get_backgrounds_queries_);
|
||||||
|
|
||||||
|
if (result.is_error()) {
|
||||||
|
// do not clear installed_backgrounds_
|
||||||
|
|
||||||
|
auto error = result.move_as_error();
|
||||||
|
for (auto &promise : promises) {
|
||||||
|
promise.set_error(error.clone());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto wallpapers_ptr = result.move_as_ok();
|
||||||
|
LOG(INFO) << "Receive " << to_string(wallpapers_ptr);
|
||||||
|
if (wallpapers_ptr->get_id() == telegram_api::account_wallPapersNotModified::ID) {
|
||||||
|
for (auto &promise : promises) {
|
||||||
|
promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
installed_backgrounds_.clear();
|
||||||
|
auto wallpapers = telegram_api::move_object_as<telegram_api::account_wallPapers>(wallpapers_ptr);
|
||||||
|
for (auto &wallpaper : wallpapers->wallpapers_) {
|
||||||
|
auto background_id = on_get_background(std::move(wallpaper));
|
||||||
|
if (background_id.is_valid()) {
|
||||||
|
installed_backgrounds_.push_back(background_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &promise : promises) {
|
||||||
|
promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::BackgroundType> BackgroundManager::get_background_type_object(const BackgroundType &type) {
|
||||||
|
switch (type.type) {
|
||||||
|
case BackgroundType::Type::Wallpaper:
|
||||||
|
return td_api::make_object<td_api::backgroundTypeWallpaper>(type.is_blurred, type.is_moving);
|
||||||
|
case BackgroundType::Type::Pattern:
|
||||||
|
return td_api::make_object<td_api::backgroundTypePattern>(type.is_moving, type.color, type.intensity);
|
||||||
|
case BackgroundType::Type::Solid:
|
||||||
|
return td_api::make_object<td_api::backgroundTypeSolid>(type.color);
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::background> BackgroundManager::get_background_object(BackgroundId background_id) const {
|
||||||
|
auto background = get_background(background_id);
|
||||||
|
if (background == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return td_api::make_object<td_api::background>(
|
||||||
|
background->id.get(), background->is_default, background->is_dark, background->name,
|
||||||
|
td_->documents_manager_->get_document_object(background->file_id), get_background_type_object(background->type));
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::backgrounds> BackgroundManager::get_backgrounds_object() const {
|
||||||
|
return td_api::make_object<td_api::backgrounds>(transform(
|
||||||
|
installed_backgrounds_, [this](BackgroundId background_id) { return get_background_object(background_id); }));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
94
td/telegram/BackgroundManager.h
Normal file
94
td/telegram/BackgroundManager.h
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/BackgroundId.h"
|
||||||
|
#include "td/telegram/files/FileId.h"
|
||||||
|
#include "td/telegram/files/FileSourceId.h"
|
||||||
|
#include "td/telegram/Photo.h"
|
||||||
|
#include "td/telegram/td_api.h"
|
||||||
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
|
#include "td/actor/actor.h"
|
||||||
|
#include "td/actor/PromiseFuture.h"
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/Status.h"
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class Td;
|
||||||
|
|
||||||
|
class BackgroundManager : public Actor {
|
||||||
|
public:
|
||||||
|
BackgroundManager(Td *td, ActorShared<> parent);
|
||||||
|
|
||||||
|
void get_backgrounds(Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id) const;
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::backgrounds> get_backgrounds_object() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct BackgroundType {
|
||||||
|
enum class Type : int32 { Wallpaper, Pattern, Solid };
|
||||||
|
Type type = Type::Solid;
|
||||||
|
bool is_blurred = false;
|
||||||
|
bool is_moving = false;
|
||||||
|
int32 color = 0;
|
||||||
|
int32 intensity = 0;
|
||||||
|
|
||||||
|
BackgroundType() = default;
|
||||||
|
BackgroundType(bool is_blurred, bool is_moving)
|
||||||
|
: type(Type::Wallpaper), is_blurred(is_blurred), is_moving(is_moving) {
|
||||||
|
}
|
||||||
|
BackgroundType(bool is_moving, int32 color, int32 intensity)
|
||||||
|
: type(Type::Pattern), is_moving(is_moving), color(color), intensity(intensity) {
|
||||||
|
}
|
||||||
|
explicit BackgroundType(int32 color) : type(Type::Solid), color(color) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Background {
|
||||||
|
BackgroundId id;
|
||||||
|
int64 access_hash = 0;
|
||||||
|
string name;
|
||||||
|
FileId file_id;
|
||||||
|
bool is_creator = false;
|
||||||
|
bool is_default = false;
|
||||||
|
bool is_dark = false;
|
||||||
|
BackgroundType type;
|
||||||
|
};
|
||||||
|
|
||||||
|
void tear_down() override;
|
||||||
|
|
||||||
|
Background *add_background(BackgroundId background_id);
|
||||||
|
|
||||||
|
const Background *get_background(BackgroundId background_id) const;
|
||||||
|
|
||||||
|
static BackgroundType get_background_type(bool is_pattern,
|
||||||
|
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings);
|
||||||
|
|
||||||
|
BackgroundId on_get_background(telegram_api::object_ptr<telegram_api::wallPaper> wallpaper);
|
||||||
|
|
||||||
|
void on_get_backgrounds(Result<telegram_api::object_ptr<telegram_api::account_WallPapers>> result);
|
||||||
|
|
||||||
|
static td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const BackgroundType &type);
|
||||||
|
|
||||||
|
std::unordered_map<BackgroundId, Background, BackgroundIdHash> backgrounds_; // id -> Background
|
||||||
|
|
||||||
|
vector<BackgroundId> installed_backgrounds_;
|
||||||
|
|
||||||
|
vector<Promise<Unit>> pending_get_backgrounds_queries_;
|
||||||
|
|
||||||
|
Td *td_;
|
||||||
|
ActorShared<> parent_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace td
|
@ -48,31 +48,31 @@ vector<FileId> Document::get_file_ids(const Td *td) const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder &operator<<(StringBuilder &string_builder, const Document &document) {
|
StringBuilder &operator<<(StringBuilder &string_builder, const Document::Type &document_type) {
|
||||||
auto type = [&] {
|
switch (document_type) {
|
||||||
switch (document.type) {
|
|
||||||
case Document::Type::Unknown:
|
case Document::Type::Unknown:
|
||||||
return "Unknown";
|
return string_builder << "Unknown";
|
||||||
case Document::Type::Animation:
|
case Document::Type::Animation:
|
||||||
return "Animation";
|
return string_builder << "Animation";
|
||||||
case Document::Type::Audio:
|
case Document::Type::Audio:
|
||||||
return "Audio";
|
return string_builder << "Audio";
|
||||||
case Document::Type::General:
|
case Document::Type::General:
|
||||||
return "Document";
|
return string_builder << "Document";
|
||||||
case Document::Type::Sticker:
|
case Document::Type::Sticker:
|
||||||
return "Sticker";
|
return string_builder << "Sticker";
|
||||||
case Document::Type::Video:
|
case Document::Type::Video:
|
||||||
return "Video";
|
return string_builder << "Video";
|
||||||
case Document::Type::VideoNote:
|
case Document::Type::VideoNote:
|
||||||
return "VideoNote";
|
return string_builder << "VideoNote";
|
||||||
case Document::Type::VoiceNote:
|
case Document::Type::VoiceNote:
|
||||||
return "VoiceNote";
|
return string_builder << "VoiceNote";
|
||||||
default:
|
default:
|
||||||
return "Unreachable";
|
return string_builder << "Unreachable";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}();
|
|
||||||
|
|
||||||
return string_builder << '[' << type << ' ' << document.file_id << ']';
|
StringBuilder &operator<<(StringBuilder &string_builder, const Document &document) {
|
||||||
|
return string_builder << '[' << document.type << ' ' << document.file_id << ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -33,6 +33,8 @@ struct Document {
|
|||||||
vector<FileId> get_file_ids(const Td *td) const;
|
vector<FileId> get_file_ids(const Td *td) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const Document::Type &document_type);
|
||||||
|
|
||||||
StringBuilder &operator<<(StringBuilder &string_builder, const Document &document);
|
StringBuilder &operator<<(StringBuilder &string_builder, const Document &document);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -63,7 +63,7 @@ tl_object_ptr<td_api::document> DocumentsManager::get_document_object(FileId fil
|
|||||||
|
|
||||||
Document DocumentsManager::on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
|
Document DocumentsManager::on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
|
||||||
MultiPromiseActor *load_data_multipromise_ptr,
|
MultiPromiseActor *load_data_multipromise_ptr,
|
||||||
Document::Type default_document_type) {
|
Document::Type default_document_type, bool is_background, bool is_pattern) {
|
||||||
tl_object_ptr<telegram_api::documentAttributeAnimated> animated;
|
tl_object_ptr<telegram_api::documentAttributeAnimated> animated;
|
||||||
tl_object_ptr<telegram_api::documentAttributeVideo> video;
|
tl_object_ptr<telegram_api::documentAttributeVideo> video;
|
||||||
tl_object_ptr<telegram_api::documentAttributeAudio> audio;
|
tl_object_ptr<telegram_api::documentAttributeAudio> audio;
|
||||||
@ -188,6 +188,21 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
|
|||||||
<< ", has_stickers = " << has_stickers;
|
<< ", has_stickers = " << has_stickers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_png_thumbnail = false;
|
||||||
|
if (is_background) {
|
||||||
|
if (document_type != Document::Type::General) {
|
||||||
|
LOG(ERROR) << "Receive background of type " << document_type;
|
||||||
|
document_type = Document::Type::General;
|
||||||
|
}
|
||||||
|
file_type = FileType::Background;
|
||||||
|
if (is_pattern) {
|
||||||
|
default_extension = Slice("png");
|
||||||
|
has_png_thumbnail = true;
|
||||||
|
} else {
|
||||||
|
default_extension = Slice("jpg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int64 id;
|
int64 id;
|
||||||
int64 access_hash;
|
int64 access_hash;
|
||||||
int32 dc_id;
|
int32 dc_id;
|
||||||
@ -213,7 +228,7 @@ Document DocumentsManager::on_get_document(RemoteDocument remote_document, Dialo
|
|||||||
if (document_type != Document::Type::VoiceNote) {
|
if (document_type != Document::Type::VoiceNote) {
|
||||||
for (auto &thumb : document->thumbs_) {
|
for (auto &thumb : document->thumbs_) {
|
||||||
auto photo_size = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", owner_dialog_id,
|
auto photo_size = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", owner_dialog_id,
|
||||||
std::move(thumb), has_webp_thumbnail);
|
std::move(thumb), has_webp_thumbnail, has_png_thumbnail);
|
||||||
if (photo_size.get_offset() == 0) {
|
if (photo_size.get_offset() == 0) {
|
||||||
thumbnail = std::move(photo_size.get<0>());
|
thumbnail = std::move(photo_size.get<0>());
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,7 +78,8 @@ class DocumentsManager {
|
|||||||
|
|
||||||
Document on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
|
Document on_get_document(RemoteDocument remote_document, DialogId owner_dialog_id,
|
||||||
MultiPromiseActor *load_data_multipromise_ptr = nullptr,
|
MultiPromiseActor *load_data_multipromise_ptr = nullptr,
|
||||||
Document::Type default_document_type = Document::Type::General);
|
Document::Type default_document_type = Document::Type::General, bool is_background = false,
|
||||||
|
bool is_pattern = false);
|
||||||
|
|
||||||
void create_document(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type,
|
void create_document(FileId file_id, string minithumbnail, PhotoSize thumbnail, string file_name, string mime_type,
|
||||||
bool replace);
|
bool replace);
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
#include "td/telegram/FileReferenceManager.h"
|
#include "td/telegram/FileReferenceManager.h"
|
||||||
|
|
||||||
#include "td/telegram/AnimationsManager.h"
|
#include "td/telegram/AnimationsManager.h"
|
||||||
|
#include "td/telegram/BackgroundManager.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
#include "td/telegram/StickersManager.h"
|
#include "td/telegram/StickersManager.h"
|
||||||
#include "td/telegram/WallpaperManager.h"
|
|
||||||
#include "td/telegram/WebPagesManager.h"
|
#include "td/telegram/WebPagesManager.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
@ -45,7 +45,7 @@ fileSourceUserProfilePhoto user_id:int32 photo_id:int64 = FileSource; // repair
|
|||||||
fileSourceBasicGroupPhoto basic_group_id:int32 = FileSource; // repaired with messages.getChats
|
fileSourceBasicGroupPhoto basic_group_id:int32 = FileSource; // repaired with messages.getChats
|
||||||
fileSourceSupergroupPhoto supergroup_id:int32 = FileSource; // repaired with channels.getChannels
|
fileSourceSupergroupPhoto supergroup_id:int32 = FileSource; // repaired with channels.getChannels
|
||||||
fileSourceWebPage url:string = FileSource; // repaired with messages.getWebPage
|
fileSourceWebPage url:string = FileSource; // repaired with messages.getWebPage
|
||||||
fileSourceWallpapers = FileSource; // repaired with account.getWallPapers
|
fileSourceWallpapers = FileSource; // can't be repaired
|
||||||
fileSourceSavedAnimations = FileSource; // repaired with messages.getSavedGifs
|
fileSourceSavedAnimations = FileSource; // repaired with messages.getSavedGifs
|
||||||
fileSourceRecentStickers is_attached:Bool = FileSource; // repaired with messages.getRecentStickers, not reliable
|
fileSourceRecentStickers is_attached:Bool = FileSource; // repaired with messages.getRecentStickers, not reliable
|
||||||
fileSourceFavoriteStickers = FileSource; // repaired with messages.getFavedStickers, not reliable
|
fileSourceFavoriteStickers = FileSource; // repaired with messages.getFavedStickers, not reliable
|
||||||
@ -82,11 +82,6 @@ FileSourceId FileReferenceManager::create_channel_photo_file_source(ChannelId ch
|
|||||||
return add_file_source_id(source, PSLICE() << "photo of " << channel_id);
|
return add_file_source_id(source, PSLICE() << "photo of " << channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSourceId FileReferenceManager::create_wallpapers_file_source() {
|
|
||||||
FileSourceWallpapers source;
|
|
||||||
return add_file_source_id(source, "wallpapers");
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSourceId FileReferenceManager::create_web_page_file_source(string url) {
|
FileSourceId FileReferenceManager::create_web_page_file_source(string url) {
|
||||||
FileSourceWebPage source{std::move(url)};
|
FileSourceWebPage source{std::move(url)};
|
||||||
auto source_str = PSTRING() << "web page of " << source.url;
|
auto source_str = PSTRING() << "web page of " << source.url;
|
||||||
@ -264,9 +259,7 @@ void FileReferenceManager::send_query(Destination dest, FileSourceId file_source
|
|||||||
send_closure_later(G()->contacts_manager(), &ContactsManager::reload_channel, source.channel_id,
|
send_closure_later(G()->contacts_manager(), &ContactsManager::reload_channel, source.channel_id,
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
},
|
},
|
||||||
[&](const FileSourceWallpapers &source) {
|
[&](const FileSourceWallpapers &source) { promise.set_error(Status::Error("Can't repair old wallpapers")); },
|
||||||
send_closure_later(G()->wallpaper_manager(), &WallpaperManager::reload_wallpapers, std::move(promise));
|
|
||||||
},
|
|
||||||
[&](const FileSourceWebPage &source) {
|
[&](const FileSourceWebPage &source) {
|
||||||
send_closure_later(G()->web_pages_manager(), &WebPagesManager::reload_web_page_by_url, source.url,
|
send_closure_later(G()->web_pages_manager(), &WebPagesManager::reload_web_page_by_url, source.url,
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
|
@ -39,7 +39,7 @@ class FileReferenceManager : public Actor {
|
|||||||
FileSourceId create_user_photo_file_source(UserId user_id, int64 photo_id);
|
FileSourceId create_user_photo_file_source(UserId user_id, int64 photo_id);
|
||||||
FileSourceId create_chat_photo_file_source(ChatId chat_id);
|
FileSourceId create_chat_photo_file_source(ChatId chat_id);
|
||||||
FileSourceId create_channel_photo_file_source(ChannelId channel_id);
|
FileSourceId create_channel_photo_file_source(ChannelId channel_id);
|
||||||
FileSourceId create_wallpapers_file_source();
|
// FileSourceId create_wallpapers_file_source(); old wallpapers can't be repaired
|
||||||
FileSourceId create_web_page_file_source(string url);
|
FileSourceId create_web_page_file_source(string url);
|
||||||
FileSourceId create_saved_animations_file_source();
|
FileSourceId create_saved_animations_file_source();
|
||||||
FileSourceId create_recent_stickers_file_source(bool is_attached);
|
FileSourceId create_recent_stickers_file_source(bool is_attached);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/telegram/AnimationsManager.h"
|
#include "td/telegram/AnimationsManager.h"
|
||||||
|
#include "td/telegram/BackgroundManager.h"
|
||||||
#include "td/telegram/ChannelId.h"
|
#include "td/telegram/ChannelId.h"
|
||||||
#include "td/telegram/ChatId.h"
|
#include "td/telegram/ChatId.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
@ -17,7 +18,6 @@
|
|||||||
#include "td/telegram/StickersManager.h"
|
#include "td/telegram/StickersManager.h"
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
#include "td/telegram/UserId.h"
|
#include "td/telegram/UserId.h"
|
||||||
#include "td/telegram/WallpaperManager.h"
|
|
||||||
#include "td/telegram/WebPagesManager.h"
|
#include "td/telegram/WebPagesManager.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
@ -73,7 +73,7 @@ FileSourceId FileReferenceManager::parse_file_source(Td *td, ParserT &parser) {
|
|||||||
return td->contacts_manager_->get_channel_photo_file_source_id(channel_id);
|
return td->contacts_manager_->get_channel_photo_file_source_id(channel_id);
|
||||||
}
|
}
|
||||||
case 4:
|
case 4:
|
||||||
return td->wallpaper_manager_->get_wallpapers_file_source_id();
|
return FileSourceId(); // there is no way to repair old wallpapers
|
||||||
case 5: {
|
case 5: {
|
||||||
string url;
|
string url;
|
||||||
td::parse(url, parser);
|
td::parse(url, parser);
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
class AnimationsManager;
|
class AnimationsManager;
|
||||||
|
class BackgroundManager;
|
||||||
class CallManager;
|
class CallManager;
|
||||||
class ConfigManager;
|
class ConfigManager;
|
||||||
class ConfigShared;
|
class ConfigShared;
|
||||||
@ -53,7 +54,6 @@ class TdDb;
|
|||||||
class TempAuthKeyWatchdog;
|
class TempAuthKeyWatchdog;
|
||||||
class TopDialogManager;
|
class TopDialogManager;
|
||||||
class UpdatesManager;
|
class UpdatesManager;
|
||||||
class WallpaperManager;
|
|
||||||
class WebPagesManager;
|
class WebPagesManager;
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|
||||||
@ -155,6 +155,13 @@ class Global : public ActorContext {
|
|||||||
animations_manager_ = animations_manager;
|
animations_manager_ = animations_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActorId<BackgroundManager> background_manager() const {
|
||||||
|
return background_manager_;
|
||||||
|
}
|
||||||
|
void set_background_manager(ActorId<BackgroundManager> background_manager) {
|
||||||
|
background_manager_ = background_manager;
|
||||||
|
}
|
||||||
|
|
||||||
ActorId<CallManager> call_manager() const {
|
ActorId<CallManager> call_manager() const {
|
||||||
return call_manager_;
|
return call_manager_;
|
||||||
}
|
}
|
||||||
@ -253,13 +260,6 @@ class Global : public ActorContext {
|
|||||||
updates_manager_ = updates_manager;
|
updates_manager_ = updates_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorId<WallpaperManager> wallpaper_manager() const {
|
|
||||||
return wallpaper_manager_;
|
|
||||||
}
|
|
||||||
void set_wallpaper_manager(ActorId<WallpaperManager> wallpaper_manager) {
|
|
||||||
wallpaper_manager_ = wallpaper_manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActorId<WebPagesManager> web_pages_manager() const {
|
ActorId<WebPagesManager> web_pages_manager() const {
|
||||||
return web_pages_manager_;
|
return web_pages_manager_;
|
||||||
}
|
}
|
||||||
@ -356,6 +356,7 @@ class Global : public ActorContext {
|
|||||||
|
|
||||||
ActorId<Td> td_;
|
ActorId<Td> td_;
|
||||||
ActorId<AnimationsManager> animations_manager_;
|
ActorId<AnimationsManager> animations_manager_;
|
||||||
|
ActorId<BackgroundManager> background_manager_;
|
||||||
ActorId<CallManager> call_manager_;
|
ActorId<CallManager> call_manager_;
|
||||||
ActorId<ConfigManager> config_manager_;
|
ActorId<ConfigManager> config_manager_;
|
||||||
ActorId<ContactsManager> contacts_manager_;
|
ActorId<ContactsManager> contacts_manager_;
|
||||||
@ -370,7 +371,6 @@ class Global : public ActorContext {
|
|||||||
ActorId<StorageManager> storage_manager_;
|
ActorId<StorageManager> storage_manager_;
|
||||||
ActorId<TopDialogManager> top_dialog_manager_;
|
ActorId<TopDialogManager> top_dialog_manager_;
|
||||||
ActorId<UpdatesManager> updates_manager_;
|
ActorId<UpdatesManager> updates_manager_;
|
||||||
ActorId<WallpaperManager> wallpaper_manager_;
|
|
||||||
ActorId<WebPagesManager> web_pages_manager_;
|
ActorId<WebPagesManager> web_pages_manager_;
|
||||||
ActorOwn<ConnectionCreator> connection_creator_;
|
ActorOwn<ConnectionCreator> connection_creator_;
|
||||||
ActorOwn<TempAuthKeyWatchdog> temp_auth_key_watchdog_;
|
ActorOwn<TempAuthKeyWatchdog> temp_auth_key_watchdog_;
|
||||||
|
@ -98,7 +98,7 @@ td_api::object_ptr<td_api::minithumbnail> get_minithumbnail_object(const string
|
|||||||
static FileId register_photo(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
|
static FileId register_photo(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
|
||||||
std::string upload_file_reference,
|
std::string upload_file_reference,
|
||||||
tl_object_ptr<telegram_api::FileLocation> &&location_ptr, DialogId owner_dialog_id,
|
tl_object_ptr<telegram_api::FileLocation> &&location_ptr, DialogId owner_dialog_id,
|
||||||
int32 file_size, bool is_webp = false) {
|
int32 file_size, bool is_webp = false, bool is_png = false) {
|
||||||
DcId dc_id;
|
DcId dc_id;
|
||||||
int32 local_id;
|
int32 local_id;
|
||||||
int64 volume_id;
|
int64 volume_id;
|
||||||
@ -131,11 +131,11 @@ static FileId register_photo(FileManager *file_manager, FileType file_type, int6
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(DEBUG) << "Receive " << (is_webp ? "webp" : "jpeg") << " photo of type " << static_cast<int8>(file_type)
|
LOG(DEBUG) << "Receive " << (is_webp ? "webp" : (is_png ? "png" : "jpeg")) << " photo of type "
|
||||||
<< " in [" << dc_id << "," << volume_id << "," << local_id << "]. Id: (" << id << ", " << access_hash
|
<< static_cast<int8>(file_type) << " in [" << dc_id << "," << volume_id << "," << local_id << "]. Id: ("
|
||||||
<< ")";
|
<< id << ", " << access_hash << ")";
|
||||||
auto suggested_name = PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id)
|
auto suggested_name = PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id)
|
||||||
<< (is_webp ? ".webp" : ".jpg");
|
<< (is_webp ? ".webp" : (is_png ? ".png" : ".jpg"));
|
||||||
return file_manager->register_remote(FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret,
|
return file_manager->register_remote(FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret,
|
||||||
dc_id, upload_file_reference, download_file_reference),
|
dc_id, upload_file_reference, download_file_reference),
|
||||||
FileLocationSource::FromServer, owner_dialog_id, file_size, 0,
|
FileLocationSource::FromServer, owner_dialog_id, file_size, 0,
|
||||||
@ -288,7 +288,8 @@ PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice
|
|||||||
|
|
||||||
Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
|
Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
|
||||||
std::string upload_file_reference, DialogId owner_dialog_id,
|
std::string upload_file_reference, DialogId owner_dialog_id,
|
||||||
tl_object_ptr<telegram_api::PhotoSize> &&size_ptr, bool is_webp) {
|
tl_object_ptr<telegram_api::PhotoSize> &&size_ptr, bool is_webp,
|
||||||
|
bool is_png) {
|
||||||
tl_object_ptr<telegram_api::FileLocation> location_ptr;
|
tl_object_ptr<telegram_api::FileLocation> location_ptr;
|
||||||
string type;
|
string type;
|
||||||
|
|
||||||
@ -331,7 +332,7 @@ Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, FileType fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.file_id = register_photo(file_manager, file_type, id, access_hash, upload_file_reference, std::move(location_ptr),
|
res.file_id = register_photo(file_manager, file_type, id, access_hash, upload_file_reference, std::move(location_ptr),
|
||||||
owner_dialog_id, res.size, is_webp);
|
owner_dialog_id, res.size, is_webp, is_png);
|
||||||
|
|
||||||
if (!content.empty()) {
|
if (!content.empty()) {
|
||||||
file_manager->set_content(res.file_id, std::move(content));
|
file_manager->set_content(res.file_id, std::move(content));
|
||||||
@ -527,7 +528,7 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr<telegram_api::photo> &&
|
|||||||
for (auto &size_ptr : photo->sizes_) {
|
for (auto &size_ptr : photo->sizes_) {
|
||||||
auto photo_size =
|
auto photo_size =
|
||||||
get_photo_size(file_manager, FileType::Photo, photo->id_, photo->access_hash_,
|
get_photo_size(file_manager, FileType::Photo, photo->id_, photo->access_hash_,
|
||||||
photo->file_reference_.as_slice().str(), owner_dialog_id, std::move(size_ptr), false);
|
photo->file_reference_.as_slice().str(), owner_dialog_id, std::move(size_ptr), false, false);
|
||||||
if (photo_size.get_offset() == 0) {
|
if (photo_size.get_offset() == 0) {
|
||||||
res.photos.push_back(std::move(photo_size.get<0>()));
|
res.photos.push_back(std::move(photo_size.get<0>()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,7 +88,7 @@ PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice
|
|||||||
int32 width, int32 height);
|
int32 width, int32 height);
|
||||||
Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
|
Variant<PhotoSize, string> get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
|
||||||
std::string upload_file_reference, DialogId owner_dialog_id,
|
std::string upload_file_reference, DialogId owner_dialog_id,
|
||||||
tl_object_ptr<telegram_api::PhotoSize> &&size_ptr, bool is_webp);
|
tl_object_ptr<telegram_api::PhotoSize> &&size_ptr, bool is_webp, bool is_png);
|
||||||
PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_type, DialogId owner_dialog_id,
|
PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_type, DialogId owner_dialog_id,
|
||||||
tl_object_ptr<telegram_api::WebDocument> web_document_ptr);
|
tl_object_ptr<telegram_api::WebDocument> web_document_ptr);
|
||||||
td_api::object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size);
|
td_api::object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size);
|
||||||
|
@ -1168,7 +1168,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
|
|||||||
PhotoSize thumbnail;
|
PhotoSize thumbnail;
|
||||||
for (auto &thumb : document->thumbs_) {
|
for (auto &thumb : document->thumbs_) {
|
||||||
auto photo_size = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", DialogId(),
|
auto photo_size = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, "", DialogId(),
|
||||||
std::move(thumb), has_webp_thumbnail(sticker));
|
std::move(thumb), has_webp_thumbnail(sticker), false);
|
||||||
if (photo_size.get_offset() == 0) {
|
if (photo_size.get_offset() == 0) {
|
||||||
thumbnail = std::move(photo_size.get<0>());
|
thumbnail = std::move(photo_size.get<0>());
|
||||||
break;
|
break;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "td/telegram/AnimationsManager.h"
|
#include "td/telegram/AnimationsManager.h"
|
||||||
#include "td/telegram/AudiosManager.h"
|
#include "td/telegram/AudiosManager.h"
|
||||||
#include "td/telegram/AuthManager.h"
|
#include "td/telegram/AuthManager.h"
|
||||||
|
#include "td/telegram/BackgroundManager.h"
|
||||||
#include "td/telegram/CallbackQueriesManager.h"
|
#include "td/telegram/CallbackQueriesManager.h"
|
||||||
#include "td/telegram/CallId.h"
|
#include "td/telegram/CallId.h"
|
||||||
#include "td/telegram/CallManager.h"
|
#include "td/telegram/CallManager.h"
|
||||||
@ -71,7 +72,6 @@
|
|||||||
#include "td/telegram/VideoNotesManager.h"
|
#include "td/telegram/VideoNotesManager.h"
|
||||||
#include "td/telegram/VideosManager.h"
|
#include "td/telegram/VideosManager.h"
|
||||||
#include "td/telegram/VoiceNotesManager.h"
|
#include "td/telegram/VoiceNotesManager.h"
|
||||||
#include "td/telegram/WallpaperManager.h"
|
|
||||||
#include "td/telegram/WebPageId.h"
|
#include "td/telegram/WebPageId.h"
|
||||||
#include "td/telegram/WebPagesManager.h"
|
#include "td/telegram/WebPagesManager.h"
|
||||||
|
|
||||||
@ -2885,17 +2885,17 @@ class GetSupportUserRequest : public RequestActor<> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class GetWallpapersRequest : public RequestOnceActor {
|
class GetBackgroundsRequest : public RequestOnceActor {
|
||||||
void do_run(Promise<Unit> &&promise) override {
|
void do_run(Promise<Unit> &&promise) override {
|
||||||
td->wallpaper_manager_->get_wallpapers(std::move(promise));
|
td->background_manager_->get_backgrounds(std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_send_result() override {
|
void do_send_result() override {
|
||||||
send_result(td->wallpaper_manager_->get_wallpapers_object());
|
send_result(td->background_manager_->get_backgrounds_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GetWallpapersRequest(ActorShared<Td> td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) {
|
GetBackgroundsRequest(ActorShared<Td> td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3689,6 +3689,8 @@ void Td::dec_actor_refcnt() {
|
|||||||
LOG(DEBUG) << "AudiosManager was cleared " << timer;
|
LOG(DEBUG) << "AudiosManager was cleared " << timer;
|
||||||
auth_manager_.reset();
|
auth_manager_.reset();
|
||||||
LOG(DEBUG) << "AuthManager was cleared " << timer;
|
LOG(DEBUG) << "AuthManager was cleared " << timer;
|
||||||
|
background_manager_.reset();
|
||||||
|
LOG(DEBUG) << "BackgroundManager was cleared " << timer;
|
||||||
contacts_manager_.reset();
|
contacts_manager_.reset();
|
||||||
LOG(DEBUG) << "ContactsManager was cleared " << timer;
|
LOG(DEBUG) << "ContactsManager was cleared " << timer;
|
||||||
documents_manager_.reset();
|
documents_manager_.reset();
|
||||||
@ -3715,8 +3717,6 @@ void Td::dec_actor_refcnt() {
|
|||||||
LOG(DEBUG) << "VideosManager was cleared " << timer;
|
LOG(DEBUG) << "VideosManager was cleared " << timer;
|
||||||
voice_notes_manager_.reset();
|
voice_notes_manager_.reset();
|
||||||
LOG(DEBUG) << "VoiceNotesManager was cleared " << timer;
|
LOG(DEBUG) << "VoiceNotesManager was cleared " << timer;
|
||||||
wallpaper_manager_.reset();
|
|
||||||
LOG(DEBUG) << "WallpaperManager was cleared " << timer;
|
|
||||||
web_pages_manager_.reset();
|
web_pages_manager_.reset();
|
||||||
LOG(DEBUG) << "WebPagesManager was cleared " << timer;
|
LOG(DEBUG) << "WebPagesManager was cleared " << timer;
|
||||||
Promise<> promise = PromiseCreator::lambda([actor_id = create_reference()](Unit) mutable { actor_id.reset(); });
|
Promise<> promise = PromiseCreator::lambda([actor_id = create_reference()](Unit) mutable { actor_id.reset(); });
|
||||||
@ -3868,6 +3868,8 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "AnimationsManager actor was cleared " << timer;
|
LOG(DEBUG) << "AnimationsManager actor was cleared " << timer;
|
||||||
auth_manager_actor_.reset();
|
auth_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "AuthManager actor was cleared " << timer;
|
LOG(DEBUG) << "AuthManager actor was cleared " << timer;
|
||||||
|
background_manager_actor_.reset();
|
||||||
|
LOG(DEBUG) << "BackgroundManager actor was cleared " << timer;
|
||||||
contacts_manager_actor_.reset();
|
contacts_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "ContactsManager actor was cleared " << timer;
|
LOG(DEBUG) << "ContactsManager actor was cleared " << timer;
|
||||||
file_manager_actor_.reset();
|
file_manager_actor_.reset();
|
||||||
@ -3886,8 +3888,6 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "StickersManager actor was cleared " << timer;
|
LOG(DEBUG) << "StickersManager actor was cleared " << timer;
|
||||||
updates_manager_actor_.reset();
|
updates_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "UpdatesManager actor was cleared " << timer;
|
LOG(DEBUG) << "UpdatesManager actor was cleared " << timer;
|
||||||
wallpaper_manager_actor_.reset();
|
|
||||||
LOG(DEBUG) << "WallpaperManager actor was cleared " << timer;
|
|
||||||
web_pages_manager_actor_.reset();
|
web_pages_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "WebPagesManager actor was cleared " << timer;
|
LOG(DEBUG) << "WebPagesManager actor was cleared " << timer;
|
||||||
}
|
}
|
||||||
@ -4247,10 +4247,6 @@ void Td::init_file_manager() {
|
|||||||
return td_->file_reference_manager_->add_file_source(file_id, file_source_id);
|
return td_->file_reference_manager_->add_file_source(file_id, file_source_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSourceId get_wallpapers_file_source_id() final {
|
|
||||||
return td_->wallpaper_manager_->get_wallpapers_file_source_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool remove_file_source(FileId file_id, FileSourceId file_source_id) final {
|
bool remove_file_source(FileId file_id, FileSourceId file_source_id) final {
|
||||||
return td_->file_reference_manager_->remove_file_source(file_id, file_source_id);
|
return td_->file_reference_manager_->remove_file_source(file_id, file_source_id);
|
||||||
}
|
}
|
||||||
@ -4298,6 +4294,9 @@ void Td::init_managers() {
|
|||||||
animations_manager_ = make_unique<AnimationsManager>(this, create_reference());
|
animations_manager_ = make_unique<AnimationsManager>(this, create_reference());
|
||||||
animations_manager_actor_ = register_actor("AnimationsManager", animations_manager_.get());
|
animations_manager_actor_ = register_actor("AnimationsManager", animations_manager_.get());
|
||||||
G()->set_animations_manager(animations_manager_actor_.get());
|
G()->set_animations_manager(animations_manager_actor_.get());
|
||||||
|
background_manager_ = make_unique<BackgroundManager>(this, create_reference());
|
||||||
|
background_manager_actor_ = register_actor("BackgroundManager", background_manager_.get());
|
||||||
|
G()->set_background_manager(background_manager_actor_.get());
|
||||||
contacts_manager_ = make_unique<ContactsManager>(this, create_reference());
|
contacts_manager_ = make_unique<ContactsManager>(this, create_reference());
|
||||||
contacts_manager_actor_ = register_actor("ContactsManager", contacts_manager_.get());
|
contacts_manager_actor_ = register_actor("ContactsManager", contacts_manager_.get());
|
||||||
G()->set_contacts_manager(contacts_manager_actor_.get());
|
G()->set_contacts_manager(contacts_manager_actor_.get());
|
||||||
@ -4317,9 +4316,6 @@ void Td::init_managers() {
|
|||||||
updates_manager_ = make_unique<UpdatesManager>(this, create_reference());
|
updates_manager_ = make_unique<UpdatesManager>(this, create_reference());
|
||||||
updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get());
|
updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get());
|
||||||
G()->set_updates_manager(updates_manager_actor_.get());
|
G()->set_updates_manager(updates_manager_actor_.get());
|
||||||
wallpaper_manager_ = make_unique<WallpaperManager>(this, create_reference());
|
|
||||||
wallpaper_manager_actor_ = register_actor("WallpaperManager", wallpaper_manager_.get());
|
|
||||||
G()->set_wallpaper_manager(wallpaper_manager_actor_.get());
|
|
||||||
web_pages_manager_ = make_unique<WebPagesManager>(this, create_reference());
|
web_pages_manager_ = make_unique<WebPagesManager>(this, create_reference());
|
||||||
web_pages_manager_actor_ = register_actor("WebPagesManager", web_pages_manager_.get());
|
web_pages_manager_actor_ = register_actor("WebPagesManager", web_pages_manager_.get());
|
||||||
G()->set_web_pages_manager(web_pages_manager_actor_.get());
|
G()->set_web_pages_manager(web_pages_manager_actor_.get());
|
||||||
@ -6943,9 +6939,9 @@ void Td::on_request(uint64 id, const td_api::getSupportUser &request) {
|
|||||||
CREATE_NO_ARGS_REQUEST(GetSupportUserRequest);
|
CREATE_NO_ARGS_REQUEST(GetSupportUserRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getWallpapers &request) {
|
void Td::on_request(uint64 id, const td_api::getBackgrounds &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_NO_ARGS_REQUEST(GetWallpapersRequest);
|
CREATE_NO_ARGS_REQUEST(GetBackgroundsRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request) {
|
void Td::on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request) {
|
||||||
|
@ -39,6 +39,7 @@ namespace td {
|
|||||||
class AnimationsManager;
|
class AnimationsManager;
|
||||||
class AudiosManager;
|
class AudiosManager;
|
||||||
class AuthManager;
|
class AuthManager;
|
||||||
|
class BackgroundManager;
|
||||||
class CallManager;
|
class CallManager;
|
||||||
class CallbackQueriesManager;
|
class CallbackQueriesManager;
|
||||||
class ConfigManager;
|
class ConfigManager;
|
||||||
@ -66,7 +67,6 @@ class UpdatesManager;
|
|||||||
class VideoNotesManager;
|
class VideoNotesManager;
|
||||||
class VideosManager;
|
class VideosManager;
|
||||||
class VoiceNotesManager;
|
class VoiceNotesManager;
|
||||||
class WallpaperManager;
|
|
||||||
class WebPagesManager;
|
class WebPagesManager;
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
@ -140,6 +140,8 @@ class Td final : public NetQueryCallback {
|
|||||||
ActorOwn<AnimationsManager> animations_manager_actor_;
|
ActorOwn<AnimationsManager> animations_manager_actor_;
|
||||||
unique_ptr<AuthManager> auth_manager_;
|
unique_ptr<AuthManager> auth_manager_;
|
||||||
ActorOwn<AuthManager> auth_manager_actor_;
|
ActorOwn<AuthManager> auth_manager_actor_;
|
||||||
|
unique_ptr<BackgroundManager> background_manager_;
|
||||||
|
ActorOwn<BackgroundManager> background_manager_actor_;
|
||||||
unique_ptr<ContactsManager> contacts_manager_;
|
unique_ptr<ContactsManager> contacts_manager_;
|
||||||
ActorOwn<ContactsManager> contacts_manager_actor_;
|
ActorOwn<ContactsManager> contacts_manager_actor_;
|
||||||
unique_ptr<FileManager> file_manager_;
|
unique_ptr<FileManager> file_manager_;
|
||||||
@ -158,8 +160,6 @@ class Td final : public NetQueryCallback {
|
|||||||
ActorOwn<StickersManager> stickers_manager_actor_;
|
ActorOwn<StickersManager> stickers_manager_actor_;
|
||||||
unique_ptr<UpdatesManager> updates_manager_;
|
unique_ptr<UpdatesManager> updates_manager_;
|
||||||
ActorOwn<UpdatesManager> updates_manager_actor_;
|
ActorOwn<UpdatesManager> updates_manager_actor_;
|
||||||
unique_ptr<WallpaperManager> wallpaper_manager_;
|
|
||||||
ActorOwn<WallpaperManager> wallpaper_manager_actor_;
|
|
||||||
unique_ptr<WebPagesManager> web_pages_manager_;
|
unique_ptr<WebPagesManager> web_pages_manager_;
|
||||||
ActorOwn<WebPagesManager> web_pages_manager_actor_;
|
ActorOwn<WebPagesManager> web_pages_manager_actor_;
|
||||||
|
|
||||||
@ -922,7 +922,7 @@ class Td final : public NetQueryCallback {
|
|||||||
|
|
||||||
void on_request(uint64 id, const td_api::getSupportUser &request);
|
void on_request(uint64 id, const td_api::getSupportUser &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getWallpapers &request);
|
void on_request(uint64 id, const td_api::getBackgrounds &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request);
|
void on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request);
|
||||||
|
|
||||||
|
@ -1,152 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
|
||||||
//
|
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
//
|
|
||||||
#include "td/telegram/WallpaperManager.h"
|
|
||||||
|
|
||||||
#include "td/telegram/td_api.h"
|
|
||||||
#include "td/telegram/telegram_api.h"
|
|
||||||
|
|
||||||
#include "td/telegram/DialogId.h"
|
|
||||||
#include "td/telegram/FileReferenceManager.h"
|
|
||||||
#include "td/telegram/files/FileManager.h"
|
|
||||||
#include "td/telegram/files/FileType.h"
|
|
||||||
#include "td/telegram/Global.h"
|
|
||||||
#include "td/telegram/Photo.h"
|
|
||||||
#include "td/telegram/Td.h"
|
|
||||||
|
|
||||||
#include "td/utils/buffer.h"
|
|
||||||
#include "td/utils/common.h"
|
|
||||||
#include "td/utils/misc.h"
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
|
|
||||||
class GetWallpapersQuery : public Td::ResultHandler {
|
|
||||||
Promise<vector<telegram_api::object_ptr<telegram_api::wallPaper>>> promise_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit GetWallpapersQuery(Promise<vector<telegram_api::object_ptr<telegram_api::wallPaper>>> &&promise)
|
|
||||||
: promise_(std::move(promise)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void send() {
|
|
||||||
send_query(G()->net_query_creator().create(create_storer(telegram_api::account_getWallPapers(0))));
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_result(uint64 id, BufferSlice packet) override {
|
|
||||||
auto result_ptr = fetch_result<telegram_api::account_getWallPapers>(packet);
|
|
||||||
if (result_ptr.is_error()) {
|
|
||||||
return on_error(id, result_ptr.move_as_error());
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
promise_.set_value(vector<telegram_api::object_ptr<telegram_api::wallPaper>>());
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_error(uint64 id, Status status) override {
|
|
||||||
promise_.set_error(std::move(status));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
WallpaperManager::WallpaperManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperManager::tear_down() {
|
|
||||||
parent_.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperManager::get_wallpapers(Promise<Unit> &&promise) {
|
|
||||||
if (!wallpapers_.empty()) {
|
|
||||||
return promise.set_value(Unit());
|
|
||||||
}
|
|
||||||
|
|
||||||
reload_wallpapers(std::move(promise));
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperManager::reload_wallpapers(Promise<Unit> &&promise) {
|
|
||||||
pending_get_wallpapers_queries_.push_back(std::move(promise));
|
|
||||||
if (pending_get_wallpapers_queries_.size() == 1) {
|
|
||||||
auto request_promise = PromiseCreator::lambda(
|
|
||||||
[actor_id = actor_id(this)](Result<vector<telegram_api::object_ptr<telegram_api::wallPaper>>> result) {
|
|
||||||
send_closure(actor_id, &WallpaperManager::on_get_wallpapers, std::move(result));
|
|
||||||
});
|
|
||||||
|
|
||||||
td_->create_handler<GetWallpapersQuery>(std::move(request_promise))->send();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WallpaperManager::on_get_wallpapers(Result<vector<telegram_api::object_ptr<telegram_api::wallPaper>>> result) {
|
|
||||||
auto promises = std::move(pending_get_wallpapers_queries_);
|
|
||||||
CHECK(!promises.empty());
|
|
||||||
reset_to_empty(pending_get_wallpapers_queries_);
|
|
||||||
|
|
||||||
if (result.is_error()) {
|
|
||||||
// do not clear wallpapers_
|
|
||||||
|
|
||||||
auto error = result.move_as_error();
|
|
||||||
for (auto &promise : promises) {
|
|
||||||
promise.set_error(error.clone());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
wallpapers_ = transform(result.move_as_ok(), [file_manager = td_->file_manager_.get()](
|
|
||||||
tl_object_ptr<telegram_api::wallPaper> &&wallpaper_ptr) {
|
|
||||||
CHECK(wallpaper_ptr != nullptr);
|
|
||||||
switch (wallpaper_ptr->get_id()) {
|
|
||||||
case telegram_api::wallPaper::ID: {
|
|
||||||
auto wallpaper = move_tl_object_as<telegram_api::wallPaper>(wallpaper_ptr);
|
|
||||||
vector<PhotoSize> sizes;
|
|
||||||
sizes.reserve(wallpaper->sizes_.size());
|
|
||||||
for (auto &size : wallpaper->sizes_) {
|
|
||||||
auto photo_size =
|
|
||||||
get_photo_size(file_manager, FileType::Wallpaper, 0, 0, "", DialogId(), std::move(size), false);
|
|
||||||
if (photo_size.get_offset() == 0) {
|
|
||||||
sizes.push_back(std::move(photo_size.get<0>()));
|
|
||||||
} else {
|
|
||||||
LOG(ERROR) << "Receive minithumbnail for a wallpaper";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Wallpaper{wallpaper->id_, std::move(sizes), wallpaper->color_};
|
|
||||||
}
|
|
||||||
case telegram_api::wallPaperSolid::ID: {
|
|
||||||
auto wallpaper = move_tl_object_as<telegram_api::wallPaperSolid>(wallpaper_ptr);
|
|
||||||
return Wallpaper{wallpaper->id_, {}, wallpaper->bg_color_};
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
return Wallpaper{0, {}, 0};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
vector<FileId> new_file_ids;
|
|
||||||
for (auto &wallpaper : wallpapers_) {
|
|
||||||
append(new_file_ids, transform(wallpaper.sizes, [](auto &size) { return size.file_id; }));
|
|
||||||
};
|
|
||||||
td_->file_manager_->change_files_source(get_wallpapers_file_source_id(), wallpaper_file_ids_, new_file_ids);
|
|
||||||
wallpaper_file_ids_ = std::move(new_file_ids);
|
|
||||||
|
|
||||||
for (auto &promise : promises) {
|
|
||||||
promise.set_value(Unit());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileSourceId WallpaperManager::get_wallpapers_file_source_id() {
|
|
||||||
if (!wallpaper_source_id_.is_valid()) {
|
|
||||||
wallpaper_source_id_ = td_->file_reference_manager_->create_wallpapers_file_source();
|
|
||||||
}
|
|
||||||
return wallpaper_source_id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
td_api::object_ptr<td_api::wallpapers> WallpaperManager::get_wallpapers_object() const {
|
|
||||||
return td_api::make_object<td_api::wallpapers>(
|
|
||||||
transform(wallpapers_, [file_manager = td_->file_manager_.get()](const Wallpaper &wallpaper) {
|
|
||||||
return td_api::make_object<td_api::wallpaper>(
|
|
||||||
wallpaper.id, get_photo_sizes_object(file_manager, wallpaper.sizes), wallpaper.color);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace td
|
|
@ -1,60 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
|
||||||
//
|
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "td/telegram/files/FileId.h"
|
|
||||||
#include "td/telegram/files/FileSourceId.h"
|
|
||||||
#include "td/telegram/Photo.h"
|
|
||||||
#include "td/telegram/td_api.h"
|
|
||||||
#include "td/telegram/telegram_api.h"
|
|
||||||
|
|
||||||
#include "td/actor/actor.h"
|
|
||||||
#include "td/actor/PromiseFuture.h"
|
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
|
||||||
#include "td/utils/Status.h"
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
|
|
||||||
class Td;
|
|
||||||
|
|
||||||
class WallpaperManager : public Actor {
|
|
||||||
public:
|
|
||||||
WallpaperManager(Td *td, ActorShared<> parent);
|
|
||||||
|
|
||||||
void get_wallpapers(Promise<Unit> &&promise);
|
|
||||||
|
|
||||||
void reload_wallpapers(Promise<Unit> &&promise);
|
|
||||||
|
|
||||||
td_api::object_ptr<td_api::wallpapers> get_wallpapers_object() const;
|
|
||||||
|
|
||||||
FileSourceId get_wallpapers_file_source_id();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void tear_down() override;
|
|
||||||
|
|
||||||
void on_get_wallpapers(Result<vector<telegram_api::object_ptr<telegram_api::wallPaper>>> result);
|
|
||||||
|
|
||||||
struct Wallpaper {
|
|
||||||
int32 id = 0;
|
|
||||||
vector<PhotoSize> sizes;
|
|
||||||
int32 color = 0;
|
|
||||||
|
|
||||||
Wallpaper(int32 id, vector<PhotoSize> sizes, int32 color) : id(id), sizes(std::move(sizes)), color(color) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
vector<Wallpaper> wallpapers_;
|
|
||||||
vector<FileId> wallpaper_file_ids_;
|
|
||||||
FileSourceId wallpaper_source_id_;
|
|
||||||
|
|
||||||
vector<Promise<Unit>> pending_get_wallpapers_queries_;
|
|
||||||
|
|
||||||
Td *td_;
|
|
||||||
ActorShared<> parent_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace td
|
|
@ -1959,8 +1959,8 @@ class CliClient final : public Actor {
|
|||||||
send_request(td_api::make_object<td_api::disconnectWebsite>(to_integer<int64>(args)));
|
send_request(td_api::make_object<td_api::disconnectWebsite>(to_integer<int64>(args)));
|
||||||
} else if (op == "daw") {
|
} else if (op == "daw") {
|
||||||
send_request(td_api::make_object<td_api::disconnectAllWebsites>());
|
send_request(td_api::make_object<td_api::disconnectAllWebsites>());
|
||||||
} else if (op == "gw") {
|
} else if (op == "gb") {
|
||||||
send_request(td_api::make_object<td_api::getWallpapers>());
|
send_request(td_api::make_object<td_api::getBackgrounds>());
|
||||||
} else if (op == "gccode") {
|
} else if (op == "gccode") {
|
||||||
send_request(td_api::make_object<td_api::getCountryCode>());
|
send_request(td_api::make_object<td_api::getCountryCode>());
|
||||||
} else if (op == "git") {
|
} else if (op == "git") {
|
||||||
|
@ -53,11 +53,17 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector<FullFi
|
|||||||
immune_types[narrow_cast<size_t>(FileType::ProfilePhoto)] = true;
|
immune_types[narrow_cast<size_t>(FileType::ProfilePhoto)] = true;
|
||||||
immune_types[narrow_cast<size_t>(FileType::Thumbnail)] = true;
|
immune_types[narrow_cast<size_t>(FileType::Thumbnail)] = true;
|
||||||
immune_types[narrow_cast<size_t>(FileType::Wallpaper)] = true;
|
immune_types[narrow_cast<size_t>(FileType::Wallpaper)] = true;
|
||||||
|
immune_types[narrow_cast<size_t>(FileType::Background)] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parameters.file_types.empty()) {
|
if (!parameters.file_types.empty()) {
|
||||||
std::fill(immune_types.begin(), immune_types.end(), true);
|
std::fill(immune_types.begin(), immune_types.end(), true);
|
||||||
for (auto file_type : parameters.file_types) {
|
for (auto file_type : parameters.file_types) {
|
||||||
|
if (file_type == FileType::Secure) {
|
||||||
|
immune_types[narrow_cast<size_t>(FileType::SecureRaw)] = false;
|
||||||
|
} else if (file_type == FileType::Background) {
|
||||||
|
immune_types[narrow_cast<size_t>(FileType::Wallpaper)] = false;
|
||||||
|
}
|
||||||
immune_types[narrow_cast<size_t>(file_type)] = false;
|
immune_types[narrow_cast<size_t>(file_type)] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,7 @@ class FullRemoteFileLocation {
|
|||||||
case FileType::VideoNote:
|
case FileType::VideoNote:
|
||||||
case FileType::SecureRaw:
|
case FileType::SecureRaw:
|
||||||
case FileType::Secure:
|
case FileType::Secure:
|
||||||
|
case FileType::Background:
|
||||||
return LocationType::Common;
|
return LocationType::Common;
|
||||||
case FileType::None:
|
case FileType::None:
|
||||||
case FileType::Size:
|
case FileType::Size:
|
||||||
|
@ -708,7 +708,11 @@ FileManager::FileManager(unique_ptr<Context> context) : context_(std::move(conte
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
for (int32 i = 0; i < file_type_size; i++) {
|
for (int32 i = 0; i < file_type_size; i++) {
|
||||||
auto path = get_files_dir(FileType(i));
|
FileType file_type = static_cast<FileType>(i);
|
||||||
|
if (file_type == FileType::SecureRaw || file_type == FileType::Background) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto path = get_files_dir(file_type);
|
||||||
create_dir(path);
|
create_dir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,13 +772,18 @@ string FileManager::get_file_name(FileType file_type, Slice path) {
|
|||||||
return fix_file_extension(file_name, "audio", "mp3");
|
return fix_file_extension(file_name, "audio", "mp3");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case FileType::Wallpaper:
|
||||||
|
case FileType::Background:
|
||||||
|
if (extension != "jpg" && extension != "jpeg" && extension != "png") {
|
||||||
|
return fix_file_extension(file_name, "wallpaper", "jpg");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case FileType::Document:
|
case FileType::Document:
|
||||||
case FileType::Sticker:
|
case FileType::Sticker:
|
||||||
case FileType::Animation:
|
case FileType::Animation:
|
||||||
case FileType::Encrypted:
|
case FileType::Encrypted:
|
||||||
case FileType::Temp:
|
case FileType::Temp:
|
||||||
case FileType::EncryptedThumbnail:
|
case FileType::EncryptedThumbnail:
|
||||||
case FileType::Wallpaper:
|
|
||||||
case FileType::Secure:
|
case FileType::Secure:
|
||||||
case FileType::SecureRaw:
|
case FileType::SecureRaw:
|
||||||
break;
|
break;
|
||||||
@ -2531,7 +2540,11 @@ void FileManager::cancel_upload(FileId file_id) {
|
|||||||
|
|
||||||
static bool is_document_type(FileType type) {
|
static bool is_document_type(FileType type) {
|
||||||
return type == FileType::Document || type == FileType::Sticker || type == FileType::Audio ||
|
return type == FileType::Document || type == FileType::Sticker || type == FileType::Audio ||
|
||||||
type == FileType::Animation;
|
type == FileType::Animation || type == FileType::Background;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_background_type(FileType type) {
|
||||||
|
return type == FileType::Wallpaper || type == FileType::Background;
|
||||||
}
|
}
|
||||||
|
|
||||||
string FileManager::get_persistent_id(const FullGenerateFileLocation &location) {
|
string FileManager::get_persistent_id(const FullGenerateFileLocation &location) {
|
||||||
@ -2611,6 +2624,8 @@ Result<FileId> FileManager::from_persistent_id_v2(Slice binary, FileType file_ty
|
|||||||
auto &real_file_type = remote_location.file_type_;
|
auto &real_file_type = remote_location.file_type_;
|
||||||
if (is_document_type(real_file_type) && is_document_type(file_type)) {
|
if (is_document_type(real_file_type) && is_document_type(file_type)) {
|
||||||
real_file_type = file_type;
|
real_file_type = file_type;
|
||||||
|
} else if (is_background_type(real_file_type) && is_background_type(file_type)) {
|
||||||
|
real_file_type = file_type;
|
||||||
} else if (real_file_type != file_type && file_type != FileType::Temp) {
|
} else if (real_file_type != file_type && file_type != FileType::Temp) {
|
||||||
return Status::Error(10, "Type of file mismatch");
|
return Status::Error(10, "Type of file mismatch");
|
||||||
}
|
}
|
||||||
@ -2618,9 +2633,6 @@ Result<FileId> FileManager::from_persistent_id_v2(Slice binary, FileType file_ty
|
|||||||
data.remote_ = RemoteFileLocation(std::move(remote_location));
|
data.remote_ = RemoteFileLocation(std::move(remote_location));
|
||||||
auto file_id =
|
auto file_id =
|
||||||
register_file(std::move(data), FileLocationSource::FromUser, "from_persistent_id_v2", false).move_as_ok();
|
register_file(std::move(data), FileLocationSource::FromUser, "from_persistent_id_v2", false).move_as_ok();
|
||||||
if (real_file_type == FileType::Wallpaper && file_id.is_valid()) {
|
|
||||||
add_file_source(file_id, context_->get_wallpapers_file_source_id());
|
|
||||||
}
|
|
||||||
return file_id;
|
return file_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2720,7 +2732,8 @@ Result<FileId> FileManager::check_input_file_id(FileType type, Result<FileId> re
|
|||||||
FileType real_type = file_view.get_type();
|
FileType real_type = file_view.get_type();
|
||||||
if (!is_encrypted && !is_secure) {
|
if (!is_encrypted && !is_secure) {
|
||||||
if (real_type != type && !(real_type == FileType::Temp && file_view.has_url()) &&
|
if (real_type != type && !(real_type == FileType::Temp && file_view.has_url()) &&
|
||||||
!(is_document_type(real_type) && is_document_type(type))) {
|
!(is_document_type(real_type) && is_document_type(type)) &&
|
||||||
|
!(is_background_type(real_type) && is_background_type(type))) {
|
||||||
// TODO: send encrypted file to unencrypted chat
|
// TODO: send encrypted file to unencrypted chat
|
||||||
return Status::Error(6, "Type of file mismatch");
|
return Status::Error(6, "Type of file mismatch");
|
||||||
}
|
}
|
||||||
|
@ -346,8 +346,6 @@ class FileManager : public FileLoadManager::Callback {
|
|||||||
|
|
||||||
virtual bool add_file_source(FileId file_id, FileSourceId file_source_id) = 0;
|
virtual bool add_file_source(FileId file_id, FileSourceId file_source_id) = 0;
|
||||||
|
|
||||||
virtual FileSourceId get_wallpapers_file_source_id() = 0;
|
|
||||||
|
|
||||||
virtual bool remove_file_source(FileId file_id, FileSourceId file_source_id) = 0;
|
virtual bool remove_file_source(FileId file_id, FileSourceId file_source_id) = 0;
|
||||||
|
|
||||||
virtual void on_merge_files(FileId to_file_id, FileId from_file_id) = 0;
|
virtual void on_merge_files(FileId to_file_id, FileId from_file_id) = 0;
|
||||||
|
@ -123,6 +123,8 @@ tl_object_ptr<td_api::storageStatisticsByChat> as_td_api(DialogId dialog_id,
|
|||||||
auto stats = make_tl_object<td_api::storageStatisticsByChat>(dialog_id.get(), 0, 0, Auto());
|
auto stats = make_tl_object<td_api::storageStatisticsByChat>(dialog_id.get(), 0, 0, Auto());
|
||||||
int64 secure_raw_size = 0;
|
int64 secure_raw_size = 0;
|
||||||
int32 secure_raw_cnt = 0;
|
int32 secure_raw_cnt = 0;
|
||||||
|
int64 wallpaper_raw_size = 0;
|
||||||
|
int32 wallpaper_raw_cnt = 0;
|
||||||
for (int32 i = 0; i < file_type_size; i++) {
|
for (int32 i = 0; i < file_type_size; i++) {
|
||||||
FileType file_type = static_cast<FileType>(i);
|
FileType file_type = static_cast<FileType>(i);
|
||||||
auto size = stat_by_type[i].size;
|
auto size = stat_by_type[i].size;
|
||||||
@ -133,10 +135,19 @@ tl_object_ptr<td_api::storageStatisticsByChat> as_td_api(DialogId dialog_id,
|
|||||||
secure_raw_cnt = cnt;
|
secure_raw_cnt = cnt;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (file_type == FileType::Wallpaper) {
|
||||||
|
wallpaper_raw_size = size;
|
||||||
|
wallpaper_raw_cnt = cnt;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (file_type == FileType::Secure) {
|
if (file_type == FileType::Secure) {
|
||||||
size += secure_raw_size;
|
size += secure_raw_size;
|
||||||
cnt += secure_raw_cnt;
|
cnt += secure_raw_cnt;
|
||||||
}
|
}
|
||||||
|
if (file_type == FileType::Background) {
|
||||||
|
size += wallpaper_raw_size;
|
||||||
|
cnt += wallpaper_raw_cnt;
|
||||||
|
}
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ template <class CallbackT>
|
|||||||
void scan_fs(CancellationToken &token, CallbackT &&callback) {
|
void scan_fs(CancellationToken &token, CallbackT &&callback) {
|
||||||
for (int32 i = 0; i < file_type_size; i++) {
|
for (int32 i = 0; i < file_type_size; i++) {
|
||||||
auto file_type = static_cast<FileType>(i);
|
auto file_type = static_cast<FileType>(i);
|
||||||
if (file_type == FileType::SecureRaw) {
|
if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto files_dir = get_files_dir(file_type);
|
auto files_dir = get_files_dir(file_type);
|
||||||
|
@ -31,6 +31,7 @@ enum class FileType : int8 {
|
|||||||
VideoNote,
|
VideoNote,
|
||||||
SecureRaw,
|
SecureRaw,
|
||||||
Secure,
|
Secure,
|
||||||
|
Background,
|
||||||
Size,
|
Size,
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -62,7 +63,7 @@ inline FileType from_td_api(const td_api::FileType &file_type) {
|
|||||||
case td_api::fileTypeSecretThumbnail::ID:
|
case td_api::fileTypeSecretThumbnail::ID:
|
||||||
return FileType::EncryptedThumbnail;
|
return FileType::EncryptedThumbnail;
|
||||||
case td_api::fileTypeWallpaper::ID:
|
case td_api::fileTypeWallpaper::ID:
|
||||||
return FileType::Wallpaper;
|
return FileType::Background;
|
||||||
case td_api::fileTypeVideoNote::ID:
|
case td_api::fileTypeVideoNote::ID:
|
||||||
return FileType::VideoNote;
|
return FileType::VideoNote;
|
||||||
case td_api::fileTypeSecure::ID:
|
case td_api::fileTypeSecure::ID:
|
||||||
@ -110,6 +111,8 @@ inline tl_object_ptr<td_api::FileType> as_td_api(FileType file_type) {
|
|||||||
case FileType::SecureRaw:
|
case FileType::SecureRaw:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
return make_tl_object<td_api::fileTypeSecure>();
|
return make_tl_object<td_api::fileTypeSecure>();
|
||||||
|
case FileType::Background:
|
||||||
|
return make_tl_object<td_api::fileTypeWallpaper>();
|
||||||
case FileType::None:
|
case FileType::None:
|
||||||
return make_tl_object<td_api::fileTypeNone>();
|
return make_tl_object<td_api::fileTypeNone>();
|
||||||
default:
|
default:
|
||||||
@ -154,6 +157,8 @@ inline CSlice get_file_type_name(FileType file_type) {
|
|||||||
return CSlice("passport");
|
return CSlice("passport");
|
||||||
case FileType::Secure:
|
case FileType::Secure:
|
||||||
return CSlice("passport");
|
return CSlice("passport");
|
||||||
|
case FileType::Background:
|
||||||
|
return CSlice("wallpapers");
|
||||||
case FileType::Size:
|
case FileType::Size:
|
||||||
case FileType::None:
|
case FileType::None:
|
||||||
default:
|
default:
|
||||||
@ -179,6 +184,7 @@ inline FileDirType get_file_dir_type(FileType file_type) {
|
|||||||
case FileType::EncryptedThumbnail:
|
case FileType::EncryptedThumbnail:
|
||||||
case FileType::Secure:
|
case FileType::Secure:
|
||||||
case FileType::SecureRaw:
|
case FileType::SecureRaw:
|
||||||
|
case FileType::Background:
|
||||||
return FileDirType::Secure;
|
return FileDirType::Secure;
|
||||||
default:
|
default:
|
||||||
return FileDirType::Common;
|
return FileDirType::Common;
|
||||||
|
@ -59,7 +59,7 @@ void NetStatsManager::init() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for_each_stat([&](NetStatsInfo &stat, size_t id, CSlice name, FileType file_type) {
|
for_each_stat([&](NetStatsInfo &stat, size_t id, CSlice name, FileType file_type) {
|
||||||
if (file_type == FileType::SecureRaw) {
|
if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) {
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
stat.key = "net_stats_" + name.str();
|
stat.key = "net_stats_" + name.str();
|
||||||
@ -112,7 +112,7 @@ void NetStatsManager::get_network_stats(bool current, Promise<NetworkStats> prom
|
|||||||
entry.is_call = true;
|
entry.is_call = true;
|
||||||
result.entries.push_back(std::move(entry));
|
result.entries.push_back(std::move(entry));
|
||||||
} else if (file_type != FileType::None) {
|
} else if (file_type != FileType::None) {
|
||||||
if (file_type == FileType::SecureRaw) {
|
if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ void NetStatsManager::add_network_stats_impl(NetStatsInfo &info, const NetworkSt
|
|||||||
|
|
||||||
void NetStatsManager::start_up() {
|
void NetStatsManager::start_up() {
|
||||||
for_each_stat([&](NetStatsInfo &info, size_t id, CSlice name, FileType file_type) {
|
for_each_stat([&](NetStatsInfo &info, size_t id, CSlice name, FileType file_type) {
|
||||||
if (file_type == FileType::SecureRaw) {
|
if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +252,7 @@ std::shared_ptr<NetStatsCallback> NetStatsManager::get_media_stats_callback() co
|
|||||||
std::vector<std::shared_ptr<NetStatsCallback>> NetStatsManager::get_file_stats_callbacks() const {
|
std::vector<std::shared_ptr<NetStatsCallback>> NetStatsManager::get_file_stats_callbacks() const {
|
||||||
auto result = transform(files_stats_, [](auto &stat) { return stat.stats.get_callback(); });
|
auto result = transform(files_stats_, [](auto &stat) { return stat.stats.get_callback(); });
|
||||||
result[static_cast<int32>(FileType::SecureRaw)] = result[static_cast<int32>(FileType::Secure)];
|
result[static_cast<int32>(FileType::SecureRaw)] = result[static_cast<int32>(FileType::Secure)];
|
||||||
|
result[static_cast<int32>(FileType::Wallpaper)] = result[static_cast<int32>(FileType::Background)];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user