Merge remote-tracking branch 'td/master'

This commit is contained in:
Andrea Cavalli 2022-06-29 23:33:12 +02:00
commit 377050ced3
137 changed files with 982 additions and 825 deletions

View File

@ -12,6 +12,7 @@
#include "td/utils/common.h"
#include "td/utils/crypto.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/SliceBuilder.h"
#if TD_MSVC

View File

@ -16,12 +16,12 @@
#include "td/db/SqliteDb.h"
#include "td/actor/ConcurrentScheduler.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/benchmark.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Random.h"
#include "td/utils/Status.h"

View File

@ -9,10 +9,10 @@
#include "td/actor/actor.h"
#include "td/actor/ConcurrentScheduler.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
int main(int argc, char *argv[]) {

View File

@ -989,7 +989,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int53 = ChatType;
//@description Represents a filter of user chats
//@title The title of the filter; 1-12 characters without line feeds
//@icon_name The chosen icon name for short filter representation. If non-empty, must be one of "All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom", "Setup", "Cat", "Crown", "Favorite", "Flower", "Game", "Home", "Love", "Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work".
//@icon_name The chosen icon name for short filter representation. If non-empty, must be one of "All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom", "Setup", "Cat", "Crown", "Favorite", "Flower", "Game", "Home", "Love", "Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work", "Airplane", "Book", "Light", "Like", "Money", "Note", "Palette".
//-If empty, use getChatFilterDefaultIconName to get default icon name for the filter
//@pinned_chat_ids The chat identifiers of pinned chats in the filtered chat list. There can be up to GetOption("chat_filter_chosen_chat_count_max") pinned and always included non-secret chats and the same number of secret chats, but the limit can be increased with Telegram Premium
//@included_chat_ids The chat identifiers of always included chats in the filtered chat list. There can be up to GetOption("chat_filter_chosen_chat_count_max") pinned and always included non-secret chats and the same number of secret chats, but the limit can be increased with Telegram Premium
@ -1007,7 +1007,7 @@ chatFilter title:string icon_name:string pinned_chat_ids:vector<int53> included_
//@description Contains basic information about a chat filter
//@id Unique chat filter identifier
//@title The title of the filter; 1-12 characters without line feeds
//@icon_name The chosen or default icon name for short filter representation. One of "All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom", "Setup", "Cat", "Crown", "Favorite", "Flower", "Game", "Home", "Love", "Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work"
//@icon_name The chosen or default icon name for short filter representation. One of "All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom", "Setup", "Cat", "Crown", "Favorite", "Flower", "Game", "Home", "Love", "Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work", "Airplane", "Book", "Light", "Like", "Money", "Note", "Palette"
chatFilterInfo id:int32 title:string icon_name:string = ChatFilterInfo;
//@description Describes a recommended chat filter @filter The chat filter @param_description Chat filter description
@ -6428,6 +6428,15 @@ clickPremiumSubscriptionButton = Ok;
//@description Returns state of Telegram Premium subscription and promotion videos for Premium features
getPremiumState = PremiumState;
//@description Checks whether Telegram Premium purchase is possible. Must be called before in-store Premium purchase
canPurchasePremium = Ok;
//@description Informs server about a Telegram Premium purchase through App Store. For official applications only @receipt App Store receipt @is_restore Pass true if this is a restore of a Telegram Premium purchase
assignAppStoreTransaction receipt:bytes is_restore:Bool = Ok;
//@description Informs server about a Telegram Premium purchase through Google Play. For official applications only @purchase_token Google Play purchase token
assignGooglePlayTransaction purchase_token:string = Ok;
//@description Accepts Telegram terms of services @terms_of_service_id Terms of service identifier
acceptTermsOfService terms_of_service_id:string = Ok;

View File

@ -11,8 +11,8 @@
#include "td/mtproto/RawConnection.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -10,9 +10,6 @@
#include "td/mtproto/PingConnection.h"
#include "td/mtproto/RawConnection.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"

View File

@ -10,9 +10,9 @@
#include "td/mtproto/RawConnection.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
namespace td {

View File

@ -9,9 +9,8 @@
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/td_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -28,8 +28,6 @@
#include "td/db/SqliteKeyValueAsync.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"

View File

@ -15,11 +15,11 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -9,9 +9,8 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/telegram_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -14,11 +14,11 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -28,12 +28,11 @@
#include "td/telegram/TopDialogManager.h"
#include "td/telegram/UpdatesManager.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/base64.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Promise.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/Slice.h"
#include "td/utils/Time.h"
@ -77,8 +76,11 @@ void AuthManager::start_up() {
if (state_ == State::LoggingOut) {
send_log_out_query();
} else if (state_ == State::DestroyingKeys) {
G()->net_query_dispatcher().destroy_auth_keys(
PromiseCreator::lambda([](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore()));
G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda([](Result<Unit> result) {
if (result.is_ok()) {
send_closure_later(G()->td(), &Td::destroy);
}
}));
}
}
void AuthManager::tear_down() {
@ -706,12 +708,15 @@ void AuthManager::destroy_auth_keys() {
return;
}
update_state(State::DestroyingKeys);
auto promise = PromiseCreator::lambda(
[](Unit) {
G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda(
[](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore()));
},
PromiseCreator::Ignore());
auto promise = PromiseCreator::lambda([](Result<Unit> result) {
if (result.is_ok()) {
G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda([](Result<Unit> result) {
if (result.is_ok()) {
send_closure_later(G()->td(), &Td::destroy);
}
}));
}
});
G()->td_db()->get_binlog_pmc()->set("auth", "destroy");
G()->td_db()->get_binlog_pmc()->force_sync(std::move(promise));
}

View File

@ -9,9 +9,8 @@
#include "td/telegram/net/NetType.h"
#include "td/telegram/td_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -15,11 +15,11 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <memory>

View File

@ -10,9 +10,8 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/tl_helpers.h"
namespace td {

View File

@ -10,9 +10,8 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/tl_helpers.h"
namespace td {

View File

@ -18,10 +18,10 @@
#include "td/mtproto/DhHandshake.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Container.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <memory>

View File

@ -12,10 +12,10 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <map>

View File

@ -18,7 +18,6 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"

View File

@ -13,10 +13,9 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -14,11 +14,11 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FloodControlStrict.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/Time.h"

View File

@ -56,7 +56,6 @@
#include "td/db/SqliteKeyValue.h"
#include "td/db/SqliteKeyValueAsync.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/SleepActor.h"
#include "td/utils/algorithm.h"

View File

@ -39,13 +39,13 @@
#include "td/actor/actor.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Hints.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/Time.h"

View File

@ -10,10 +10,10 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

View File

@ -16,6 +16,8 @@
#include "td/mtproto/DhHandshake.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/base64.h"
#include "td/utils/buffer.h"
@ -364,7 +366,7 @@ void DeviceTokenManager::save_info(int32 token_type) {
}
sync_cnt_++;
G()->td_db()->get_binlog_pmc()->force_sync(
PromiseCreator::event(self_closure(this, &DeviceTokenManager::dec_sync_cnt)));
create_event_promise(self_closure(this, &DeviceTokenManager::dec_sync_cnt)));
}
void DeviceTokenManager::dec_sync_cnt() {

View File

@ -11,9 +11,9 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/StringBuilder.h"

View File

@ -443,12 +443,12 @@ class DialogDbAsync final : public DialogDbAsyncInterface {
//NB: order is important, destructor of pending_writes_ will change pending_write_results_
std::vector<std::pair<Promise<>, Status>> pending_write_results_;
vector<Promise<>> pending_writes_;
vector<Promise<>> pending_writes_; // TODO use Action
double wakeup_at_ = 0;
template <class F>
void add_write_query(F &&f) {
pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f), PromiseCreator::Ignore()));
pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f)));
if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) {
do_flush();
wakeup_at_ = 0;

View File

@ -13,10 +13,9 @@
#include "td/db/KeyValueSyncInterface.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <memory>

View File

@ -10,9 +10,8 @@
#include "td/telegram/td_api.h"
#include "td/telegram/UserId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -448,15 +448,20 @@ void DialogFilter::init_icon_names() {
"\xF0\x9F\x8C\xB9", "\xF0\x9F\x8E\xAE", "\xF0\x9F\x8F\xA0",
"\xE2\x9D\xA4\xEF\xB8\x8F", "\xF0\x9F\x8E\xAD", "\xF0\x9F\x8D\xB8",
"\xE2\x9A\xBD\xEF\xB8\x8F", "\xF0\x9F\x8E\x93", "\xF0\x9F\x93\x88",
"\xE2\x9C\x88\xEF\xB8\x8F", "\xF0\x9F\x92\xBC"};
"\xE2\x9C\x88\xEF\xB8\x8F", "\xF0\x9F\x92\xBC", "\xF0\x9F\x9B\xAB",
"\xF0\x9F\x93\x95", "\xF0\x9F\x92\xA1", "\xF0\x9F\x91\x8D",
"\xF0\x9F\x92\xB0", "\xF0\x9F\x8E\xB5", "\xF0\x9F\x8E\xA8"};
vector<string> icon_names{"All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom",
"Setup", "Cat", "Crown", "Favorite", "Flower", "Game", "Home", "Love",
"Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work"};
"Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work", "Airplane",
"Book", "Light", "Like", "Money", "Note", "Palette"};
CHECK(emojis.size() == icon_names.size());
for (size_t i = 0; i < emojis.size(); i++) {
remove_emoji_modifiers_in_place(emojis[i]);
emoji_to_icon_name_[emojis[i]] = icon_names[i];
icon_name_to_emoji_[icon_names[i]] = emojis[i];
bool is_inserted = emoji_to_icon_name_.emplace(emojis[i], icon_names[i]).second &&
icon_name_to_emoji_.emplace(icon_names[i], emojis[i]).second;
CHECK(is_inserted);
}
return true;
}();

