Skip to content

Commit

Permalink
Merge commit '1bbcc01091c8ca92f79821790b8857edb5a1b6b4'
Browse files Browse the repository at this point in the history
  • Loading branch information
cavallium committed Apr 3, 2021
2 parents efb9c6b + 1bbcc01 commit 1ce823b
Show file tree
Hide file tree
Showing 37 changed files with 262 additions and 199 deletions.
3 changes: 2 additions & 1 deletion td/mtproto/SessionConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "td/utils/format.h"
#include "td/utils/Gzip.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Random.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/Time.h"
Expand Down Expand Up @@ -863,7 +864,7 @@ void SessionConnection::flush_packet() {
max_after = HTTP_MAX_AFTER;
auto time_to_disconnect =
min(ping_disconnect_delay() + last_pong_at_, read_disconnect_delay() + last_read_at_) - Time::now_cached();
max_wait = min(http_max_wait(), static_cast<int>(1000 * max(0.1, time_to_disconnect - rtt())));
max_wait = static_cast<int>(1000 * clamp(time_to_disconnect - rtt(), 0.1, http_max_wait()));
} else if (mode_ == Mode::Http) {
max_delay = HTTP_MAX_DELAY;
max_after = HTTP_MAX_AFTER;
Expand Down
4 changes: 2 additions & 2 deletions td/mtproto/SessionConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class SessionConnection
return online_flag_ ? rtt() : 60;
}

int http_max_wait() const {
return 25 * 1000; // 25s. Longer could be closed by proxy
double http_max_wait() const {
return 25.0; // 25s. Longer could be closed by proxy
}
static constexpr int HTTP_MAX_AFTER = 10; // 0.01s
static constexpr int HTTP_MAX_DELAY = 30; // 0.03s
Expand Down
9 changes: 4 additions & 5 deletions td/telegram/AuthManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void AuthManager::check_bot_token(uint64 query_id, string bot_token) {
telegram_api::auth_importBotAuthorization(0, api_id_, api_hash_, bot_token_)));
}

