Add td_api::getBackgroundUrl.
GitOrigin-RevId: d9f55ce5f4d6630795fc269b3c19045376393d84
This commit is contained in:
parent
85dd77b02c
commit
d8f95c3ea0
@ -3601,9 +3601,13 @@ deleteSavedCredentials = Ok;
|
||||
//@description Returns a user that can be contacted to get support
|
||||
getSupportUser = User;
|
||||
|
||||
|
||||
//@description Returns backgrounds installed by the user
|
||||
getBackgrounds = Backgrounds;
|
||||
|
||||
//@description Constructs persistent URL for a background @name Background name @type Background type
|
||||
getBackgroundUrl name:string type:BackgroundType = HttpUrl;
|
||||
|
||||
|
||||
//@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
|
||||
getLocalizationTargetInfo only_local:Bool = LocalizationTargetInfo;
|
||||
|
Binary file not shown.
@ -9,6 +9,7 @@
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/Document.h"
|
||||
#include "td/telegram/DocumentsManager.h"
|
||||
@ -70,6 +71,91 @@ void BackgroundManager::get_backgrounds(Promise<Unit> &&promise) {
|
||||
}
|
||||
}
|
||||
|
||||
Result<BackgroundManager::BackgroundType> BackgroundManager::get_background_type(
|
||||
td_api::object_ptr<td_api::BackgroundType> type) {
|
||||
if (type == nullptr) {
|
||||
return Status::Error(400, "Type must not be empty");
|
||||
}
|
||||
|
||||
BackgroundType result;
|
||||
switch (type->get_id()) {
|
||||
case td_api::backgroundTypeWallpaper::ID: {
|
||||
auto wallpaper = td_api::move_object_as<td_api::backgroundTypeWallpaper>(type);
|
||||
result = BackgroundType(wallpaper->is_blurred_, wallpaper->is_moving_);
|
||||
break;
|
||||
}
|
||||
case td_api::backgroundTypePattern::ID: {
|
||||
auto pattern = td_api::move_object_as<td_api::backgroundTypePattern>(type);
|
||||
result = BackgroundType(pattern->is_moving_, pattern->color_, pattern->intensity_);
|
||||
break;
|
||||
}
|
||||
case td_api::backgroundTypeSolid::ID: {
|
||||
auto solid = td_api::move_object_as<td_api::backgroundTypeSolid>(type);
|
||||
result = BackgroundType(solid->color_);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (result.intensity < 0 || result.intensity > 100) {
|
||||
return Status::Error(400, "Wrong intensity value");
|
||||
}
|
||||
if (result.color < 0 || result.color > 0xFFFFFF) {
|
||||
return Status::Error(400, "Wrong color value");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<string> BackgroundManager::get_background_url(const string &name,
|
||||
td_api::object_ptr<td_api::BackgroundType> background_type) const {
|
||||
TRY_RESULT(type, get_background_type(std::move(background_type)));
|
||||
|
||||
vector<string> modes;
|
||||
if (type.is_blurred) {
|
||||
modes.emplace_back("blur");
|
||||
}
|
||||
if (type.is_moving) {
|
||||
modes.emplace_back("motion");
|
||||
}
|
||||
string mode = implode(modes, '+');
|
||||
|
||||
auto get_color_string = [](int32 color) {
|
||||
string result;
|
||||
for (int i = 20; i >= 0; i -= 4) {
|
||||
result += "0123456789abcdef"[(color >> i) & 0xf];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
string url = PSTRING() << G()->shared_config().get_option_string("t_me_url", "https://t.me/") << "bg/";
|
||||
switch (type.type) {
|
||||
case BackgroundType::Type::Wallpaper:
|
||||
url += name;
|
||||
if (!mode.empty()) {
|
||||
url += "?mode=";
|
||||
url += mode;
|
||||
}
|
||||
return url;
|
||||
case BackgroundType::Type::Pattern:
|
||||
url += name;
|
||||
url += "?intensity=";
|
||||
url += to_string(type.intensity);
|
||||
url += "&bg_color=";
|
||||
url += get_color_string(type.color);
|
||||
if (!mode.empty()) {
|
||||
url += "&mode=";
|
||||
url += mode;
|
||||
}
|
||||
return url;
|
||||
case BackgroundType::Type::Solid:
|
||||
url += get_color_string(type.color);
|
||||
return url;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
BackgroundManager::Background *BackgroundManager::add_background(BackgroundId background_id) {
|
||||
CHECK(background_id.is_valid());
|
||||
return &backgrounds_[background_id];
|
||||
|
@ -31,6 +31,9 @@ class BackgroundManager : public Actor {
|
||||
|
||||
void get_backgrounds(Promise<Unit> &&promise);
|
||||
|
||||
Result<string> get_background_url(const string &name,
|
||||
td_api::object_ptr<td_api::BackgroundType> background_type) const;
|
||||
|
||||
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;
|
||||
@ -72,6 +75,8 @@ class BackgroundManager : public Actor {
|
||||
|
||||
const Background *get_background(BackgroundId background_id) const;
|
||||
|
||||
static Result<BackgroundType> get_background_type(td_api::object_ptr<td_api::BackgroundType> type);
|
||||
|
||||
static BackgroundType get_background_type(bool is_pattern,
|
||||
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings);
|
||||
|
||||
|
@ -6944,6 +6944,17 @@ void Td::on_request(uint64 id, const td_api::getBackgrounds &request) {
|
||||
CREATE_NO_ARGS_REQUEST(GetBackgroundsRequest);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getBackgroundUrl &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.name_);
|
||||
Result<string> r_url = background_manager_->get_background_url(request.name_, std::move(request.type_));
|
||||
if (r_url.is_error()) {
|
||||
return send_closure(actor_id(this), &Td::send_error, id, r_url.move_as_error());
|
||||
}
|
||||
|
||||
send_closure(actor_id(this), &Td::send_result, id, td_api::make_object<td_api::httpUrl>(r_url.ok()));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.referrer_);
|
||||
|
@ -924,6 +924,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, const td_api::getBackgrounds &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getBackgroundUrl &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setBotUpdatesStatus &request);
|
||||
|
@ -1220,7 +1220,7 @@ class CliClient final : public Actor {
|
||||
}
|
||||
}
|
||||
|
||||
void send_message(const string &chat_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content,
|
||||
void send_message(const string &chat_id, td_api::object_ptr<td_api::InputMessageContent> &&input_message_content,
|
||||
bool disable_notification = false, bool from_background = false, int64 reply_to_message_id = 0) {
|
||||
auto chat = as_chat_id(chat_id);
|
||||
auto id = send_request(td_api::make_object<td_api::sendMessage>(
|
||||
@ -1228,6 +1228,10 @@ class CliClient final : public Actor {
|
||||
query_id_to_send_message_info_[id].start_time = Time::now();
|
||||
}
|
||||
|
||||
void send_get_background_url(td_api::object_ptr<td_api::BackgroundType> &&background_type) {
|
||||
send_request(td_api::make_object<td_api::getBackgroundUrl>("asd", std::move(background_type)));
|
||||
}
|
||||
|
||||
void on_cmd(string cmd) {
|
||||
// TODO: need to remove https://en.wikipedia.org/wiki/ANSI_escape_code from cmd
|
||||
cmd.erase(std::remove_if(cmd.begin(), cmd.end(), [](unsigned char c) { return c < 32; }), cmd.end());
|
||||
@ -1959,8 +1963,23 @@ class CliClient final : public Actor {
|
||||
send_request(td_api::make_object<td_api::disconnectWebsite>(to_integer<int64>(args)));
|
||||
} else if (op == "daw") {
|
||||
send_request(td_api::make_object<td_api::disconnectAllWebsites>());
|
||||
} else if (op == "gb") {
|
||||
} else if (op == "gbgs") {
|
||||
send_request(td_api::make_object<td_api::getBackgrounds>());
|
||||
} else if (op == "gbgu") {
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(false, false));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(false, true));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(true, false));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(true, true));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, -1, 0));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(true, 0x1000000, 0));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, 0, -1));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, 0, 101));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, 0, 0));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(true, 0xFFFFFF, 100));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(true, 0xABCDEF, 49));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeSolid>(-1));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeSolid>(0xABCDEF));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeSolid>(0x1000000));
|
||||
} else if (op == "gccode") {
|
||||
send_request(td_api::make_object<td_api::getCountryCode>());
|
||||
} else if (op == "git") {
|
||||
|
@ -25,7 +25,7 @@ char *str_dup(Slice str) {
|
||||
return res;
|
||||
}
|
||||
|
||||
string implode(vector<string> v, char delimiter) {
|
||||
string implode(const vector<string> &v, char delimiter) {
|
||||
string result;
|
||||
for (auto &str : v) {
|
||||
if (!result.empty()) {
|
||||
|
@ -49,7 +49,7 @@ vector<T> full_split(T s, char delimiter = ' ') {
|
||||
}
|
||||
}
|
||||
|
||||
string implode(vector<string> v, char delimiter = ' ');
|
||||
string implode(const vector<string> &v, char delimiter = ' ');
|
||||
|
||||
namespace detail {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user