View File

@ -15,6 +15,7 @@
#include "td/telegram/TdParameters.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/FlatHashMap.h"

View File

@ -12,9 +12,9 @@
#include "td/telegram/td_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -11,9 +11,9 @@
#include "td/telegram/Td.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -18,11 +18,11 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/Variant.h"

View File

@ -12,9 +12,9 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -14,8 +14,6 @@
#include "td/telegram/StateManager.h"
#include "td/telegram/TdDb.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"

View File

@ -15,12 +15,12 @@
#include "td/net/NetStats.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/SchedulerLocalStorage.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/Time.h"

View File

@ -17,11 +17,11 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <utility>

View File

@ -7,10 +7,10 @@
#pragma once
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Hints.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -350,7 +350,7 @@ Result<tl_object_ptr<telegram_api::InputBotInlineMessage>> InlineQueriesManager:
return Status::Error(400, "Inline message can't be empty");
}
TRY_RESULT(reply_markup, get_reply_markup(std::move(reply_markup_ptr), true, true, false, true));
auto input_reply_markup = get_input_reply_markup(reply_markup);
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), reply_markup);
auto constructor_id = input_message_content->get_id();
if (constructor_id == td_api::inputMessageText::ID) {
@ -695,7 +695,7 @@ Result<tl_object_ptr<telegram_api::InputBotInlineResult>> InlineQueriesManager::
return r_reply_markup.move_as_error();
}
auto input_reply_markup = get_input_reply_markup(r_reply_markup.ok());
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), r_reply_markup.ok());
int32 flags = 0;
if (input_reply_markup != nullptr) {
flags |= telegram_api::inputBotInlineMessageGame::REPLY_MARKUP_MASK;

View File

@ -19,11 +19,11 @@
#include "td/actor/actor.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <utility>

View File

@ -11,11 +11,11 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Container.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

View File

@ -12,9 +12,9 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

View File

@ -76,7 +76,6 @@
#include "td/actor/actor.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/emoji.h"

View File

@ -26,10 +26,9 @@
#include "td/telegram/UserId.h"
#include "td/telegram/WebPageId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <utility>

View File

@ -1390,12 +1390,12 @@ static void sort_entities(vector<MessageEntity> &entities) {
std::sort(entities.begin(), entities.end());
}
#define check_is_sorted(entities) check_is_sorted_impl(entities, __LINE__)
#define check_is_sorted(entities) check_is_sorted_impl((entities), __LINE__)
static void check_is_sorted_impl(const vector<MessageEntity> &entities, int line) {
LOG_CHECK(std::is_sorted(entities.begin(), entities.end())) << line << " " << entities;
}
#define check_non_intersecting(entities) check_non_intersecting_impl(entities, __LINE__)
#define check_non_intersecting(entities) check_non_intersecting_impl((entities), __LINE__)
static void check_non_intersecting_impl(const vector<MessageEntity> &entities, int line) {
for (size_t i = 0; i + 1 < entities.size(); i++) {
LOG_CHECK(entities[i].offset + entities[i].length <= entities[i + 1].offset) << line << " " << entities;
@ -4248,7 +4248,7 @@ vector<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co
break;
case MessageEntity::Type::MentionName: {
auto r_input_user = contacts_manager->get_input_user(entity.user_id);
LOG_CHECK(r_input_user.is_ok()) << source << ' ' << r_input_user.error();
LOG_CHECK(r_input_user.is_ok()) << source << ' ' << entity.user_id << ' ' << r_input_user.error();
result.push_back(make_tl_object<telegram_api::inputMessageEntityMentionName>(entity.offset, entity.length,
r_input_user.move_as_ok()));
break;

View File

@ -14,10 +14,9 @@
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/StringBuilder.h"
#include <utility>

View File

@ -14,7 +14,6 @@
#include "td/db/SqliteStatement.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/SchedulerLocalStorage.h"
#include "td/utils/format.h"
@ -1216,11 +1215,12 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
//NB: order is important, destructor of pending_writes_ will change pending_write_results_
vector<std::pair<Promise<>, Status>> pending_write_results_;
vector<Promise<>> pending_writes_;
vector<Promise<>> pending_writes_; // TODO use Action
double wakeup_at_ = 0;
template <class F>
void add_write_query(F &&f) {
pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f), PromiseCreator::Ignore()));
pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f)));
if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) {
do_flush();
wakeup_at_ = 0;

View File

@ -13,10 +13,9 @@
#include "td/telegram/NotificationId.h"
#include "td/telegram/ServerMessageId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <memory>

View File

@ -69,7 +69,6 @@
#include "td/db/SqliteKeyValue.h"
#include "td/db/SqliteKeyValueAsync.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/SleepActor.h"
#include "td/utils/algorithm.h"
@ -3213,11 +3212,11 @@ class SendMessageQuery final : public Td::ResultHandler {
{{dialog_id, MessageContentType::Text},
{dialog_id, is_copy ? MessageContentType::Photo : MessageContentType::Text}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda(
[random_id](Unit) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
},
PromiseCreator::Ignore());
query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}
});
}
*send_query_ref = query.get_weak();
send_query(std::move(query));
@ -3284,11 +3283,11 @@ class StartBotQuery final : public Td::ResultHandler {
telegram_api::messages_startBot(std::move(bot_input_user), std::move(input_peer), random_id, parameter),
{{dialog_id, MessageContentType::Text}, {dialog_id, MessageContentType::Photo}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda(
[random_id](Unit) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
},
PromiseCreator::Ignore());
query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}
});
}
auto send_query_ref = query.get_weak();
send_query(std::move(query));
@ -3526,11 +3525,11 @@ class SendMediaQuery final : public Td::ResultHandler {
std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)),
{{dialog_id, content_type}, {dialog_id, is_copy ? MessageContentType::Text : content_type}});
if (G()->shared_config().get_option_boolean("use_quick_ack") && was_uploaded_) {
query->quick_ack_promise_ = PromiseCreator::lambda(
[random_id](Unit) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
},
PromiseCreator::Ignore());
query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}
});
}
*send_query_ref = query.get_weak();
send_query(std::move(query));
@ -3890,13 +3889,13 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
std::move(random_ids), std::move(to_input_peer), schedule_date, std::move(as_input_peer)),
{{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda(
[random_ids = random_ids_](Unit) {
for (auto random_id : random_ids) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}
},
PromiseCreator::Ignore());
query->quick_ack_promise_ = PromiseCreator::lambda([random_ids = random_ids_](Result<Unit> result) {
if (result.is_ok()) {
for (auto random_id : random_ids) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}
}
});
}
send_query(std::move(query));
}
@ -24694,7 +24693,8 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
auto is_pinned = is_scheduled ? false : m->is_pinned;
auto has_timestamped_media = for_event_log || reply_to_message_id == 0 || m->max_own_media_timestamp >= 0;
auto reply_markup = get_reply_markup_object(m->reply_markup);
auto reply_markup =
get_reply_markup_object(m->message_id.is_any_server() ? td_->contacts_manager_.get() : nullptr, m->reply_markup);
auto live_location_date = m->is_failed_to_send ? 0 : m->date;
auto skip_bot_commands = for_event_log ? true : need_skip_bot_commands(dialog_id, m);
@ -25817,7 +25817,7 @@ void MessagesManager::on_message_media_uploaded(DialogId dialog_id, const Messag
auto message_id = m->message_id;
if (message_id.is_any_server()) {
const FormattedText *caption = get_message_content_caption(m->edited_content.get());
auto input_reply_markup = get_input_reply_markup(m->edited_reply_markup);
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), m->edited_reply_markup);
bool was_uploaded = FileManager::extract_was_uploaded(input_media);
bool was_thumbnail_uploaded = FileManager::extract_was_thumbnail_uploaded(input_media);
@ -25857,7 +25857,8 @@ void MessagesManager::on_message_media_uploaded(DialogId dialog_id, const Messag
int64 random_id = begin_send_message(dialog_id, m);
td_->create_handler<SendMediaQuery>()->send(
file_id, thumbnail_file_id, get_message_flags(m), dialog_id, get_send_message_as_input_peer(m),
m->reply_to_message_id, get_message_schedule_date(m), get_input_reply_markup(m->reply_markup),
m->reply_to_message_id, get_message_schedule_date(m),
get_input_reply_markup(td_->contacts_manager_.get(), m->reply_markup),
get_input_message_entities(td_->contacts_manager_.get(), caption, "on_message_media_uploaded"),
caption == nullptr ? "" : caption->text, std::move(input_media), m->content->get_type(), m->is_copy,
random_id, &m->send_query_ref);
@ -26263,7 +26264,7 @@ void MessagesManager::on_text_message_ready_to_send(DialogId dialog_id, MessageI
int64 random_id = begin_send_message(dialog_id, m);
td_->create_handler<SendMessageQuery>()->send(
get_message_flags(m), dialog_id, get_send_message_as_input_peer(m), m->reply_to_message_id,
get_message_schedule_date(m), get_input_reply_markup(m->reply_markup),
get_message_schedule_date(m), get_input_reply_markup(td_->contacts_manager_.get(), m->reply_markup),
get_input_message_entities(td_->contacts_manager_.get(), message_text->entities, "do_send_message"),
message_text->text, m->is_copy, random_id, &m->send_query_ref);
}
@ -26972,7 +26973,7 @@ void MessagesManager::edit_message_text(FullMessageId full_message_id,
if (r_new_reply_markup.is_error()) {
return promise.set_error(r_new_reply_markup.move_as_error());
}
auto input_reply_markup = get_input_reply_markup(r_new_reply_markup.ok());
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok());
int32 flags = 0;
if (input_message_text.disable_web_page_preview) {
flags |= SEND_MESSAGE_FLAG_DISABLE_WEB_PAGE_PREVIEW;
@ -27028,7 +27029,7 @@ void MessagesManager::edit_message_live_location(FullMessageId full_message_id,
if (r_new_reply_markup.is_error()) {
return promise.set_error(r_new_reply_markup.move_as_error());
}
auto input_reply_markup = get_input_reply_markup(r_new_reply_markup.ok());
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok());
int32 flags = 0;
if (location.empty()) {
@ -27264,7 +27265,7 @@ void MessagesManager::edit_message_caption(FullMessageId full_message_id,
if (r_new_reply_markup.is_error()) {
return promise.set_error(r_new_reply_markup.move_as_error());
}
auto input_reply_markup = get_input_reply_markup(r_new_reply_markup.ok());
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok());
td_->create_handler<EditMessageQuery>(std::move(promise))
->send(1 << 11, dialog_id, m->message_id, caption.text,
@ -27304,7 +27305,7 @@ void MessagesManager::edit_message_reply_markup(FullMessageId full_message_id,
if (r_new_reply_markup.is_error()) {
return promise.set_error(r_new_reply_markup.move_as_error());
}
auto input_reply_markup = get_input_reply_markup(r_new_reply_markup.ok());
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok());
td_->create_handler<EditMessageQuery>(std::move(promise))
->send(0, dialog_id, m->message_id, string(), vector<tl_object_ptr<telegram_api::MessageEntity>>(), nullptr,
std::move(input_reply_markup), get_message_schedule_date(m));
@ -27351,7 +27352,7 @@ void MessagesManager::edit_inline_message_text(const string &inline_message_id,
->send(flags, std::move(input_bot_inline_message_id), input_message_text.text.text,
get_input_message_entities(td_->contacts_manager_.get(), input_message_text.text.entities,
"edit_inline_message_text"),
nullptr, get_input_reply_markup(r_new_reply_markup.ok()));
nullptr, get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok()));
}
void MessagesManager::edit_inline_message_live_location(const string &inline_message_id,
@ -27389,7 +27390,7 @@ void MessagesManager::edit_inline_message_live_location(const string &inline_mes
flags, false /*ignored*/, location.get_input_geo_point(), heading, 0, proximity_alert_radius);
td_->create_handler<EditInlineMessageQuery>(std::move(promise))
->send(0, std::move(input_bot_inline_message_id), "", vector<tl_object_ptr<telegram_api::MessageEntity>>(),
std::move(input_media), get_input_reply_markup(r_new_reply_markup.ok()));
std::move(input_media), get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok()));
}
void MessagesManager::edit_inline_message_media(const string &inline_message_id,
@ -27441,7 +27442,7 @@ void MessagesManager::edit_inline_message_media(const string &inline_message_id,
td_->create_handler<EditInlineMessageQuery>(std::move(promise))
->send(1 << 11, std::move(input_bot_inline_message_id), caption == nullptr ? "" : caption->text,
get_input_message_entities(td_->contacts_manager_.get(), caption, "edit_inline_message_media"),
std::move(input_media), get_input_reply_markup(r_new_reply_markup.ok()));
std::move(input_media), get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok()));
}
void MessagesManager::edit_inline_message_caption(const string &inline_message_id,
@ -27472,7 +27473,7 @@ void MessagesManager::edit_inline_message_caption(const string &inline_message_i
td_->create_handler<EditInlineMessageQuery>(std::move(promise))
->send(1 << 11, std::move(input_bot_inline_message_id), caption.text,
get_input_message_entities(td_->contacts_manager_.get(), caption.entities, "edit_inline_message_caption"),
nullptr, get_input_reply_markup(r_new_reply_markup.ok()));
nullptr, get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok()));
}
void MessagesManager::edit_inline_message_reply_markup(const string &inline_message_id,
@ -27494,7 +27495,7 @@ void MessagesManager::edit_inline_message_reply_markup(const string &inline_mess
td_->create_handler<EditInlineMessageQuery>(std::move(promise))
->send(0, std::move(input_bot_inline_message_id), string(), vector<tl_object_ptr<telegram_api::MessageEntity>>(),
nullptr, get_input_reply_markup(r_new_reply_markup.ok()));
nullptr, get_input_reply_markup(td_->contacts_manager_.get(), r_new_reply_markup.ok()));
}
void MessagesManager::edit_message_scheduling_state(
@ -28008,8 +28009,8 @@ class MessagesManager::ForwardMessagesLogEvent {
DialogId from_dialog_id;
vector<MessageId> message_ids;
vector<Message *> messages_in;
bool drop_author;
bool drop_media_captions;
bool drop_author = false;
bool drop_media_captions = false;
vector<unique_ptr<Message>> messages_out;
template <class StorerT>
@ -29073,16 +29074,17 @@ void MessagesManager::on_imported_message_attachments_uploaded(int64 random_id,
}
bool MessagesManager::on_update_message_id(int64 random_id, MessageId new_message_id, const string &source) {
if (!new_message_id.is_valid() || !new_message_id.is_server()) {
if (!new_message_id.is_valid() && !new_message_id.is_valid_scheduled()) {
LOG(ERROR) << "Receive " << new_message_id << " in updateMessageId with random_id " << random_id << " from "
<< source;
return false;
}
CHECK(new_message_id.is_any_server());
auto it = being_sent_messages_.find(random_id);
if (it == being_sent_messages_.end()) {
// update about a new message sent from other device or a service message
LOG(INFO) << "Receive not send outgoing " << new_message_id << " with random_id = " << random_id;
LOG(INFO) << "Receive not sent outgoing " << new_message_id << " with random_id = " << random_id;
return true;
}
@ -29098,38 +29100,11 @@ bool MessagesManager::on_update_message_id(int64 random_id, MessageId new_messag
LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id;
CHECK(old_message_id.is_yet_unsent());
update_message_ids_[FullMessageId(dialog_id, new_message_id)] = old_message_id;
return true;
}
bool MessagesManager::on_update_scheduled_message_id(int64 random_id, ScheduledServerMessageId new_message_id,
const string &source) {
if (!new_message_id.is_valid()) {
LOG(ERROR) << "Receive " << new_message_id << " in updateMessageId with random_id " << random_id << " from "
<< source;
return false;
if (new_message_id.is_scheduled()) {
update_scheduled_message_ids_[dialog_id][new_message_id.get_scheduled_server_message_id()] = old_message_id;
} else {
update_message_ids_[FullMessageId(dialog_id, new_message_id)] = old_message_id;
}
auto it = being_sent_messages_.find(random_id);
if (it == being_sent_messages_.end()) {
LOG(ERROR) << "Receive not send outgoing " << new_message_id << " with random_id = " << random_id;
return false;
}
auto dialog_id = it->second.get_dialog_id();
auto old_message_id = it->second.get_message_id();
being_sent_messages_.erase(it);
if (!have_message_force({dialog_id, old_message_id}, "on_update_scheduled_message_id")) {
delete_sent_message_on_server(dialog_id, MessageId(new_message_id, std::numeric_limits<int32>::max()),
old_message_id);
return true;
}
LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id;
CHECK(old_message_id.is_yet_unsent());
update_scheduled_message_ids_[dialog_id][new_message_id] = old_message_id;
return true;
}
@ -30509,8 +30484,9 @@ void MessagesManager::send_update_message_edited(DialogId dialog_id, const Messa
cancel_dialog_action(dialog_id, m);
auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateMessageEdited>(dialog_id.get(), m->message_id.get(), edit_date,
get_reply_markup_object(m->reply_markup)));
make_tl_object<td_api::updateMessageEdited>(
dialog_id.get(), m->message_id.get(), edit_date,
get_reply_markup_object(td_->contacts_manager_.get(), m->reply_markup)));
}
void MessagesManager::send_update_message_interaction_info(DialogId dialog_id, const Message *m) const {
@ -36819,9 +36795,15 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
<< ", max_notification_message_id = " << d->max_notification_message_id;
if (d->messages != nullptr) {
CHECK(d->messages->message_id == last_message_id);
CHECK(d->messages->left == nullptr);
CHECK(d->messages->right == nullptr);
LOG_CHECK(d->messages->message_id == last_message_id)
<< d->messages->message_id << ' ' << last_message_id << ' ' << d->debug_set_dialog_last_database_message_id
<< ' ' << d->messages->debug_source;
LOG_CHECK(d->messages->left == nullptr)
<< d->messages->left->message_id << ' ' << d->messages->message_id << ' ' << last_message_id << ' '
<< d->debug_set_dialog_last_database_message_id << ' ' << d->messages->debug_source;
LOG_CHECK(d->messages->right == nullptr)
<< d->messages->right->message_id << ' ' << d->messages->message_id << ' ' << last_message_id << ' '
<< d->debug_set_dialog_last_database_message_id << ' ' << d->messages->debug_source;
}
// must be after update_dialog_pos, because uses d->order
@ -37257,7 +37239,7 @@ void MessagesManager::update_dialog_lists(
if (total_count != -1) {
total_count += delta;
if (total_count < 0) {
LOG(ERROR) << "Total chat count became negative after leaving " << dialog_id;
LOG(ERROR) << "Total chat count in " << dialog_list_id << " became negative after removing " << dialog_id;
total_count = 0;
}
}
@ -37267,7 +37249,7 @@ void MessagesManager::update_dialog_lists(
need_update_unread_chat_count =
list.is_dialog_unread_count_inited_ && old_position.total_dialog_count != get_dialog_total_count(list);
auto unread_count = d->server_unread_count + d->local_unread_count;
const char *change_source = was_in_list ? "on_dialog_leave" : "on_dialog_join";
const char *change_source = was_in_list ? "on_dialog_remove" : "on_dialog_add";
if (unread_count != 0 && list.is_message_unread_count_inited_) {
unread_count *= delta;

View File

@ -61,7 +61,6 @@
#include "td/actor/actor.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/SignalSlot.h"
#include "td/actor/Timeout.h"
@ -73,6 +72,7 @@
#include "td/utils/Heap.h"
#include "td/utils/Hints.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
@ -290,8 +290,6 @@ class MessagesManager final : public Actor {
bool on_update_message_id(int64 random_id, MessageId new_message_id, const string &source);
bool on_update_scheduled_message_id(int64 random_id, ScheduledServerMessageId new_message_id, const string &source);
void on_update_dialog_draft_message(DialogId dialog_id, tl_object_ptr<telegram_api::DraftMessage> &&draft_message);
void on_update_dialog_is_pinned(FolderId folder_id, DialogId dialog_id, bool is_pinned);

View File

@ -449,7 +449,7 @@ NotificationManager::NotificationGroups::iterator NotificationManager::get_group
if (last_group_key.last_notification_date != 0) {
send_remove_group_update(last_group_key, groups_[last_group_key], vector<int32>());
}
send_add_group_update(group_key, group);
send_add_group_update(group_key, group, "get_group_force");
}
}
return add_group(std::move(group_key), std::move(group), "get_group_force");
@ -468,6 +468,7 @@ int32 NotificationManager::load_message_notification_groups_from_database(int32
return 0;
}
VLOG(notifications) << "Trying to load up to " << limit << " notification groups from database";
vector<NotificationGroupKey> group_keys = td_->messages_manager_->get_message_notification_group_keys_from_database(
last_loaded_notification_group_key_, limit);
last_loaded_notification_group_key_ =
@ -681,7 +682,7 @@ void NotificationManager::add_notifications_to_group_begin(NotificationGroups::i
// need to remove last notification group to not exceed max_notification_group_count_
send_remove_group_update(last_group_key, groups_[last_group_key], vector<int32>());
}
send_add_group_update(group_key, group);
send_add_group_update(group_key, group, "add_notifications_to_group_begin");
}
vector<Notification> new_notifications;
@ -718,7 +719,7 @@ void NotificationManager::add_notifications_to_group_begin(NotificationGroups::i
if (!added_notifications.empty()) {
add_update_notification_group(td_api::make_object<td_api::updateNotificationGroup>(
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, true,
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, 0,
group.total_count, std::move(added_notifications), vector<int32>()));
}
}
@ -1449,7 +1450,7 @@ td_api::object_ptr<td_api::updateNotificationGroup> NotificationManager::get_rem
}
return td_api::make_object<td_api::updateNotificationGroup>(
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(),
group_key.dialog_id.get(), true, group.total_count, vector<td_api::object_ptr<td_api::notification>>(),
group_key.dialog_id.get(), 0, group.total_count, vector<td_api::object_ptr<td_api::notification>>(),
std::move(removed_notification_ids));
}
@ -1463,8 +1464,9 @@ void NotificationManager::send_remove_group_update(const NotificationGroupKey &g
}
}
void NotificationManager::send_add_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group) {
VLOG(notifications) << "Add " << group_key.group_id;
void NotificationManager::send_add_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group,
const char *source) {
VLOG(notifications) << "Add " << group_key.group_id << " from " << source;
auto total_size = group.notifications.size();
auto added_size = min(total_size, max_notification_group_size_);
vector<td_api::object_ptr<td_api::notification>> added_notifications;
@ -1478,7 +1480,7 @@ void NotificationManager::send_add_group_update(const NotificationGroupKey &grou
if (!added_notifications.empty()) {
add_update_notification_group(td_api::make_object<td_api::updateNotificationGroup>(
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, true,
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, 0,
group.total_count, std::move(added_notifications), vector<int32>()));
}
}
@ -1536,7 +1538,7 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_
removed_group_id = last_group_key.group_id;
send_remove_group_update(last_group_key, groups_[last_group_key], vector<int32>());
}
send_add_group_update(group_key, group);
send_add_group_update(group_key, group, "flush_pending_notifications");
}
DialogId notification_settings_dialog_id;
@ -1731,8 +1733,8 @@ void NotificationManager::on_notifications_removed(
if (final_group_key.last_notification_date == 0 && group.total_count == 0) {
// send update about empty invisible group anyway
add_update_notification_group(td_api::make_object<td_api::updateNotificationGroup>(
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, true,
0, vector<td_api::object_ptr<td_api::notification>>(), vector<int32>()));
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, 0, 0,
vector<td_api::object_ptr<td_api::notification>>(), vector<int32>()));
} else {
VLOG(notifications) << "There is no need to send updateNotificationGroup about " << group_key.group_id;
}
@ -1740,14 +1742,14 @@ void NotificationManager::on_notifications_removed(
if (is_updated) {
// group is still visible
add_update_notification_group(td_api::make_object<td_api::updateNotificationGroup>(
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, true,
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(), 0, 0,
group.total_count, std::move(added_notifications), std::move(removed_notification_ids)));
} else {
// group needs to be removed
send_remove_group_update(group_key, group, std::move(removed_notification_ids));
if (last_group_key.last_notification_date != 0) {
// need to add new last notification group
send_add_group_update(last_group_key, groups_[last_group_key]);
send_add_group_update(last_group_key, groups_[last_group_key], "on_notifications_removed");
}
}
}
@ -1766,8 +1768,8 @@ void NotificationManager::on_notifications_removed(
}
if (last_loaded_notification_group_key_ < last_group_key) {
load_message_notification_groups_from_database(td::max(static_cast<int32>(max_notification_group_count_), 10) / 2,
true);
auto limit = td::max(static_cast<int32>(max_notification_group_count_), static_cast<int32>(10)) / 2;
load_message_notification_groups_from_database(limit, true);
}
}
@ -2415,7 +2417,7 @@ void NotificationManager::on_notification_group_count_max_changed(bool send_upda
}
if (is_increased) {
send_add_group_update(group_key, group);
send_add_group_update(group_key, group, "on_notification_group_count_max_changed");
} else {
send_remove_group_update(group_key, group, vector<int32>());
}
@ -2434,7 +2436,8 @@ void NotificationManager::on_notification_group_count_max_changed(bool send_upda
max_notification_group_count_ = new_max_notification_group_count_size_t;
if (is_increased && last_loaded_notification_group_key_ < get_last_updated_group_key()) {
load_message_notification_groups_from_database(td::max(new_max_notification_group_count, 5), true);
auto limit = td::max(new_max_notification_group_count, static_cast<int32>(5));
load_message_notification_groups_from_database(limit, true);
}
}
@ -2509,7 +2512,7 @@ void NotificationManager::on_notification_group_size_max_changed() {
if (!is_destroyed_) {
auto update = td_api::make_object<td_api::updateNotificationGroup>(
group_key.group_id.get(), get_notification_group_type_object(group.type), group_key.dialog_id.get(),
group_key.dialog_id.get(), true, group.total_count, std::move(added_notifications),
group_key.dialog_id.get(), 0, group.total_count, std::move(added_notifications),
std::move(removed_notification_ids));
VLOG(notifications) << "Send " << as_notification_update(update.get());
send_closure(G()->td(), &Td::send_update, std::move(update));

View File

@ -21,13 +21,13 @@
#include "td/telegram/td_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/Time.h"
@ -273,7 +273,7 @@ class NotificationManager final : public Actor {
void send_remove_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group,
vector<int32> &&removed_notification_ids);
void send_add_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group);
void send_add_group_update(const NotificationGroupKey &group_key, const NotificationGroup &group, const char *source);
int32 get_notification_delay_ms(DialogId dialog_id, const PendingNotification &notification,
int32 min_delay_ms) const;

View File

@ -14,11 +14,11 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <memory>

View File

@ -9,9 +9,9 @@
#include "td/telegram/td_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
namespace td {

View File

@ -13,12 +13,12 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Container.h"
#include "td/utils/optional.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/tl_helpers.h"

View File

@ -14,9 +14,8 @@
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"

View File

@ -196,7 +196,7 @@ class StopPollQuery final : public Td::ResultHandler {
}
int32 flags = telegram_api::messages_editMessage::MEDIA_MASK;
auto input_reply_markup = get_input_reply_markup(reply_markup);
auto input_reply_markup = get_input_reply_markup(td_->contacts_manager_.get(), reply_markup);
if (input_reply_markup != nullptr) {
flags |= telegram_api::messages_editMessage::REPLY_MARKUP_MASK;
}
@ -1787,7 +1787,7 @@ void PollManager::on_get_poll_vote(PollId poll_id, UserId user_id, vector<Buffer
for (auto &option : options) {
auto slice = option.as_slice();
if (slice.size() != 1 || slice[0] < '0' || slice[0] > '9') {
LOG(ERROR) << "Receive updateMessagePollVote with unexpected option \"" << format::escaped(slice) << '"';
LOG(INFO) << "Receive updateMessagePollVote with unexpected option \"" << format::escaped(slice) << '"';
return;
}
option_ids.push_back(static_cast<int32>(slice[0] - '0'));

View File

@ -16,13 +16,13 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <utility>

View File

@ -17,6 +17,7 @@
#include "td/telegram/MessageEntity.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UpdatesManager.h"
#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
@ -138,6 +139,94 @@ class GetPremiumPromoQuery final : public Td::ResultHandler {
}
};
class CanPurchasePremiumQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit CanPurchasePremiumQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send() {
send_query(G()->net_query_creator().create(telegram_api::payments_canPurchasePremium()));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_canPurchasePremium>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
bool result = result_ptr.ok();
if (result) {
return promise_.set_value(Unit());
}
on_error(Status::Error(400, "Premium can't be purchased"));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class AssignAppStoreTransactionQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit AssignAppStoreTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &receipt, bool is_restore) {
int32 flags = 0;
if (is_restore) {
flags |= telegram_api::payments_assignAppStoreTransaction::RESTORE_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::payments_assignAppStoreTransaction(flags, false /*ignored*/, BufferSlice(receipt))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_assignAppStoreTransaction>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for AssignAppStoreTransactionQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class AssignPlayMarketTransactionQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit AssignPlayMarketTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &purchase_token) {
send_query(G()->net_query_creator().create(telegram_api::payments_assignPlayMarketTransaction(purchase_token)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_assignPlayMarketTransaction>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for AssignPlayMarketTransactionQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
const vector<Slice> &get_premium_limit_keys() {
static const vector<Slice> limit_keys{"channels",
"saved_gifs",
@ -377,4 +466,16 @@ void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>>
td->create_handler<GetPremiumPromoQuery>(std::move(promise))->send();
}
void can_purchase_premium(Td *td, Promise<Unit> &&promise) {
td->create_handler<CanPurchasePremiumQuery>(std::move(promise))->send();
}
void assign_app_store_transaction(Td *td, const string &receipt, bool is_restore, Promise<Unit> &&promise) {
td->create_handler<AssignAppStoreTransactionQuery>(std::move(promise))->send(receipt, is_restore);
}
void assign_play_market_transaction(Td *td, const string &purchase_token, Promise<Unit> &&promise) {
td->create_handler<AssignPlayMarketTransactionQuery>(std::move(promise))->send(purchase_token);
}
} // namespace td

View File

@ -8,9 +8,8 @@
#include "td/telegram/td_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
namespace td {
@ -31,4 +30,10 @@ void click_premium_subscription_button(Td *td, Promise<Unit> &&promise);
void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>> &&promise);
void can_purchase_premium(Td *td, Promise<Unit> &&promise);
void assign_app_store_transaction(Td *td, const string &receipt, bool is_restore, Promise<Unit> &&promise);
void assign_play_market_transaction(Td *td, const string &purchase_token, Promise<Unit> &&promise);
} // namespace td

View File

@ -12,10 +12,10 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Container.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <array>

View File

@ -7,10 +7,10 @@
#pragma once
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

View File

@ -9,10 +9,10 @@
#include "td/telegram/DialogId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Promise.h"
#include <utility>

View File

@ -11,7 +11,6 @@
#include "td/telegram/Global.h"
#include "td/telegram/LinkManager.h"
#include "td/telegram/misc.h"
#include "td/telegram/Td.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
@ -224,7 +223,12 @@ static KeyboardButton get_keyboard_button(tl_object_ptr<telegram_api::KeyboardBu
auto keyboard_button = move_tl_object_as<telegram_api::keyboardButtonSimpleWebView>(keyboard_button_ptr);
button.type = KeyboardButton::Type::WebView;
button.text = std::move(keyboard_button->text_);
button.url = std::move(keyboard_button->url_);
auto r_url = LinkManager::check_link(keyboard_button->url_);
if (r_url.is_error()) {
LOG(ERROR) << "Keyboard Web App " << r_url.error().message();
return {};
}
button.url = r_url.move_as_ok();
break;
}
default:
@ -243,7 +247,12 @@ static InlineKeyboardButton get_inline_keyboard_button(
auto keyboard_button = move_tl_object_as<telegram_api::keyboardButtonUrl>(keyboard_button_ptr);
button.type = InlineKeyboardButton::Type::Url;
button.text = std::move(keyboard_button->text_);
button.data = std::move(keyboard_button->url_);
auto r_url = LinkManager::check_link(keyboard_button->url_);
if (r_url.is_error()) {
LOG(ERROR) << "Inline keyboard " << r_url.error().message();
return {};
}
button.data = r_url.move_as_ok();
break;
}
case telegram_api::keyboardButtonCallback::ID: {
@ -280,8 +289,13 @@ static InlineKeyboardButton get_inline_keyboard_button(
button.type = InlineKeyboardButton::Type::UrlAuth;
button.id = keyboard_button->button_id_;
button.text = std::move(keyboard_button->text_);
button.data = std::move(keyboard_button->url_);
button.forward_text = std::move(keyboard_button->fwd_text_);
auto r_url = LinkManager::check_link(keyboard_button->url_);
if (r_url.is_error()) {
LOG(ERROR) << "Inline keyboard Login " << r_url.error().message();
return {};
}
button.data = r_url.move_as_ok();
break;
}
case telegram_api::keyboardButtonUserProfile::ID: {
@ -289,13 +303,22 @@ static InlineKeyboardButton get_inline_keyboard_button(
button.type = InlineKeyboardButton::Type::User;
button.text = std::move(keyboard_button->text_);
button.user_id = UserId(keyboard_button->user_id_);
if (!button.user_id.is_valid()) {
LOG(ERROR) << "Receive " << button.user_id << " in inline keyboard";
return {};
}
break;
}
case telegram_api::keyboardButtonWebView::ID: {
auto keyboard_button = move_tl_object_as<telegram_api::keyboardButtonWebView>(keyboard_button_ptr);
button.type = InlineKeyboardButton::Type::WebView;
button.text = std::move(keyboard_button->text_);
button.data = std::move(keyboard_button->url_);
auto r_url = LinkManager::check_link(keyboard_button->url_);
if (r_url.is_error()) {
LOG(ERROR) << "Inline keyboard Web App " << r_url.error().message();
return {};
}
button.data = r_url.move_as_ok();
break;
}
default:
@ -703,7 +726,7 @@ Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMark
return std::move(reply_markup);
}
static tl_object_ptr<telegram_api::KeyboardButton> get_keyboard_button(const KeyboardButton &keyboard_button) {
static tl_object_ptr<telegram_api::KeyboardButton> get_input_keyboard_button(const KeyboardButton &keyboard_button) {
switch (keyboard_button.type) {
case KeyboardButton::Type::Text:
return make_tl_object<telegram_api::keyboardButton>(keyboard_button.text);
@ -725,8 +748,8 @@ static tl_object_ptr<telegram_api::KeyboardButton> get_keyboard_button(const Key
}
}
static tl_object_ptr<telegram_api::KeyboardButton> get_inline_keyboard_button(
const InlineKeyboardButton &keyboard_button) {
static tl_object_ptr<telegram_api::KeyboardButton> get_input_keyboard_button(
ContactsManager *contacts_manager, const InlineKeyboardButton &keyboard_button) {
switch (keyboard_button.type) {
case InlineKeyboardButton::Type::Url:
return make_tl_object<telegram_api::keyboardButtonUrl>(keyboard_button.text, keyboard_button.data);
@ -757,7 +780,7 @@ static tl_object_ptr<telegram_api::KeyboardButton> get_inline_keyboard_button(
if (!keyboard_button.forward_text.empty()) {
flags |= telegram_api::inputKeyboardButtonUrlAuth::FWD_TEXT_MASK;
}
auto r_input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(UserId(bot_user_id));
auto r_input_user = contacts_manager->get_input_user(UserId(bot_user_id));
if (r_input_user.is_error()) {
LOG(ERROR) << "Failed to get InputUser for " << bot_user_id << ": " << r_input_user.error();
return make_tl_object<telegram_api::keyboardButtonUrl>(keyboard_button.text, keyboard_button.data);
@ -770,7 +793,7 @@ static tl_object_ptr<telegram_api::KeyboardButton> get_inline_keyboard_button(
UNREACHABLE();
break;
case InlineKeyboardButton::Type::User: {
auto r_input_user = G()->td().get_actor_unsafe()->contacts_manager_->get_input_user(keyboard_button.user_id);
auto r_input_user = contacts_manager->get_input_user(keyboard_button.user_id);
if (r_input_user.is_error()) {
LOG(ERROR) << "Failed to get InputUser for " << keyboard_button.user_id << ": " << r_input_user.error();
r_input_user = make_tl_object<telegram_api::inputUserEmpty>();
@ -786,7 +809,7 @@ static tl_object_ptr<telegram_api::KeyboardButton> get_inline_keyboard_button(
}
}
tl_object_ptr<telegram_api::ReplyMarkup> ReplyMarkup::get_input_reply_markup() const {
tl_object_ptr<telegram_api::ReplyMarkup> ReplyMarkup::get_input_reply_markup(ContactsManager *contacts_manager) const {
LOG(DEBUG) << "Send " << *this;
switch (type) {
case ReplyMarkup::Type::InlineKeyboard: {
@ -796,7 +819,7 @@ tl_object_ptr<telegram_api::ReplyMarkup> ReplyMarkup::get_input_reply_markup() c
vector<tl_object_ptr<telegram_api::KeyboardButton>> buttons;
buttons.reserve(row.size());
for (auto &button : row) {
buttons.push_back(get_inline_keyboard_button(button));
buttons.push_back(get_input_keyboard_button(contacts_manager, button));
}
rows.push_back(make_tl_object<telegram_api::keyboardButtonRow>(std::move(buttons)));
}
@ -810,7 +833,7 @@ tl_object_ptr<telegram_api::ReplyMarkup> ReplyMarkup::get_input_reply_markup() c
vector<tl_object_ptr<telegram_api::KeyboardButton>> buttons;
buttons.reserve(row.size());
for (auto &button : row) {
buttons.push_back(get_keyboard_button(button));
buttons.push_back(get_input_keyboard_button(button));
}
rows.push_back(make_tl_object<telegram_api::keyboardButtonRow>(std::move(buttons)));
}
@ -868,7 +891,7 @@ static tl_object_ptr<td_api::keyboardButton> get_keyboard_button_object(const Ke
}
static tl_object_ptr<td_api::inlineKeyboardButton> get_inline_keyboard_button_object(
const InlineKeyboardButton &keyboard_button) {
ContactsManager *contacts_manager, const InlineKeyboardButton &keyboard_button) {
tl_object_ptr<td_api::InlineKeyboardButtonType> type;
switch (keyboard_button.type) {
case InlineKeyboardButton::Type::Url:
@ -896,11 +919,13 @@ static tl_object_ptr<td_api::inlineKeyboardButton> get_inline_keyboard_button_ob
case InlineKeyboardButton::Type::CallbackWithPassword:
type = make_tl_object<td_api::inlineKeyboardButtonTypeCallbackWithPassword>(keyboard_button.data);
break;
case InlineKeyboardButton::Type::User:
type = make_tl_object<td_api::inlineKeyboardButtonTypeUser>(
G()->td().get_actor_unsafe()->contacts_manager_->get_user_id_object(keyboard_button.user_id,
"get_inline_keyboard_button_object"));
case InlineKeyboardButton::Type::User: {
auto user_id = contacts_manager == nullptr ? keyboard_button.user_id.get()
: contacts_manager->get_user_id_object(
keyboard_button.user_id, "get_inline_keyboard_button_object");
type = make_tl_object<td_api::inlineKeyboardButtonTypeUser>(user_id);
break;
}
case InlineKeyboardButton::Type::WebView:
type = make_tl_object<td_api::inlineKeyboardButtonTypeWebApp>(keyboard_button.data);
break;
@ -911,7 +936,7 @@ static tl_object_ptr<td_api::inlineKeyboardButton> get_inline_keyboard_button_ob
return make_tl_object<td_api::inlineKeyboardButton>(keyboard_button.text, std::move(type));
}
tl_object_ptr<td_api::ReplyMarkup> ReplyMarkup::get_reply_markup_object() const {
tl_object_ptr<td_api::ReplyMarkup> ReplyMarkup::get_reply_markup_object(ContactsManager *contacts_manager) const {
switch (type) {
case ReplyMarkup::Type::InlineKeyboard: {
vector<vector<tl_object_ptr<td_api::inlineKeyboardButton>>> rows;
@ -920,7 +945,7 @@ tl_object_ptr<td_api::ReplyMarkup> ReplyMarkup::get_reply_markup_object() const
vector<tl_object_ptr<td_api::inlineKeyboardButton>> buttons;
buttons.reserve(row.size());
for (auto &button : row) {
buttons.push_back(get_inline_keyboard_button_object(button));
buttons.push_back(get_inline_keyboard_button_object(contacts_manager, button));
}
rows.push_back(std::move(buttons));
}
@ -952,20 +977,22 @@ tl_object_ptr<td_api::ReplyMarkup> ReplyMarkup::get_reply_markup_object() const
}
}
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(const unique_ptr<ReplyMarkup> &reply_markup) {
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(ContactsManager *contacts_manager,
const unique_ptr<ReplyMarkup> &reply_markup) {
if (reply_markup == nullptr) {
return nullptr;
}
return reply_markup->get_input_reply_markup();
return reply_markup->get_input_reply_markup(contacts_manager);
}
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(const unique_ptr<ReplyMarkup> &reply_markup) {
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(ContactsManager *contacts_manager,
const unique_ptr<ReplyMarkup> &reply_markup) {
if (reply_markup == nullptr) {
return nullptr;
}
return reply_markup->get_reply_markup_object();
return reply_markup->get_reply_markup_object(contacts_manager);
}
void add_reply_markup_dependencies(Dependencies &dependencies, const ReplyMarkup *reply_markup) {

View File

@ -16,6 +16,7 @@
namespace td {
class ContactsManager;
class Dependencies;
struct KeyboardButton {
@ -72,9 +73,9 @@ struct ReplyMarkup {
StringBuilder &print(StringBuilder &string_builder) const;
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup() const;
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(ContactsManager *contacts_manager) const;
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object() const;
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(ContactsManager *contacts_manager) const;
};
bool operator==(const ReplyMarkup &lhs, const ReplyMarkup &rhs);
@ -89,9 +90,11 @@ Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMark
bool only_inline_keyboard, bool request_buttons_allowed,
bool switch_inline_buttons_allowed) TD_WARN_UNUSED_RESULT;
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(const unique_ptr<ReplyMarkup> &reply_markup);
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(ContactsManager *contacts_manager,
const unique_ptr<ReplyMarkup> &reply_markup);
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(const unique_ptr<ReplyMarkup> &reply_markup);
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(ContactsManager *contacts_manager,
const unique_ptr<ReplyMarkup> &reply_markup);
void add_reply_markup_dependencies(Dependencies &dependencies, const ReplyMarkup *reply_markup);

View File

@ -15,6 +15,7 @@
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <type_traits>
@ -37,7 +38,7 @@ class RequestActor : public Actor {
FutureActor<T> future;
init_promise_future(&promise_actor, &future);
auto promise = PromiseCreator::from_promise_actor(std::move(promise_actor));
auto promise = create_promise_from_promise_actor(std::move(promise_actor));
do_run(std::move(promise));
if (future.is_ready()) {

View File

@ -1436,9 +1436,11 @@ NetQueryPtr SecretChatActor::create_net_query(const log_event::OutboundSecretMes
}
if (message.is_external && context_->get_config_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ =
PromiseCreator::lambda([actor_id = actor_id(this), random_id = message.random_id](
Unit) { send_closure(actor_id, &SecretChatActor::on_send_message_ack, random_id); },
PromiseCreator::Ignore());
PromiseCreator::lambda([actor_id = actor_id(this), random_id = message.random_id](Result<Unit> result) {
if (result.is_ok()) {
send_closure(actor_id, &SecretChatActor::on_send_message_ack, random_id);
}
});
}
return query;

View File

@ -24,7 +24,6 @@
#include "td/mtproto/DhHandshake.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/ChangesProcessor.h"
@ -32,6 +31,7 @@
#include "td/utils/Container.h"
#include "td/utils/format.h"
#include "td/utils/port/Clocks.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"

View File

@ -28,8 +28,6 @@
#include "td/db/binlog/BinlogHelper.h"
#include "td/db/binlog/BinlogInterface.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"

View File

@ -14,9 +14,9 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Time.h"
#include <map>

View File

@ -14,11 +14,11 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Container.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <map>

View File

@ -17,6 +17,7 @@
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Promise.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"

View File

@ -12,11 +12,11 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -128,7 +128,7 @@ void StateManager::on_network_soft() {
}
void StateManager::start_up() {
create_actor<SleepActor>("SleepActor", 1, PromiseCreator::event(self_closure(this, &StateManager::on_network_soft)))
create_actor<SleepActor>("SleepActor", 1, create_event_promise(self_closure(this, &StateManager::on_network_soft)))
.release();
loop();
}

View File

@ -12,9 +12,9 @@
#include "td/mtproto/ConnectionManager.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -41,8 +41,6 @@
#include "td/db/SqliteKeyValue.h"
#include "td/db/SqliteKeyValueAsync.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/SleepActor.h"
#include "td/utils/algorithm.h"

View File

@ -22,7 +22,6 @@
#include "td/actor/actor.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/buffer.h"
@ -30,6 +29,7 @@
#include "td/utils/FlatHashMap.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Hints.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

View File

@ -12,10 +12,10 @@
#include "td/telegram/td_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/CancellationToken.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

View File

@ -9,9 +9,8 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/td_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
namespace td {

View File

@ -135,7 +135,6 @@
#include "td/mtproto/TransportType.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
@ -7931,6 +7930,25 @@ void Td::on_request(uint64 id, const td_api::getPremiumState &request) {
get_premium_state(this, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::canPurchasePremium &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
can_purchase_premium(this, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::assignAppStoreTransaction &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
assign_app_store_transaction(this, request.receipt_, request.is_restore_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::assignGooglePlayTransaction &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.purchase_token_);
CREATE_OK_REQUEST_PROMISE();
assign_play_market_transaction(this, request.purchase_token_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::acceptTermsOfService &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.terms_of_service_id_);

View File

@ -21,7 +21,6 @@
#include "td/db/DbKey.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/buffer.h"
@ -29,6 +28,7 @@
#include "td/utils/Container.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
@ -1318,6 +1318,12 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getPremiumState &request);
void on_request(uint64 id, const td_api::canPurchasePremium &request);
void on_request(uint64 id, const td_api::assignAppStoreTransaction &request);
void on_request(uint64 id, td_api::assignGooglePlayTransaction &request);
void on_request(uint64 id, td_api::acceptTermsOfService &request);
void on_request(uint64 id, const td_api::getCountries &request);

View File

@ -13,8 +13,7 @@
#include "td/db/DbKey.h"
#include "td/db/KeyValueSyncInterface.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"

View File

@ -11,9 +11,8 @@
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/tl_helpers.h"

View File

@ -12,9 +12,9 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -22,6 +22,8 @@
#include "td/telegram/TdDb.h"
#include "td/telegram/TdParameters.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
#include "td/utils/logging.h"
@ -587,7 +589,7 @@ void TopDialogManager::try_start() {
db_sync_state_ = SyncState::Ok;
send_closure(G()->state_manager(), &StateManager::wait_first_sync,
PromiseCreator::event(self_closure(this, &TopDialogManager::on_first_sync)));
create_event_promise(self_closure(this, &TopDialogManager::on_first_sync)));
}
void TopDialogManager::on_first_sync() {

View File

@ -11,9 +11,9 @@
#include "td/telegram/TopDialogCategory.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include "td/utils/Time.h"

View File

@ -57,12 +57,14 @@
#include "td/telegram/WebPagesManager.h"
#include "td/actor/MultiPromise.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Random.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/Slice.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"
@ -371,12 +373,12 @@ void UpdatesManager::before_get_difference(bool is_initial) {
Promise<> UpdatesManager::add_pts(int32 pts) {
auto id = pts_manager_.add_pts(pts);
return PromiseCreator::event(self_closure(this, &UpdatesManager::on_pts_ack, id));
return create_event_promise(self_closure(this, &UpdatesManager::on_pts_ack, id));
}
Promise<> UpdatesManager::add_qts(int32 qts) {
auto id = qts_manager_.add_pts(qts);
return PromiseCreator::event(self_closure(this, &UpdatesManager::on_qts_ack, id));
return create_event_promise(self_closure(this, &UpdatesManager::on_qts_ack, id));
}
void UpdatesManager::on_pts_ack(PtsManager::PtsId ack_token) {
@ -1719,7 +1721,7 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
case telegram_api::updateServiceNotification::ID:
case telegram_api::updateLangPackTooLong::ID:
case telegram_api::updateLangPack::ID:
short_update_date_ = date;
short_update_date_ = date == 0 ? G()->unix_time() : date;
LOG(INFO) << "Process short " << oneline(to_string(update));
// don't need promise for short update
downcast_call(*update, OnUpdate(this, update, Promise<Unit>()));
@ -1796,16 +1798,20 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
size_t ordinary_new_message_count = 0;
size_t scheduled_new_message_count = 0;
size_t update_message_id_count = 0;
size_t update_count = 0;
for (auto &update : updates) {
if (update != nullptr) {
auto constructor_id = update->get_id();
if (constructor_id == telegram_api::updateNewMessage::ID ||
constructor_id == telegram_api::updateNewChannelMessage::ID) {
ordinary_new_message_count++;
} else if (constructor_id == telegram_api::updateNewScheduledMessage::ID) {
scheduled_new_message_count++;
} else if (constructor_id == telegram_api::updateMessageID::ID) {
if (constructor_id == telegram_api::updateMessageID::ID) {
update_message_id_count++;
} else {
update_count++;
if (constructor_id == telegram_api::updateNewMessage::ID ||
constructor_id == telegram_api::updateNewChannelMessage::ID) {
ordinary_new_message_count++;
} else if (constructor_id == telegram_api::updateNewScheduledMessage::ID) {
scheduled_new_message_count++;
}
}
}
}
@ -1822,11 +1828,29 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
}
MultiPromiseActorSafe mpas{"OnPendingUpdatesMultiPromiseActor"};
being_processed_updates_++;
mpas.add_promise([actor_id = create_reference(), promise = std::move(promise)](Result<Unit> &&result) mutable {
send_closure(actor_id, &UpdatesManager::on_pending_updates_processed, std::move(result), std::move(promise));
});
auto lock = mpas.get_promise();
Promise<Unit> lock;
auto use_mpas = need_postpone || update_count != 1;
auto get_promise = [&] {
if (use_mpas) {
return mpas.get_promise();
} else {
CHECK(update_count != 0);
update_count--;
return std::move(promise);
}
};
if (use_mpas) {
being_processed_updates_++;
mpas.add_promise([actor_id = create_reference(), promise = std::move(promise)](Result<Unit> &&result) mutable {
send_closure(actor_id, &UpdatesManager::on_pending_updates_processed, std::move(result), std::move(promise));
});
lock = get_promise();
}
SCOPE_EXIT {
if (!use_mpas && update_count == 1) {
promise.set_value(Unit());
}
};
for (auto &update : updates) {
if (update != nullptr) {
@ -1835,15 +1859,13 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
if (id == telegram_api::updateMessageID::ID) {
LOG(INFO) << "Receive from " << source << " " << to_string(update);
auto sent_message_update = move_tl_object_as<telegram_api::updateMessageID>(update);
bool success = false;
MessageId message_id;
if (ordinary_new_message_count != 0) {
success = td_->messages_manager_->on_update_message_id(
sent_message_update->random_id_, MessageId(ServerMessageId(sent_message_update->id_)), source);
message_id = MessageId(ServerMessageId(sent_message_update->id_));
} else if (scheduled_new_message_count != 0) {
success = td_->messages_manager_->on_update_scheduled_message_id(
sent_message_update->random_id_, ScheduledServerMessageId(sent_message_update->id_), source);
message_id = MessageId(ScheduledServerMessageId(sent_message_update->id_), std::numeric_limits<int32>::max());
}
if (!success) {
if (!td_->messages_manager_->on_update_message_id(sent_message_update->random_id_, message_id, source)) {
for (auto &debug_update : updates) {
LOG(ERROR) << "Update: " << oneline(to_string(debug_update));
}
@ -1851,11 +1873,11 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
update = nullptr;
}
if (id == telegram_api::updateFolderPeers::ID) {
on_update(move_tl_object_as<telegram_api::updateFolderPeers>(update), mpas.get_promise());
on_update(move_tl_object_as<telegram_api::updateFolderPeers>(update), get_promise());
update = nullptr;
}
if (id == telegram_api::updateEncryption::ID) {
on_update(move_tl_object_as<telegram_api::updateEncryption>(update), mpas.get_promise());
on_update(move_tl_object_as<telegram_api::updateEncryption>(update), get_promise());
update = nullptr;
}
CHECK(need_postpone || !running_get_difference_);
@ -1871,7 +1893,7 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
min_postponed_update_pts_ = pts;
}
}
downcast_call(*update, OnUpdate(this, update, mpas.get_promise()));
downcast_call(*update, OnUpdate(this, update, get_promise()));
update = nullptr;
} else if (is_qts_update(update.get())) {
if (running_get_difference_) {
@ -1880,7 +1902,10 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
min_postponed_update_qts_ = qts;
}
}
downcast_call(*update, OnUpdate(this, update, mpas.get_promise()));
downcast_call(*update, OnUpdate(this, update, get_promise()));
update = nullptr;
} else if (is_channel_pts_update(update.get())) {
downcast_call(*update, OnUpdate(this, update, get_promise()));
update = nullptr;
}
}
@ -1900,6 +1925,11 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
}
}
if (!use_mpas && update_count == 1) {
// still need to process the only update
lock = std::move(promise); // now we can use lock as the last promise
update_count = 0;
}
if (need_postpone || running_get_difference_) {
LOG(INFO) << "Postpone " << updates.size() << " updates [" << seq_begin << ", " << seq_end
<< "] with date = " << date << " from " << source;
@ -1907,16 +1937,16 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
LOG(ERROR) << "Run get difference while applying updates from " << source;
}
postponed_updates_.emplace(
seq_begin, PendingSeqUpdates(seq_begin, seq_end, date, receive_time, std::move(updates), mpas.get_promise()));
return lock.set_value(Unit());
seq_begin, PendingSeqUpdates(seq_begin, seq_end, date, receive_time, std::move(updates), std::move(lock)));
return;
}
if (seq_begin == 0 || seq_begin == seq_ + 1) {
LOG(INFO) << "Process " << updates.size() << " updates [" << seq_begin << ", " << seq_end
<< "] with date = " << date << " from " << source;
process_seq_updates(seq_end, date, std::move(updates), mpas.get_promise());
process_seq_updates(seq_end, date, std::move(updates), std::move(lock));
process_pending_seq_updates();
return lock.set_value(Unit());
return;
}
if (seq_begin <= seq_) {
@ -1939,9 +1969,8 @@ void UpdatesManager::on_pending_updates(vector<tl_object_ptr<telegram_api::Updat
<< "Already have pending updates with seq = " << seq_begin << ", but receive it again from " << source;
pending_seq_updates_.emplace(
seq_begin, PendingSeqUpdates(seq_begin, seq_end, date, receive_time, std::move(updates), mpas.get_promise()));
seq_begin, PendingSeqUpdates(seq_begin, seq_end, date, receive_time, std::move(updates), std::move(lock)));
set_seq_gap_timeout(receive_time + MAX_UNFILLED_GAP_TIME - Time::now());
lock.set_value(Unit());
}
void UpdatesManager::on_pending_updates_processed(Result<Unit> result, Promise<Unit> promise) {
@ -1998,11 +2027,37 @@ void UpdatesManager::add_pending_qts_update(tl_object_ptr<telegram_api::Update>
void UpdatesManager::process_updates(vector<tl_object_ptr<telegram_api::Update>> &&updates, bool force_apply,
Promise<Unit> &&promise) {
tl_object_ptr<telegram_api::updatePtsChanged> update_pts_changed;
int32 update_count = 0;
for (auto &update : updates) {
if (update != nullptr) {
update_count++;
}
}
if (update_count == 0) {
return promise.set_value(Unit());
}
MultiPromiseActorSafe mpas{"OnProcessUpdatesMultiPromiseActor"};
mpas.add_promise(std::move(promise));
auto lock = mpas.get_promise();
Promise<Unit> lock;
auto use_mpas = update_count != 1;
auto get_promise = [&] {
if (use_mpas) {
return mpas.get_promise();
} else {
CHECK(update_count != 0);
update_count--;
return std::move(promise);
}
};
if (use_mpas) {
mpas.add_promise(std::move(promise));
lock = get_promise();
}
SCOPE_EXIT {
if (!use_mpas && update_count == 1) {
promise.set_value(Unit());
}
};
/*
for (auto &update : updates) {
@ -2011,29 +2066,31 @@ void UpdatesManager::process_updates(vector<tl_object_ptr<telegram_api::Update>>
// process updateReadChannelInbox before updateNewChannelMessage
auto constructor_id = update->get_id();
if (constructor_id == telegram_api::updateReadChannelInbox::ID) {
on_update(move_tl_object_as<telegram_api::updateReadChannelInbox>(update), mpas.get_promise());
on_update(move_tl_object_as<telegram_api::updateReadChannelInbox>(update), get_promise());
}
}
}
*/
tl_object_ptr<telegram_api::updatePtsChanged> update_pts_changed;
for (auto &update : updates) {
if (update != nullptr) {
// process updateNewChannelMessage first
auto constructor_id = update->get_id();
if (constructor_id == telegram_api::updateNewChannelMessage::ID) {
on_update(move_tl_object_as<telegram_api::updateNewChannelMessage>(update), mpas.get_promise());
on_update(move_tl_object_as<telegram_api::updateNewChannelMessage>(update), get_promise());
continue;
}
// process updateNewScheduledMessage first
if (constructor_id == telegram_api::updateNewScheduledMessage::ID) {
on_update(move_tl_object_as<telegram_api::updateNewScheduledMessage>(update), mpas.get_promise());
on_update(move_tl_object_as<telegram_api::updateNewScheduledMessage>(update), get_promise());
continue;
}
// updateGroupCallConnection must be processed before updateGroupCall
if (constructor_id == telegram_api::updateGroupCallConnection::ID) {
on_update(move_tl_object_as<telegram_api::updateGroupCallConnection>(update), mpas.get_promise());
on_update(move_tl_object_as<telegram_api::updateGroupCallConnection>(update), get_promise());
continue;
}
@ -2063,7 +2120,7 @@ void UpdatesManager::process_updates(vector<tl_object_ptr<telegram_api::Update>>
process_pts_update(std::move(update));
} else if (is_qts_update(update.get())) {
process_qts_update(std::move(update), 0, mpas.get_promise());
process_qts_update(std::move(update), 0, get_promise());
} else if (update->get_id() == telegram_api::updateChannelTooLong::ID) {
td_->messages_manager_->on_update_channel_too_long(
move_tl_object_as<telegram_api::updateChannelTooLong>(update), true);
@ -2074,12 +2131,12 @@ void UpdatesManager::process_updates(vector<tl_object_ptr<telegram_api::Update>>
for (auto &update : updates) {
if (update != nullptr) {
LOG(INFO) << "Process update " << to_string(update);
downcast_call(*update, OnUpdate(this, update, mpas.get_promise()));
downcast_call(*update, OnUpdate(this, update, get_promise()));
CHECK(!running_get_difference_);
}
}
if (update_pts_changed != nullptr) {
on_update(std::move(update_pts_changed), mpas.get_promise());
on_update(std::move(update_pts_changed), get_promise());
}
lock.set_value(Unit());
}
@ -2236,11 +2293,14 @@ void UpdatesManager::postpone_pts_update(tl_object_ptr<telegram_api::Update> &&u
void UpdatesManager::process_seq_updates(int32 seq_end, int32 date,
vector<tl_object_ptr<telegram_api::Update>> &&updates,
Promise<Unit> &&promise) {
string serialized_updates = PSTRING() << "process_seq_updates [seq_ = " << seq_ << ", seq_end = " << seq_end << "]: ";
// TODO remove after bugs will be fixed
for (auto &update : updates) {
if (update != nullptr) {
serialized_updates += oneline(to_string(update));
string serialized_updates;
if (date && seq_end) {
serialized_updates = PSTRING() << "process_seq_updates [seq_ = " << seq_ << ", seq_end = " << seq_end << "]: ";
// TODO remove after bugs will be fixed
for (auto &update : updates) {
if (update != nullptr) {
serialized_updates += oneline(to_string(update));
}
}
}
process_updates(std::move(updates), false, std::move(promise));
@ -3000,6 +3060,18 @@ int32 UpdatesManager::get_update_qts(const telegram_api::Update *update) {
}
}
bool UpdatesManager::is_channel_pts_update(const telegram_api::Update *update) {
switch (update->get_id()) {
case telegram_api::updateNewChannelMessage::ID:
case telegram_api::updateEditChannelMessage::ID:
case telegram_api::updateDeleteChannelMessages::ID:
case telegram_api::updatePinnedChannelMessages::ID:
return true;
default:
return false;
}
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserTyping> update, Promise<Unit> &&promise) {
DialogId dialog_id(UserId(update->user_id_));
td_->messages_manager_->on_dialog_action(dialog_id, MessageId(), dialog_id, DialogAction(std::move(update->action_)),

View File

@ -17,12 +17,12 @@
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include "td/utils/tl_storers.h"
#include "td/utils/TlStorerToString.h"
@ -357,6 +357,8 @@ class UpdatesManager final : public Actor {
static int32 get_update_qts(const telegram_api::Update *update);
static bool is_channel_pts_update(const telegram_api::Update *update);
static const vector<tl_object_ptr<telegram_api::Update>> *get_updates(const telegram_api::Updates *updates_ptr);
static vector<tl_object_ptr<telegram_api::Update>> *get_updates(telegram_api::Updates *updates_ptr);

View File

@ -13,12 +13,12 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {

View File

@ -422,6 +422,9 @@ WebPagesManager::~WebPagesManager() = default;
WebPageId WebPagesManager::on_get_web_page(tl_object_ptr<telegram_api::WebPage> &&web_page_ptr,
DialogId owner_dialog_id) {
CHECK(web_page_ptr != nullptr);
if (td_->auth_manager_->is_bot()) {
return WebPageId();
}
LOG(DEBUG) << "Got " << to_string(web_page_ptr);
switch (web_page_ptr->get_id()) {
case telegram_api::webPageEmpty::ID: {

View File

@ -16,12 +16,12 @@
#include "td/telegram/WebPageId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <utility>

View File

@ -2573,6 +2573,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::clickPremiumSubscriptionButton>());
} else if (op == "gprs") {
send_request(td_api::make_object<td_api::getPremiumState>());
} else if (op == "cppr") {
send_request(td_api::make_object<td_api::canPurchasePremium>());
} else if (op == "atos") {
send_request(td_api::make_object<td_api::acceptTermsOfService>(args));
} else if (op == "gdli") {

View File

@ -9,11 +9,10 @@
#include "td/telegram/files/FileData.h"
#include "td/telegram/files/FileDbId.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include "td/utils/tl_storers.h"

View File

@ -10,10 +10,10 @@
#include "td/telegram/files/FileStats.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/CancellationToken.h"
#include "td/utils/logging.h"
#include "td/utils/Promise.h"
namespace td {

View File

@ -9,8 +9,8 @@
#include "td/telegram/files/FileLocation.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <map>

View File

@ -17,11 +17,11 @@
#include "td/telegram/net/DcId.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/Container.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
#include <map>

View File

@ -1178,8 +1178,9 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
bool has_remote = data.remote_.type() == RemoteFileLocation::Type::Full;
bool has_generate = data.generate_ != nullptr;
if (data.local_.type() == LocalFileLocation::Type::Full && !force) {
if (file_location_source == FileLocationSource::FromBinlog ||
file_location_source == FileLocationSource::FromDatabase) {
bool is_from_database = file_location_source == FileLocationSource::FromBinlog ||
file_location_source == FileLocationSource::FromDatabase;
if (is_from_database) {
PathView path_view(data.local_.full().path_);
if (path_view.is_relative()) {
data.local_.full().path_ = PSTRING()
@ -1187,16 +1188,18 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
}
}
auto status = check_local_location(data.local_.full(), data.size_, skip_file_size_checks);
if (status.is_error()) {
LOG(INFO) << "Invalid " << data.local_.full() << ": " << status << " from " << source;
data.local_ = LocalFileLocation();
if (data.remote_.type() == RemoteFileLocation::Type::Partial) {
data.remote_ = {};
}
if (!is_from_database) {
auto status = check_local_location(data.local_.full(), data.size_, skip_file_size_checks);
if (status.is_error()) {
LOG(INFO) << "Invalid " << data.local_.full() << ": " << status << " from " << source;
data.local_ = LocalFileLocation();
if (data.remote_.type() == RemoteFileLocation::Type::Partial) {
data.remote_ = {};
}
if (!has_remote && !has_generate) {
return std::move(status);
if (!has_remote && !has_generate) {
return std::move(status);
}
}
}
}

View File

@ -21,7 +21,6 @@
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/actor/PromiseFuture.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
@ -31,6 +30,7 @@
#include "td/utils/FlatHashSet.h"
#include "td/utils/logging.h"
#include "td/utils/optional.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"

Some files were not shown because too many files have changed in this diff Show More