void AuthManager::request_qr_code_authentication(uint64 query_id, vector<int32> other_user_ids) {
void AuthManager::request_qr_code_authentication(uint64 query_id, vector<UserId> other_user_ids) {
if (state_ != State::WaitPhoneNumber) {
if ((state_ == State::WaitCode || state_ == State::WaitPassword || state_ == State::WaitRegistration) &&
net_query_id_ == 0) {
Expand All @@ -181,8 +181,7 @@ void AuthManager::request_qr_code_authentication(uint64 query_id, vector<int32>
"Cannot request QR code authentication after bot token was entered. You need to log out first"));
}
for (auto &other_user_id : other_user_ids) {
UserId user_id(other_user_id);
if (!user_id.is_valid()) {
if (!other_user_id.is_valid()) {
return on_query_error(query_id, Status::Error(400, "Invalid user_id among other user_ids"));
}
}
Expand All @@ -200,8 +199,8 @@ void AuthManager::request_qr_code_authentication(uint64 query_id, vector<int32>
void AuthManager::send_export_login_token_query() {
poll_export_login_code_timeout_.cancel_timeout();
start_net_query(NetQueryType::RequestQrCode,
G()->net_query_creator().create_unauth(
telegram_api::auth_exportLoginToken(api_id_, api_hash_, vector<int32>(other_user_ids_))));
G()->net_query_creator().create_unauth(telegram_api::auth_exportLoginToken(
api_id_, api_hash_, UserId::get_input_user_ids(other_user_ids_))));
}

void AuthManager::set_login_token_expires_at(double login_token_expires_at) {
Expand Down
12 changes: 6 additions & 6 deletions td/telegram/AuthManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include "td/telegram/net/NetActor.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/SendCodeHelper.h"
#include "td/telegram/TermsOfService.h"

#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/TermsOfService.h"
#include "td/telegram/UserId.h"

#include "td/actor/actor.h"
#include "td/actor/Timeout.h"
Expand All @@ -38,7 +38,7 @@ class AuthManager : public NetActor {
void resend_authentication_code(uint64 query_id);
void check_code(uint64 query_id, string code);
void register_user(uint64 query_id, string first_name, string last_name);
void request_qr_code_authentication(uint64 query_id, vector<int32> other_user_ids);
void request_qr_code_authentication(uint64 query_id, vector<UserId> other_user_ids);
void check_bot_token(uint64 query_id, string bot_token);
void check_password(uint64 query_id, string password);
void request_password_recovery(uint64 query_id);
Expand Down Expand Up @@ -113,7 +113,7 @@ class AuthManager : public NetActor {
SendCodeHelper send_code_helper_;

// WaitQrCodeConfirmation
vector<int32> other_user_ids_;
vector<UserId> other_user_ids_;
string login_token_;
double login_token_expires_at_ = 0;

Expand All @@ -130,7 +130,7 @@ class AuthManager : public NetActor {
return state;
}

static DbState wait_qr_code_confirmation(int32 api_id, string api_hash, vector<int32> other_user_ids,
static DbState wait_qr_code_confirmation(int32 api_id, string api_hash, vector<UserId> other_user_ids,
string login_token, double login_token_expires_at) {
DbState state(State::WaitQrCodeConfirmation, api_id, api_hash);
state.other_user_ids_ = std::move(other_user_ids);
Expand Down Expand Up @@ -179,7 +179,7 @@ class AuthManager : public NetActor {
string code_;

// State::WaitQrCodeConfirmation
vector<int32> other_user_ids_;
vector<UserId> other_user_ids_;
string login_token_;
double login_token_expires_at_ = 0.0;
int32 imported_dc_id_ = -1;
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class TdReceiver {
if (is_locked) {
LOG(FATAL) << "Receive is called after Client destroy, or simultaneously from different threads";
}
auto response = receive_unlocked(timeout);
auto response = receive_unlocked(clamp(timeout, 0.0, 1000000.0));
is_locked = receive_lock_.exchange(false);
CHECK(is_locked);
VLOG(td_requests) << "End to wait for updates, returning object " << response.request_id << ' '
Expand Down
5 changes: 3 additions & 2 deletions td/telegram/Contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace td {

Contact::Contact(string phone_number, string first_name, string last_name, string vcard, int32 user_id)
Contact::Contact(string phone_number, string first_name, string last_name, string vcard, UserId user_id)
: phone_number_(std::move(phone_number))
, first_name_(std::move(first_name))
, last_name_(std::move(last_name))
Expand Down Expand Up @@ -96,7 +96,8 @@ Result<Contact> process_input_message_contact(tl_object_ptr<td_api::InputMessage
return Status::Error(400, "vCard must be encoded in UTF-8");
}

return Contact(contact->phone_number_, contact->first_name_, contact->last_name_, contact->vcard_, contact->user_id_);
return Contact(contact->phone_number_, contact->first_name_, contact->last_name_, contact->vcard_,
UserId(contact->user_id_));
}

} // namespace td
2 changes: 1 addition & 1 deletion td/telegram/Contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Contact {
public:
Contact() = default;

Contact(string phone_number, string first_name, string last_name, string vcard, int32 user_id);
Contact(string phone_number, string first_name, string last_name, string vcard, UserId user_id);

void set_user_id(UserId user_id);

Expand Down
29 changes: 17 additions & 12 deletions td/telegram/ContactsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5327,7 +5327,8 @@ std::pair<vector<UserId>, vector<int32>> ContactsManager::import_contacts(
td_->create_handler<ImportContactsQuery>(std::move(promise))
->send(transform(contacts,
[](const tl_object_ptr<td_api::contact> &contact) {
return Contact(contact->phone_number_, contact->first_name_, contact->last_name_, string(), 0);
return Contact(contact->phone_number_, contact->first_name_, contact->last_name_, string(),
UserId());
}),
random_id);
return {};
Expand Down Expand Up @@ -5517,7 +5518,7 @@ std::pair<vector<UserId>, vector<int32>> ContactsManager::change_imported_contac

auto new_contacts = transform(std::move(contacts), [](tl_object_ptr<td_api::contact> &&contact) {
return Contact(std::move(contact->phone_number_), std::move(contact->first_name_), std::move(contact->last_name_),
string(), 0);
string(), UserId());
});

vector<size_t> new_contacts_unique_id(new_contacts.size());
Expand Down Expand Up @@ -9571,7 +9572,8 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s

td_->group_call_manager_->on_update_dialog_about(DialogId(channel_id), channel_full->description, false);

td_->messages_manager_->on_dialog_bots_updated(DialogId(channel_id), channel_full->bot_user_ids, true);
send_closure_later(G()->messages_manager(), &MessagesManager::on_dialog_bots_updated, DialogId(channel_id),
channel_full->bot_user_ids, true);

update_channel_full(channel_full, channel_id, true);

Expand Down Expand Up @@ -9964,7 +9966,8 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id, bool
}
on_update_dialog_administrators(DialogId(chat_id), std::move(administrators), chat_full->version != -1,
from_database);
td_->messages_manager_->on_dialog_bots_updated(DialogId(chat_id), std::move(bot_user_ids), from_database);
send_closure_later(G()->messages_manager(), &MessagesManager::on_dialog_bots_updated, DialogId(chat_id),
std::move(bot_user_ids), from_database);

{
Chat *c = get_chat(chat_id);
Expand Down Expand Up @@ -11579,7 +11582,7 @@ void ContactsManager::on_get_channel_participants(
(filter.is_contacts() && !is_user_contact(participant.user_id)) ||
(filter.is_restricted() && !participant.status.is_restricted()) ||
(filter.is_banned() && !participant.status.is_banned())) {
bool skip_error = (filter.is_administrators() && is_user_deleted(participant.user_id)) ||
bool skip_error = ((filter.is_administrators() || filter.is_bots()) && is_user_deleted(participant.user_id)) ||
(filter.is_contacts() && participant.user_id == get_my_id());
if (!skip_error) {
LOG(ERROR) << "Receive " << participant << ", while searching for " << filter << " in " << channel_id
Expand Down Expand Up @@ -11749,7 +11752,7 @@ void ContactsManager::speculative_add_channel_participants(ChannelId channel_id,
return;
}

speculative_add_channel_participants(channel_id, delta_participant_count, by_me);
speculative_add_channel_participant_count(channel_id, delta_participant_count, by_me);
}

void ContactsManager::speculative_delete_channel_participant(ChannelId channel_id, UserId deleted_user_id, bool by_me) {
Expand Down Expand Up @@ -11777,18 +11780,18 @@ void ContactsManager::speculative_delete_channel_participant(ChannelId channel_i
}
}

speculative_add_channel_participants(channel_id, -1, by_me);
speculative_add_channel_participant_count(channel_id, -1, by_me);
}

void ContactsManager::speculative_add_channel_participants(ChannelId channel_id, int32 delta_participant_count,
bool by_me) {
void ContactsManager::speculative_add_channel_participant_count(ChannelId channel_id, int32 delta_participant_count,
bool by_me) {
if (by_me) {
// Currently ignore all changes made by the current user, because they may be already counted
invalidate_channel_full(channel_id, false); // just in case
return;
}

auto channel_full = get_channel_full_force(channel_id, "speculative_add_channel_participants");
auto channel_full = get_channel_full_force(channel_id, "speculative_add_channel_participant_count");
auto min_count = channel_full == nullptr ? 0 : channel_full->administrator_count;

auto c = get_channel_force(channel_id);
Expand Down Expand Up @@ -13097,7 +13100,8 @@ void ContactsManager::on_update_channel_bot_user_ids(ChannelId channel_id, vecto

auto channel_full = get_channel_full_force(channel_id, "on_update_channel_bot_user_ids");
if (channel_full == nullptr) {
td_->messages_manager_->on_dialog_bots_updated(DialogId(channel_id), std::move(bot_user_ids), false);
send_closure_later(G()->messages_manager(), &MessagesManager::on_dialog_bots_updated, DialogId(channel_id),
std::move(bot_user_ids), false);
return;
}
on_update_channel_full_bot_user_ids(channel_full, channel_id, std::move(bot_user_ids));
Expand All @@ -13108,7 +13112,8 @@ void ContactsManager::on_update_channel_full_bot_user_ids(ChannelFull *channel_f
vector<UserId> &&bot_user_ids) {
CHECK(channel_full != nullptr);
if (channel_full->bot_user_ids != bot_user_ids) {
td_->messages_manager_->on_dialog_bots_updated(DialogId(channel_id), bot_user_ids, false);
send_closure_later(G()->messages_manager(), &MessagesManager::on_dialog_bots_updated, DialogId(channel_id),
bot_user_ids, false);
channel_full->bot_user_ids = std::move(bot_user_ids);
channel_full->need_save_to_database = true;
}
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/ContactsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ class ContactsManager : public Actor {

static bool speculative_add_count(int32 &count, int32 delta_count, int32 min_count = 0);

void speculative_add_channel_participants(ChannelId channel_id, int32 delta_participant_count, bool by_me);
void speculative_add_channel_participant_count(ChannelId channel_id, int32 delta_participant_count, bool by_me);

void speculative_add_channel_user(ChannelId channel_id, UserId user_id, DialogParticipantStatus new_status,
DialogParticipantStatus old_status);
Expand Down
13 changes: 6 additions & 7 deletions td/telegram/DeviceTokenManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DeviceTokenManage
}

void DeviceTokenManager::register_device(tl_object_ptr<td_api::DeviceToken> device_token_ptr,
vector<int32> other_user_ids,
vector<UserId> other_user_ids,
Promise<td_api::object_ptr<td_api::pushReceiverId>> promise) {
CHECK(device_token_ptr != nullptr);
TokenType token_type;
Expand Down Expand Up @@ -227,8 +227,7 @@ void DeviceTokenManager::register_device(tl_object_ptr<td_api::DeviceToken> devi
return promise.set_error(Status::Error(400, "Device token must be encoded in UTF-8"));
}
for (auto &other_user_id : other_user_ids) {
UserId user_id(other_user_id);
if (!user_id.is_valid()) {
if (!other_user_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid user_id among other user_ids"));
}
}
Expand Down Expand Up @@ -373,12 +372,12 @@ void DeviceTokenManager::loop() {
auto other_user_ids = info.other_user_ids;
if (info.state == TokenInfo::State::Unregister) {
net_query = G()->net_query_creator().create(
telegram_api::account_unregisterDevice(token_type, info.token, std::move(other_user_ids)));
telegram_api::account_unregisterDevice(token_type, info.token, UserId::get_input_user_ids(other_user_ids)));
} else {
int32 flags = telegram_api::account_registerDevice::NO_MUTED_MASK;
net_query = G()->net_query_creator().create(
telegram_api::account_registerDevice(flags, false /*ignored*/, token_type, info.token, info.is_app_sandbox,
BufferSlice(info.encryption_key), std::move(other_user_ids)));
net_query = G()->net_query_creator().create(telegram_api::account_registerDevice(
flags, false /*ignored*/, token_type, info.token, info.is_app_sandbox, BufferSlice(info.encryption_key),
UserId::get_input_user_ids(other_user_ids)));
}
info.net_query_id = net_query->id();
G()->net_query_dispatcher().dispatch_with_callback(std::move(net_query), actor_shared(this, token_type));
Expand Down
6 changes: 3 additions & 3 deletions td/telegram/DeviceTokenManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "td/actor/PromiseFuture.h"

#include "td/telegram/net/NetQuery.h"

#include "td/telegram/td_api.h"
#include "td/telegram/UserId.h"

#include "td/utils/common.h"
#include "td/utils/Slice.h"
Expand All @@ -26,7 +26,7 @@ class DeviceTokenManager : public NetQueryCallback {
public:
explicit DeviceTokenManager(ActorShared<> parent) : parent_(std::move(parent)) {
}
void register_device(tl_object_ptr<td_api::DeviceToken> device_token_ptr, vector<int32> other_user_ids,
void register_device(tl_object_ptr<td_api::DeviceToken> device_token_ptr, vector<UserId> other_user_ids,
Promise<td_api::object_ptr<td_api::pushReceiverId>> promise);

void reregister_device();
Expand Down Expand Up @@ -55,7 +55,7 @@ class DeviceTokenManager : public NetQueryCallback {
State state = State::Sync;
string token;
uint64 net_query_id = 0;
vector<int32> other_user_ids;
vector<UserId> other_user_ids;
bool is_app_sandbox = false;
bool encrypt = false;
string encryption_key;
Expand Down
4 changes: 2 additions & 2 deletions td/telegram/GroupCallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,12 +1452,12 @@ void GroupCallManager::on_update_group_call_participants(
continue;
}
if (participant.joined_date == 0) {
if (version > group_call->leave_version) {
if (group_call == nullptr || version > group_call->leave_version) {
diff--;
}
remove_recent_group_call_speaker(input_group_call_id, participant.dialog_id);
} else {
if (participant.is_just_joined && version >= group_call->leave_version) {
if (participant.is_just_joined && (group_call == nullptr || version >= group_call->leave_version)) {
diff++;
}
on_participant_speaking_in_group_call(input_group_call_id, participant);
Expand Down
4 changes: 2 additions & 2 deletions td/telegram/InlineQueriesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,10 +1428,10 @@ void InlineQueriesManager::on_get_inline_query_results(UserId bot_user_id, uint6
auto inline_message_contact =
static_cast<const telegram_api::botInlineMessageMediaContact *>(result->send_message_.get());
Contact c(inline_message_contact->phone_number_, inline_message_contact->first_name_,
inline_message_contact->last_name_, inline_message_contact->vcard_, 0);
inline_message_contact->last_name_, inline_message_contact->vcard_, UserId());
contact->contact_ = c.get_contact_object();
} else {
Contact c(std::move(result->description_), std::move(result->title_), string(), string(), 0);
Contact c(std::move(result->description_), std::move(result->title_), string(), string(), UserId());
contact->contact_ = c.get_contact_object();
}
contact->thumbnail_ = register_thumbnail(std::move(result->thumb_));
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace td {
* Interface for managing the internal logging of TDLib.
* By default TDLib writes logs to stderr or an OS specific log and uses a verbosity level of 5.
* These functions are deprecated since TDLib 1.4.0 in favor of the td::td_api::setLogVerbosityLevel,
* td::td_api::setLogStream and other synchronous requests for managing the intrenal TDLib logging.
* td::td_api::setLogStream and other synchronous requests for managing the internal TDLib logging.
*/
class Log {
public:
Expand Down
Loading

0 comments on commit 1ce823b

Please sign in to comment.