Add td_api::getTimeZones.
This commit is contained in:
parent
552e6ba35a
commit
ab1b7cf20f
@ -5021,6 +5021,16 @@ themeSettings accent_color:int32 background:background outgoing_message_fill:Bac
|
|||||||
chatTheme name:string light_settings:themeSettings dark_settings:themeSettings = ChatTheme;
|
chatTheme name:string light_settings:themeSettings dark_settings:themeSettings = ChatTheme;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Describes a time zone
|
||||||
|
//@id Unique time zone identifier
|
||||||
|
//@name Time zone name
|
||||||
|
//@utc_time_offset Current UTC time offset for the time zone
|
||||||
|
timeZone id:string name:string utc_time_offset:int32 = TimeZone;
|
||||||
|
|
||||||
|
//@description Contains a list of time zones @time_zones A list of time zones
|
||||||
|
timeZones time_zones:vector<timeZone> = TimeZones;
|
||||||
|
|
||||||
|
|
||||||
//@description Contains a list of hashtags @hashtags A list of hashtags
|
//@description Contains a list of hashtags @hashtags A list of hashtags
|
||||||
hashtags hashtags:vector<string> = Hashtags;
|
hashtags hashtags:vector<string> = Hashtags;
|
||||||
|
|
||||||
@ -9468,6 +9478,10 @@ closeSecretChat secret_chat_id:int32 = Ok;
|
|||||||
getChatEventLog chat_id:int53 query:string from_event_id:int64 limit:int32 filters:chatEventLogFilters user_ids:vector<int53> = ChatEvents;
|
getChatEventLog chat_id:int53 query:string from_event_id:int64 limit:int32 filters:chatEventLogFilters user_ids:vector<int53> = ChatEvents;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Returns the list of supported time zones
|
||||||
|
getTimeZones = TimeZones;
|
||||||
|
|
||||||
|
|
||||||
//@description Returns an invoice payment form. This method must be called when the user presses inline button of the type inlineKeyboardButtonTypeBuy
|
//@description Returns an invoice payment form. This method must be called when the user presses inline button of the type inlineKeyboardButtonTypeBuy
|
||||||
//@input_invoice The invoice
|
//@input_invoice The invoice
|
||||||
//@theme Preferred payment form theme; pass null to use the default theme
|
//@theme Preferred payment form theme; pass null to use the default theme
|
||||||
|
@ -7141,6 +7141,11 @@ void Td::on_request(uint64 id, td_api::getChatEventLog &request) {
|
|||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::getTimeZones &request) {
|
||||||
|
CREATE_REQUEST_PROMISE();
|
||||||
|
time_zone_manager_->get_time_zones(std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::clearAllDraftMessages &request) {
|
void Td::on_request(uint64 id, const td_api::clearAllDraftMessages &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
|
@ -1225,6 +1225,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, td_api::getChatEventLog &request);
|
void on_request(uint64 id, td_api::getChatEventLog &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::getTimeZones &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::clearAllDraftMessages &request);
|
void on_request(uint64 id, const td_api::clearAllDraftMessages &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::downloadFile &request);
|
void on_request(uint64 id, const td_api::downloadFile &request);
|
||||||
|
@ -6,13 +6,125 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/TimeZoneManager.h"
|
#include "td/telegram/TimeZoneManager.h"
|
||||||
|
|
||||||
|
#include "td/telegram/Global.h"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
|
#include "td/utils/algorithm.h"
|
||||||
|
#include "td/utils/buffer.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
class GetTimezonesListQuery final : public Td::ResultHandler {
|
||||||
|
Promise<telegram_api::object_ptr<telegram_api::help_TimezonesList>> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetTimezonesListQuery(Promise<telegram_api::object_ptr<telegram_api::help_TimezonesList>> &&promise)
|
||||||
|
: promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(int32 hash) {
|
||||||
|
send_query(G()->net_query_creator().create(telegram_api::help_getTimezonesList(hash)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::help_getTimezonesList>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
promise_.set_value(result_ptr.move_as_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
if (!G()->is_expected_error(status)) {
|
||||||
|
LOG(ERROR) << "GetTimezonesListQuery returned " << status;
|
||||||
|
}
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TimeZoneManager::TimeZone::TimeZone(string &&id, string &&name, int32 utc_offset)
|
||||||
|
: id_(std::move(id)), name_(std::move(name)), utc_offset_(utc_offset) {
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::timeZone> TimeZoneManager::TimeZone::get_time_zone_object() const {
|
||||||
|
return td_api::make_object<td_api::timeZone>(id_, name_, utc_offset_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const TimeZoneManager::TimeZone &lhs, const TimeZoneManager::TimeZone &rhs) {
|
||||||
|
return lhs.id_ == rhs.id_ && lhs.name_ == rhs.name_ && lhs.utc_offset_ == rhs.utc_offset_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const TimeZoneManager::TimeZone &lhs, const TimeZoneManager::TimeZone &rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::timeZones> TimeZoneManager::TimeZoneList::get_time_zones_object() const {
|
||||||
|
return td_api::make_object<td_api::timeZones>(
|
||||||
|
transform(time_zones_, [](const TimeZone &time_zone) { return time_zone.get_time_zone_object(); }));
|
||||||
|
}
|
||||||
|
|
||||||
TimeZoneManager::TimeZoneManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
TimeZoneManager::TimeZoneManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TimeZoneManager::~TimeZoneManager() = default;
|
||||||
|
|
||||||
void TimeZoneManager::tear_down() {
|
void TimeZoneManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimeZoneManager::get_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise) {
|
||||||
|
if (time_zones_.hash_ != 0) {
|
||||||
|
return promise.set_value(time_zones_.get_time_zones_object());
|
||||||
|
}
|
||||||
|
reload_time_zones(std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeZoneManager::reload_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise) {
|
||||||
|
get_time_zones_queries_.push_back(std::move(promise));
|
||||||
|
if (get_time_zones_queries_.size() == 1) {
|
||||||
|
auto query_promise = PromiseCreator::lambda(
|
||||||
|
[actor_id = actor_id(this)](Result<telegram_api::object_ptr<telegram_api::help_TimezonesList>> &&r_time_zones) {
|
||||||
|
send_closure(actor_id, &TimeZoneManager::on_get_time_zones, std::move(r_time_zones));
|
||||||
|
});
|
||||||
|
td_->create_handler<GetTimezonesListQuery>(std::move(query_promise))->send(time_zones_.hash_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeZoneManager::on_get_time_zones(
|
||||||
|
Result<telegram_api::object_ptr<telegram_api::help_TimezonesList>> &&r_time_zones) {
|
||||||
|
G()->ignore_result_if_closing(r_time_zones);
|
||||||
|
if (r_time_zones.is_error()) {
|
||||||
|
return fail_promises(get_time_zones_queries_, r_time_zones.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto time_zones_ptr = r_time_zones.move_as_ok();
|
||||||
|
switch (time_zones_ptr->get_id()) {
|
||||||
|
case telegram_api::help_timezonesListNotModified::ID:
|
||||||
|
break;
|
||||||
|
case telegram_api::help_timezonesList::ID: {
|
||||||
|
auto zone_list = telegram_api::move_object_as<telegram_api::help_timezonesList>(time_zones_ptr);
|
||||||
|
vector<TimeZone> time_zones;
|
||||||
|
for (auto &time_zone : zone_list->timezones_) {
|
||||||
|
time_zones.emplace_back(std::move(time_zone->id_), std::move(time_zone->name_), time_zone->utc_offset_);
|
||||||
|
}
|
||||||
|
if (time_zones_.time_zones_ != time_zones || time_zones_.hash_ != zone_list->hash_) {
|
||||||
|
time_zones_.time_zones_ = std::move(time_zones);
|
||||||
|
time_zones_.hash_ = zone_list->hash_;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
auto promises = std::move(get_time_zones_queries_);
|
||||||
|
reset_to_empty(get_time_zones_queries_);
|
||||||
|
for (auto &promise : promises) {
|
||||||
|
if (promise) {
|
||||||
|
promise.set_value(time_zones_.get_time_zones_object());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -6,9 +6,13 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/td_api.h"
|
||||||
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
#include "td/actor/actor.h"
|
#include "td/actor/actor.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/Promise.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -17,10 +21,47 @@ class Td;
|
|||||||
class TimeZoneManager final : public Actor {
|
class TimeZoneManager final : public Actor {
|
||||||
public:
|
public:
|
||||||
TimeZoneManager(Td *td, ActorShared<> parent);
|
TimeZoneManager(Td *td, ActorShared<> parent);
|
||||||
|
TimeZoneManager(const TimeZoneManager &) = delete;
|
||||||
|
TimeZoneManager &operator=(const TimeZoneManager &) = delete;
|
||||||
|
TimeZoneManager(TimeZoneManager &&) = delete;
|
||||||
|
TimeZoneManager &operator=(TimeZoneManager &&) = delete;
|
||||||
|
~TimeZoneManager() final;
|
||||||
|
|
||||||
|
void get_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise);
|
||||||
|
|
||||||
|
void reload_time_zones(Promise<td_api::object_ptr<td_api::timeZones>> &&promise);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void tear_down() final;
|
void tear_down() final;
|
||||||
|
|
||||||
|
struct TimeZone {
|
||||||
|
string id_;
|
||||||
|
string name_;
|
||||||
|
int32 utc_offset_ = 0;
|
||||||
|
|
||||||
|
TimeZone() = default;
|
||||||
|
TimeZone(string &&id, string &&name, int32 utc_offset);
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::timeZone> get_time_zone_object() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TimeZoneList {
|
||||||
|
vector<TimeZone> time_zones_;
|
||||||
|
int32 hash_ = 0;
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::timeZones> get_time_zones_object() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
friend bool operator==(const TimeZone &lhs, const TimeZone &rhs);
|
||||||
|
|
||||||
|
friend bool operator!=(const TimeZone &lhs, const TimeZone &rhs);
|
||||||
|
|
||||||
|
void on_get_time_zones(Result<telegram_api::object_ptr<telegram_api::help_TimezonesList>> &&r_time_zones);
|
||||||
|
|
||||||
|
vector<Promise<td_api::object_ptr<td_api::timeZones>>> get_time_zones_queries_;
|
||||||
|
|
||||||
|
TimeZoneList time_zones_;
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
};
|
};
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
#include "td/telegram/telegram_api.hpp"
|
#include "td/telegram/telegram_api.hpp"
|
||||||
#include "td/telegram/ThemeManager.h"
|
#include "td/telegram/ThemeManager.h"
|
||||||
|
#include "td/telegram/TimeZoneManager.h"
|
||||||
#include "td/telegram/TranscriptionManager.h"
|
#include "td/telegram/TranscriptionManager.h"
|
||||||
#include "td/telegram/Usernames.h"
|
#include "td/telegram/Usernames.h"
|
||||||
#include "td/telegram/WebPagesManager.h"
|
#include "td/telegram/WebPagesManager.h"
|
||||||
@ -2298,6 +2299,7 @@ void UpdatesManager::try_reload_data() {
|
|||||||
td_->theme_manager_->reload_accent_colors();
|
td_->theme_manager_->reload_accent_colors();
|
||||||
td_->theme_manager_->reload_chat_themes();
|
td_->theme_manager_->reload_chat_themes();
|
||||||
td_->theme_manager_->reload_profile_accent_colors();
|
td_->theme_manager_->reload_profile_accent_colors();
|
||||||
|
td_->time_zone_manager_->reload_time_zones(Auto());
|
||||||
|
|
||||||
schedule_data_reload();
|
schedule_data_reload();
|
||||||
}
|
}
|
||||||
|
@ -5676,6 +5676,8 @@ class CliClient final : public Actor {
|
|||||||
} else if (op == "logf") {
|
} else if (op == "logf") {
|
||||||
get_log_chat_id_ = as_chat_id(args);
|
get_log_chat_id_ = as_chat_id(args);
|
||||||
send_request(td_api::make_object<td_api::getChatEventLog>(get_log_chat_id_, "", 0, 100, nullptr, Auto()));
|
send_request(td_api::make_object<td_api::getChatEventLog>(get_log_chat_id_, "", 0, 100, nullptr, Auto()));
|
||||||
|
} else if (op == "gtz") {
|
||||||
|
send_request(td_api::make_object<td_api::getTimeZones>());
|
||||||
} else if (op == "join") {
|
} else if (op == "join") {
|
||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
get_args(args, chat_id);
|
get_args(args, chat_id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user