Support auto-download settings.
GitOrigin-RevId: f1c41293278fc565777311b0452acdfabb6fdcd9
This commit is contained in:
parent
4f9887b4bd
commit
784aaa13d4
@ -354,6 +354,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/AnimationsManager.cpp
|
||||
td/telegram/AudiosManager.cpp
|
||||
td/telegram/AuthManager.cpp
|
||||
td/telegram/AutoDownloadSettings.cpp
|
||||
td/telegram/BackgroundManager.cpp
|
||||
td/telegram/BackgroundType.cpp
|
||||
td/telegram/CallActor.cpp
|
||||
@ -484,6 +485,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/AnimationsManager.h
|
||||
td/telegram/AudiosManager.h
|
||||
td/telegram/AuthManager.h
|
||||
td/telegram/AutoDownloadSettings.h
|
||||
td/telegram/BackgroundId.h
|
||||
td/telegram/BackgroundManager.h
|
||||
td/telegram/BackgroundType.h
|
||||
|
@ -2373,9 +2373,26 @@ networkStatisticsEntryCall network_type:NetworkType sent_bytes:int53 received_by
|
||||
networkStatistics since_date:int32 entries:vector<NetworkStatisticsEntry> = NetworkStatistics;
|
||||
|
||||
|
||||
//@description Contains auto-download settings
|
||||
//@is_auto_download_enabled True, if the auto-download is enabled
|
||||
//@max_photo_file_size Maximum size of a photo file to be auto-downloaded
|
||||
//@max_video_file_size Maximum size of a video file to be auto-downloaded
|
||||
//@max_other_file_size Maximum size of other file types to be auto-downloaded
|
||||
//@preload_large_videos True, if the beginning of videos needs to be preloaded for instant playback
|
||||
//@preload_next_audio True, if the next audio track needs to be preloaded while the user is listening to an audio file
|
||||
//@use_less_data_for_calls True, if "use less data for calls" option needs to be enabled
|
||||
autoDownloadSettings is_auto_download_enabled:Bool max_photo_file_size:int32 max_video_file_size:int32 max_other_file_size:int32 preload_large_videos:Bool preload_next_audio:Bool use_less_data_for_calls:Bool = AutoDownloadSettings;
|
||||
|
||||
//@description Contains preset auto-download settings for the user
|
||||
//@low Preset with lowest settings; supposed to be used by default when roaming
|
||||
//@medium Preset with medium settings; supposed to be used by default when using mobile data
|
||||
//@high Preset with highest settings; supposed to be used by default when connected on Wi-Fi
|
||||
autoDownloadSettingsPresets low:autoDownloadSettings medium:autoDownloadSettings high:autoDownloadSettings = AutoDownloadSettingsPresets;
|
||||
|
||||
|
||||
//@class ConnectionState @description Describes the current state of the connection to Telegram servers
|
||||
|
||||
//@description Currently waiting for the network to become available. Use SetNetworkType to change the available network type
|
||||
//@description Currently waiting for the network to become available. Use setNetworkType to change the available network type
|
||||
connectionStateWaitingForNetwork = ConnectionState;
|
||||
|
||||
//@description Currently establishing a connection with a proxy server
|
||||
@ -3755,6 +3772,12 @@ addNetworkStatistics entry:NetworkStatisticsEntry = Ok;
|
||||
//@description Resets all network data usage statistics to zero. Can be called before authorization
|
||||
resetNetworkStatistics = Ok;
|
||||
|
||||
//@description Returns auto-download settings presets for the currently logged in user
|
||||
getAutoDownloadSettingsPresets = AutoDownloadSettingsPresets;
|
||||
|
||||
//@description Sets auto-download settings @settings New user auto-download settings @type Type of the network for which the new settings are applied
|
||||
setAutoDownloadSettings settings:autoDownloadSettings type:NetworkType = Ok;
|
||||
|
||||
|
||||
//@description Returns one of the available Telegram Passport elements @type Telegram Passport element type @password Password of the current user
|
||||
getPassportElement type:PassportElementType password:string = PassportElement;
|
||||
|
Binary file not shown.
136
td/telegram/AutoDownloadSettings.cpp
Normal file
136
td/telegram/AutoDownloadSettings.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
//
|
||||
// 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/AutoDownloadSettings.h"
|
||||
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/net/NetQueryCreator.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/utils/logging.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
static td_api::object_ptr<td_api::autoDownloadSettings> convert_auto_download_settings(
|
||||
const telegram_api::object_ptr<telegram_api::autoDownloadSettings> &settings) {
|
||||
CHECK(settings != nullptr);
|
||||
auto flags = settings->flags_;
|
||||
auto disabled = (flags & telegram_api::autoDownloadSettings::DISABLED_MASK) != 0;
|
||||
auto video_preload_large = (flags & telegram_api::autoDownloadSettings::VIDEO_PRELOAD_LARGE_MASK) != 0;
|
||||
auto audio_preload_next = (flags & telegram_api::autoDownloadSettings::AUDIO_PRELOAD_NEXT_MASK) != 0;
|
||||
auto phonecalls_less_data = (flags & telegram_api::autoDownloadSettings::PHONECALLS_LESS_DATA_MASK) != 0;
|
||||
return td_api::make_object<td_api::autoDownloadSettings>(
|
||||
!disabled, settings->photo_size_max_, settings->video_size_max_, settings->file_size_max_, video_preload_large,
|
||||
audio_preload_next, phonecalls_less_data);
|
||||
}
|
||||
|
||||
class GetAutoDownloadSettingsQuery : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::autoDownloadSettingsPresets>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetAutoDownloadSettingsQuery(Promise<td_api::object_ptr<td_api::autoDownloadSettingsPresets>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send() {
|
||||
send_query(G()->net_query_creator().create(create_storer(telegram_api::account_getAutoDownloadSettings())));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) override {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getAutoDownloadSettings>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto settings = result_ptr.move_as_ok();
|
||||
promise_.set_value(td_api::make_object<td_api::autoDownloadSettingsPresets>(
|
||||
convert_auto_download_settings(settings->low_), convert_auto_download_settings(settings->medium_),
|
||||
convert_auto_download_settings(settings->high_)));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
telegram_api::object_ptr<telegram_api::autoDownloadSettings> get_input_auto_download_settings(
|
||||
const AutoDownloadSettings &settings) {
|
||||
int32 flags = 0;
|
||||
if (!settings.is_enabled) {
|
||||
flags |= telegram_api::autoDownloadSettings::DISABLED_MASK;
|
||||
}
|
||||
if (settings.preload_large_videos) {
|
||||
flags |= telegram_api::autoDownloadSettings::VIDEO_PRELOAD_LARGE_MASK;
|
||||
}
|
||||
if (settings.preload_next_audio) {
|
||||
flags |= telegram_api::autoDownloadSettings::AUDIO_PRELOAD_NEXT_MASK;
|
||||
}
|
||||
if (settings.use_less_data_for_calls) {
|
||||
flags |= telegram_api::autoDownloadSettings::PHONECALLS_LESS_DATA_MASK;
|
||||
}
|
||||
return telegram_api::make_object<telegram_api::autoDownloadSettings>(
|
||||
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, settings.max_photo_file_size,
|
||||
settings.max_video_file_size, settings.max_other_file_size);
|
||||
}
|
||||
|
||||
class SaveAutoDownloadSettingsQuery : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SaveAutoDownloadSettingsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(NetType type, const AutoDownloadSettings &settings) {
|
||||
int32 flags = 0;
|
||||
if (type == NetType::MobileRoaming) {
|
||||
flags |= telegram_api::account_saveAutoDownloadSettings::LOW_MASK;
|
||||
}
|
||||
if (type == NetType::WiFi) {
|
||||
flags |= telegram_api::account_saveAutoDownloadSettings::HIGH_MASK;
|
||||
}
|
||||
send_query(G()->net_query_creator().create(create_storer(telegram_api::account_saveAutoDownloadSettings(
|
||||
flags, false /*ignored*/, false /*ignored*/, get_input_auto_download_settings(settings)))));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) override {
|
||||
auto result_ptr = fetch_result<telegram_api::account_saveAutoDownloadSettings>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG(INFO) << "SaveAutoDownloadSettingsQuery returned " << result_ptr.ok();
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
AutoDownloadSettings get_auto_download_settings(const td_api::object_ptr<td_api::autoDownloadSettings> &settings) {
|
||||
CHECK(settings != nullptr);
|
||||
AutoDownloadSettings result;
|
||||
result.max_photo_file_size = settings->max_photo_file_size_;
|
||||
result.max_video_file_size = settings->max_video_file_size_;
|
||||
result.max_other_file_size = settings->max_other_file_size_;
|
||||
result.is_enabled = settings->is_auto_download_enabled_;
|
||||
result.preload_large_videos = settings->preload_large_videos_;
|
||||
result.preload_next_audio = settings->preload_next_audio_;
|
||||
result.use_less_data_for_calls = settings->use_less_data_for_calls_;
|
||||
return result;
|
||||
}
|
||||
|
||||
void get_auto_download_settings_presets(Td *td,
|
||||
Promise<td_api::object_ptr<td_api::autoDownloadSettingsPresets>> &&promise) {
|
||||
td->create_handler<GetAutoDownloadSettingsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void set_auto_download_settings(Td *td, NetType type, AutoDownloadSettings settings, Promise<Unit> &&promise) {
|
||||
td->create_handler<SaveAutoDownloadSettingsQuery>(std::move(promise))->send(type, settings);
|
||||
}
|
||||
|
||||
} // namespace td
|
38
td/telegram/AutoDownloadSettings.h
Normal file
38
td/telegram/AutoDownloadSettings.h
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// 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/net/NetType.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class Td;
|
||||
|
||||
class AutoDownloadSettings {
|
||||
public:
|
||||
int32 max_photo_file_size = 0;
|
||||
int32 max_video_file_size = 0;
|
||||
int32 max_other_file_size = 0;
|
||||
bool is_enabled = false;
|
||||
bool preload_large_videos = false;
|
||||
bool preload_next_audio = false;
|
||||
bool use_less_data_for_calls = false;
|
||||
};
|
||||
|
||||
AutoDownloadSettings get_auto_download_settings(const td_api::object_ptr<td_api::autoDownloadSettings> &settings);
|
||||
|
||||
void get_auto_download_settings_presets(Td *td,
|
||||
Promise<td_api::object_ptr<td_api::autoDownloadSettingsPresets>> &&promise);
|
||||
|
||||
void set_auto_download_settings(Td *td, NetType type, AutoDownloadSettings settings, Promise<Unit> &&promise);
|
||||
|
||||
} // namespace td
|
@ -10,6 +10,7 @@
|
||||
#include "td/telegram/AnimationsManager.h"
|
||||
#include "td/telegram/AudiosManager.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/AutoDownloadSettings.h"
|
||||
#include "td/telegram/BackgroundManager.h"
|
||||
#include "td/telegram/CallbackQueriesManager.h"
|
||||
#include "td/telegram/CallId.h"
|
||||
@ -5182,12 +5183,28 @@ void Td::on_request(uint64 id, td_api::addNetworkStatistics &request) {
|
||||
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setNetworkType &request) {
|
||||
void Td::on_request(uint64 id, const td_api::setNetworkType &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
send_closure(state_manager_, &StateManager::on_network, from_td_api(request.type_));
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getAutoDownloadSettingsPresets &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
get_auto_download_settings_presets(this, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::setAutoDownloadSettings &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
if (request.settings_ == nullptr) {
|
||||
return send_error_raw(id, 400, "New settings must be non-empty");
|
||||
}
|
||||
set_auto_download_settings(this, from_td_api(request.type_), get_auto_download_settings(request.settings_),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getTopChats &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
|
@ -490,7 +490,11 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, td_api::addNetworkStatistics &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setNetworkType &request);
|
||||
void on_request(uint64 id, const td_api::setNetworkType &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getAutoDownloadSettingsPresets &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::setAutoDownloadSettings &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getTopChats &request);
|
||||
|
||||
|
@ -2114,6 +2114,11 @@ class CliClient final : public Actor {
|
||||
send_request(td_api::make_object<td_api::resetNetworkStatistics>());
|
||||
} else if (op == "snt") {
|
||||
send_request(td_api::make_object<td_api::setNetworkType>(get_network_type(args)));
|
||||
} else if (op == "gadsp") {
|
||||
send_request(td_api::make_object<td_api::getAutoDownloadSettingsPresets>());
|
||||
} else if (op == "sads") {
|
||||
send_request(td_api::make_object<td_api::setAutoDownloadSettings>(
|
||||
td_api::make_object<td_api::autoDownloadSettings>(), get_network_type(args)));
|
||||
} else if (op == "ansc") {
|
||||
string sent_bytes;
|
||||
string received_bytes;
|
||||
|
@ -88,7 +88,7 @@ class NetStatsManager : public Actor {
|
||||
switch (type) {
|
||||
case NetType::Other:
|
||||
return CSlice("other");
|
||||
case NetType::Wifi:
|
||||
case NetType::WiFi:
|
||||
return CSlice("wifi");
|
||||
case NetType::Mobile:
|
||||
return CSlice("mobile");
|
||||
|
@ -12,9 +12,9 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
enum class NetType : int8 { Other, Wifi, Mobile, MobileRoaming, Size, None, Unknown };
|
||||
enum class NetType : int8 { Other, WiFi, Mobile, MobileRoaming, Size, None, Unknown };
|
||||
|
||||
inline NetType from_td_api(tl_object_ptr<td_api::NetworkType> &net_type) {
|
||||
inline NetType from_td_api(const tl_object_ptr<td_api::NetworkType> &net_type) {
|
||||
if (net_type == nullptr) {
|
||||
return NetType::Other;
|
||||
}
|
||||
@ -23,7 +23,7 @@ inline NetType from_td_api(tl_object_ptr<td_api::NetworkType> &net_type) {
|
||||
case td_api::networkTypeOther::ID:
|
||||
return NetType::Other;
|
||||
case td_api::networkTypeWiFi::ID:
|
||||
return NetType::Wifi;
|
||||
return NetType::WiFi;
|
||||
case td_api::networkTypeMobile::ID:
|
||||
return NetType::Mobile;
|
||||
case td_api::networkTypeMobileRoaming::ID:
|
||||
@ -39,7 +39,7 @@ inline tl_object_ptr<td_api::NetworkType> as_td_api(NetType net_type) {
|
||||
switch (net_type) {
|
||||
case NetType::Other:
|
||||
return make_tl_object<td_api::networkTypeOther>();
|
||||
case NetType::Wifi:
|
||||
case NetType::WiFi:
|
||||
return make_tl_object<td_api::networkTypeWiFi>();
|
||||
case NetType::Mobile:
|
||||
return make_tl_object<td_api::networkTypeMobile>();
|
||||
|
Reference in New Issue
Block a user