Remove source from get_my_id.

GitOrigin-RevId: 623c24323b55937866841c4b0f32b109c513983b
This commit is contained in:
levlam 2018-10-08 17:21:56 +03:00
parent 1b0c7d889d
commit 2540555ae5
8 changed files with 69 additions and 72 deletions

View File

@ -891,7 +891,7 @@ void AuthManager::on_authorization(tl_object_ptr<telegram_api::auth_authorizatio
state_ = State::Ok; state_ = State::Ok;
td->contacts_manager_->on_get_user(std::move(auth->user_), true); td->contacts_manager_->on_get_user(std::move(auth->user_), true);
update_state(State::Ok, true); update_state(State::Ok, true);
if (!td->contacts_manager_->get_my_id("on_authorization").is_valid()) { if (!td->contacts_manager_->get_my_id().is_valid()) {
LOG(ERROR) << "Server doesn't send proper authorization"; LOG(ERROR) << "Server doesn't send proper authorization";
if (query_id_ != 0) { if (query_id_ != 0) {
on_query_error(Status::Error(500, "Server doesn't send proper authorization")); on_query_error(Status::Error(500, "Server doesn't send proper authorization"));

View File

@ -684,8 +684,7 @@ class UpdateProfilePhotoQuery : public Td::ResultHandler {
} }
LOG(DEBUG) << "Receive result for updateProfilePhoto " << to_string(result_ptr.ok()); LOG(DEBUG) << "Receive result for updateProfilePhoto " << to_string(result_ptr.ok());
td->contacts_manager_->on_update_user_photo(td->contacts_manager_->get_my_id("UpdateProfilePhotoQuery"), td->contacts_manager_->on_update_user_photo(td->contacts_manager_->get_my_id(), result_ptr.move_as_ok());
result_ptr.move_as_ok());
promise_.set_value(Unit()); promise_.set_value(Unit());
} }
@ -2725,7 +2724,7 @@ void ContactsManager::SecretChat::parse(ParserT &parser) {
} }
tl_object_ptr<telegram_api::InputUser> ContactsManager::get_input_user(UserId user_id) const { tl_object_ptr<telegram_api::InputUser> ContactsManager::get_input_user(UserId user_id) const {
if (user_id == get_my_id("get_input_user")) { if (user_id == get_my_id()) {
return make_tl_object<telegram_api::inputUserSelf>(); return make_tl_object<telegram_api::inputUserSelf>();
} }
@ -2741,7 +2740,7 @@ tl_object_ptr<telegram_api::InputUser> ContactsManager::get_input_user(UserId us
} }
bool ContactsManager::have_input_user(UserId user_id) const { bool ContactsManager::have_input_user(UserId user_id) const {
if (user_id == get_my_id("have_input_user")) { if (user_id == get_my_id()) {
return true; return true;
} }
@ -2769,7 +2768,7 @@ tl_object_ptr<telegram_api::InputChannel> ContactsManager::get_input_channel(Cha
} }
bool ContactsManager::have_input_peer_user(UserId user_id, AccessRights access_rights) const { bool ContactsManager::have_input_peer_user(UserId user_id, AccessRights access_rights) const {
if (user_id == get_my_id("have_input_peer_user")) { if (user_id == get_my_id()) {
return true; return true;
} }
return have_input_peer_user(get_user(user_id), access_rights); return have_input_peer_user(get_user(user_id), access_rights);
@ -2793,7 +2792,7 @@ bool ContactsManager::have_input_peer_user(const User *user, AccessRights access
tl_object_ptr<telegram_api::InputPeer> ContactsManager::get_input_peer_user(UserId user_id, tl_object_ptr<telegram_api::InputPeer> ContactsManager::get_input_peer_user(UserId user_id,
AccessRights access_rights) const { AccessRights access_rights) const {
if (user_id == get_my_id("get_input_peer_user")) { if (user_id == get_my_id()) {
return make_tl_object<telegram_api::inputPeerSelf>(); return make_tl_object<telegram_api::inputPeerSelf>();
} }
const User *u = get_user(user_id); const User *u = get_user(user_id);
@ -3054,8 +3053,8 @@ int32 ContactsManager::get_secret_chat_layer(SecretChatId secret_chat_id) const
return c->layer; return c->layer;
} }
UserId ContactsManager::get_my_id(const char *source) const { UserId ContactsManager::get_my_id() const {
LOG_IF(ERROR, !my_id_.is_valid()) << "Wrong or unknown my id returned to " << source; LOG_IF(ERROR, !my_id_.is_valid()) << "Wrong or unknown my id returned";
return my_id_; return my_id_;
} }
@ -3076,7 +3075,7 @@ void ContactsManager::set_my_id(UserId my_id) {
} }
void ContactsManager::set_my_online_status(bool is_online, bool send_update, bool is_local) { void ContactsManager::set_my_online_status(bool is_online, bool send_update, bool is_local) {
auto my_id = get_my_id("set_my_online_status"); auto my_id = get_my_id();
User *u = get_user_force(my_id); User *u = get_user_force(my_id);
if (u != nullptr) { if (u != nullptr) {
int32 new_online; int32 new_online;
@ -3127,7 +3126,7 @@ void ContactsManager::check_dialog_username(DialogId dialog_id, const string &us
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: { case DialogType::User: {
if (dialog_id.get_user_id() != get_my_id("check_dialog_username")) { if (dialog_id.get_user_id() != get_my_id()) {
return promise.set_error(Status::Error(3, "Can't check username for private chat with other user")); return promise.set_error(Status::Error(3, "Can't check username for private chat with other user"));
} }
break; break;
@ -3251,7 +3250,7 @@ void ContactsManager::disconnect_all_websites(Promise<Unit> &&promise) const {
} }
Status ContactsManager::block_user(UserId user_id) { Status ContactsManager::block_user(UserId user_id) {
if (user_id == get_my_id("block_user")) { if (user_id == get_my_id()) {
return Status::Error(5, "Can't block self"); return Status::Error(5, "Can't block self");
} }
@ -3267,7 +3266,7 @@ Status ContactsManager::block_user(UserId user_id) {
} }
Status ContactsManager::unblock_user(UserId user_id) { Status ContactsManager::unblock_user(UserId user_id) {
if (user_id == get_my_id("unblock_user")) { if (user_id == get_my_id()) {
return Status::Error(5, "Can't unblock self"); return Status::Error(5, "Can't unblock self");
} }
@ -3401,7 +3400,7 @@ int32 ContactsManager::get_contacts_hash() {
vector<int64> user_ids = contacts_hints_.search_empty(100000).second; vector<int64> user_ids = contacts_hints_.search_empty(100000).second;
CHECK(std::is_sorted(user_ids.begin(), user_ids.end())); CHECK(std::is_sorted(user_ids.begin(), user_ids.end()));
auto my_id = get_my_id("get_contacts_hash"); auto my_id = get_my_id();
const User *u = get_user_force(my_id); const User *u = get_user_force(my_id);
if (u != nullptr && u->outbound == LinkState::Contact) { if (u != nullptr && u->outbound == LinkState::Contact) {
user_ids.insert(std::upper_bound(user_ids.begin(), user_ids.end(), my_id.get()), my_id.get()); user_ids.insert(std::upper_bound(user_ids.begin(), user_ids.end(), my_id.get()), my_id.get());
@ -3725,7 +3724,7 @@ void ContactsManager::clear_imported_contacts(Promise<Unit> &&promise) {
void ContactsManager::on_update_contacts_reset() { void ContactsManager::on_update_contacts_reset() {
/* /*
UserId my_id = get_my_id("on_update_contacts_reset"); UserId my_id = get_my_id();
for (auto &p : users_) { for (auto &p : users_) {
UserId user_id = p.first; UserId user_id = p.first;
User &u = p.second; User &u = p.second;
@ -3803,8 +3802,8 @@ std::pair<int32, vector<UserId>> ContactsManager::search_contacts(const string &
} }
void ContactsManager::set_profile_photo(const tl_object_ptr<td_api::InputFile> &input_photo, Promise<Unit> &&promise) { void ContactsManager::set_profile_photo(const tl_object_ptr<td_api::InputFile> &input_photo, Promise<Unit> &&promise) {
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Photo, input_photo, auto r_file_id =
DialogId(get_my_id("set_profile_photo")), false, false); td_->file_manager_->get_input_file_id(FileType::Photo, input_photo, DialogId(get_my_id()), false, false);
if (r_file_id.is_error()) { if (r_file_id.is_error()) {
// TODO promise.set_error(std::move(status)); // TODO promise.set_error(std::move(status));
return promise.set_error(Status::Error(7, r_file_id.error().message())); return promise.set_error(Status::Error(7, r_file_id.error().message()));
@ -3829,7 +3828,7 @@ void ContactsManager::set_profile_photo(const tl_object_ptr<td_api::InputFile> &
} }
void ContactsManager::delete_profile_photo(int64 profile_photo_id, Promise<Unit> &&promise) { void ContactsManager::delete_profile_photo(int64 profile_photo_id, Promise<Unit> &&promise) {
const User *u = get_user(get_my_id("delete_profile_photo")); const User *u = get_user(get_my_id());
if (u != nullptr && u->photo.id == profile_photo_id) { if (u != nullptr && u->photo.id == profile_photo_id) {
td_->create_handler<UpdateProfilePhotoQuery>(std::move(promise)) td_->create_handler<UpdateProfilePhotoQuery>(std::move(promise))
->send(make_tl_object<telegram_api::inputPhotoEmpty>()); ->send(make_tl_object<telegram_api::inputPhotoEmpty>());
@ -3846,7 +3845,7 @@ void ContactsManager::set_name(const string &first_name, const string &last_name
return promise.set_error(Status::Error(7, "First name must be non-empty")); return promise.set_error(Status::Error(7, "First name must be non-empty"));
} }
const User *u = get_user(get_my_id("set_name")); const User *u = get_user(get_my_id());
int32 flags = 0; int32 flags = 0;
// TODO we can already send request for changing first_name and last_name and wanting to set initial values // TODO we can already send request for changing first_name and last_name and wanting to set initial values
// TODO need to be rewritten using invoke after and cancelling previous request // TODO need to be rewritten using invoke after and cancelling previous request
@ -3871,7 +3870,7 @@ void ContactsManager::set_bio(const string &bio, Promise<Unit> &&promise) {
} }
} }
const UserFull *user_full = get_user_full(get_my_id("set_bio")); const UserFull *user_full = get_user_full(get_my_id());
int32 flags = 0; int32 flags = 0;
// TODO we can already send request for changing bio and wanting to set initial values // TODO we can already send request for changing bio and wanting to set initial values
// TODO need to be rewritten using invoke after and cancelling previous request // TODO need to be rewritten using invoke after and cancelling previous request
@ -3889,7 +3888,7 @@ void ContactsManager::on_update_profile_success(int32 flags, const string &first
const string &about) { const string &about) {
CHECK(flags != 0); CHECK(flags != 0);
auto my_user_id = get_my_id("on_update_profile_success"); auto my_user_id = get_my_id();
const User *u = get_user(my_user_id); const User *u = get_user(my_user_id);
if (u == nullptr) { if (u == nullptr) {
LOG(ERROR) << "Doesn't receive info about me during update profile"; LOG(ERROR) << "Doesn't receive info about me during update profile";
@ -4096,7 +4095,7 @@ void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id,
if (!have_input_user(user_id)) { if (!have_input_user(user_id)) {
return promise.set_error(Status::Error(6, "Have no access to the user")); return promise.set_error(Status::Error(6, "Have no access to the user"));
} }
if (user_id == get_my_id("report_channel_spam")) { if (user_id == get_my_id()) {
return promise.set_error(Status::Error(6, "Can't report self")); return promise.set_error(Status::Error(6, "Can't report self"));
} }
@ -4145,7 +4144,7 @@ void ContactsManager::add_chat_participant(ChatId chat_id, UserId user_id, int32
if (forward_limit < 0) { if (forward_limit < 0) {
return promise.set_error(Status::Error(3, "Can't forward negative number of messages")); return promise.set_error(Status::Error(3, "Can't forward negative number of messages"));
} }
if (user_id != get_my_id("add_chat_participant")) { if (user_id != get_my_id()) {
if (!get_chat_status(c).can_invite_users()) { if (!get_chat_status(c).can_invite_users()) {
return promise.set_error(Status::Error(3, "Not enough rights to invite members to the group chat")); return promise.set_error(Status::Error(3, "Not enough rights to invite members to the group chat"));
} }
@ -4178,7 +4177,7 @@ void ContactsManager::add_channel_participant(ChannelId channel_id, UserId user_
return promise.set_error(Status::Error(3, "User not found")); return promise.set_error(Status::Error(3, "User not found"));
} }
if (user_id == get_my_id("add_channel_participant")) { if (user_id == get_my_id()) {
// join the channel // join the channel
if (get_channel_status(c).is_banned()) { if (get_channel_status(c).is_banned()) {
return promise.set_error(Status::Error(3, "Can't return to kicked from chat")); return promise.set_error(Status::Error(3, "Can't return to kicked from chat"));
@ -4220,7 +4219,7 @@ void ContactsManager::add_channel_participants(ChannelId channel_id, const vecto
return promise.set_error(Status::Error(3, "User not found")); return promise.set_error(Status::Error(3, "User not found"));
} }
if (user_id == get_my_id("add_channel_participants")) { if (user_id == get_my_id()) {
// can't invite self // can't invite self
continue; continue;
} }
@ -4246,7 +4245,7 @@ void ContactsManager::change_channel_participant_status(ChannelId channel_id, Us
return promise.set_error(Status::Error(6, "User not found")); return promise.set_error(Status::Error(6, "User not found"));
} }
if (user_id == get_my_id("change_channel_participant_status")) { if (user_id == get_my_id()) {
// fast path is needed, because get_channel_status may return Creator, while GetChannelParticipantQuery returning Left // fast path is needed, because get_channel_status may return Creator, while GetChannelParticipantQuery returning Left
return change_channel_participant_status_impl(channel_id, user_id, std::move(status), get_channel_status(c), return change_channel_participant_status_impl(channel_id, user_id, std::move(status), get_channel_status(c),
std::move(promise)); std::move(promise));
@ -4335,7 +4334,7 @@ void ContactsManager::promote_channel_participant(ChannelId channel_id, UserId u
const Channel *c = get_channel(channel_id); const Channel *c = get_channel(channel_id);
CHECK(c != nullptr); CHECK(c != nullptr);
if (user_id == get_my_id("change_channel_participant_status")) { if (user_id == get_my_id()) {
if (status.is_administrator()) { if (status.is_administrator()) {
return promise.set_error(Status::Error(3, "Can't promote self")); return promise.set_error(Status::Error(3, "Can't promote self"));
} }
@ -4375,7 +4374,7 @@ void ContactsManager::change_chat_participant_status(ChatId chat_id, UserId user
return promise.set_error(Status::Error(3, "Administrators editing is disabled in the group chat")); return promise.set_error(Status::Error(3, "Administrators editing is disabled in the group chat"));
} }
if (user_id == get_my_id("change_chat_participant_status")) { if (user_id == get_my_id()) {
return promise.set_error(Status::Error(3, "Can't change chat member status of self")); return promise.set_error(Status::Error(3, "Can't change chat member status of self"));
} }
@ -4481,7 +4480,7 @@ void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, Pr
if (!c->is_active) { if (!c->is_active) {
return promise.set_error(Status::Error(3, "Chat is deactivated")); return promise.set_error(Status::Error(3, "Chat is deactivated"));
} }
auto my_id = get_my_id("delete_chat_participant"); auto my_id = get_my_id();
if (c->left) { if (c->left) {
if (user_id == my_id) { if (user_id == my_id) {
return promise.set_value(Unit()); return promise.set_value(Unit());
@ -4530,7 +4529,7 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, UserId
return promise.set_error(Status::Error(3, "Chat info not found")); return promise.set_error(Status::Error(3, "Chat info not found"));
} }
if (!c->status.is_member()) { if (!c->status.is_member()) {
if (user_id == get_my_id("restrict_channel_participant")) { if (user_id == get_my_id()) {
if (status.is_member()) { if (status.is_member()) {
return promise.set_error(Status::Error(3, "Can't unrestrict self")); return promise.set_error(Status::Error(3, "Can't unrestrict self"));
} }
@ -4544,7 +4543,7 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, UserId
return promise.set_error(Status::Error(3, "User not found")); return promise.set_error(Status::Error(3, "User not found"));
} }
if (user_id == get_my_id("restrict_channel_participant")) { if (user_id == get_my_id()) {
if (status.is_restricted() || status.is_banned()) { if (status.is_restricted() || status.is_banned()) {
return promise.set_error(Status::Error(3, "Can't restrict self")); return promise.set_error(Status::Error(3, "Can't restrict self"));
} }
@ -4775,7 +4774,7 @@ void ContactsManager::on_get_contacts(tl_object_ptr<telegram_api::contacts_Conta
} }
on_get_users(std::move(contacts->users_)); on_get_users(std::move(contacts->users_));
UserId my_id = get_my_id("on_get_contacts"); UserId my_id = get_my_id();
for (auto &p : users_) { for (auto &p : users_) {
UserId user_id = p.first; UserId user_id = p.first;
User &u = p.second; User &u = p.second;
@ -6068,7 +6067,7 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
user_full->photos_offset = user_full->photo_count; user_full->photos_offset = user_full->photo_count;
} }
} }
if (u->is_status_changed && user_id != get_my_id("update_user")) { if (u->is_status_changed && user_id != get_my_id()) {
auto left_time = u->was_online - G()->server_time_cached(); auto left_time = u->was_online - G()->server_time_cached();
if (left_time >= 0 && left_time < 30 * 86400) { if (left_time >= 0 && left_time < 30 * 86400) {
left_time += 2.0; // to guarantee expiration left_time += 2.0; // to guarantee expiration
@ -6770,7 +6769,7 @@ void ContactsManager::on_update_user_online(User *u, UserId user_id, tl_object_p
u->was_online = new_online; u->was_online = new_online;
u->is_status_changed = true; u->is_status_changed = true;
if (user_id == get_my_id("on_update_user_online")) { if (user_id == get_my_id()) {
my_was_online_local_ = 0; my_was_online_local_ = 0;
if (is_offline) { if (is_offline) {
td_->on_online_updated(false, false); td_->on_online_updated(false, false);
@ -6803,7 +6802,7 @@ void ContactsManager::on_update_user_full_is_blocked(UserFull *user_full, UserId
} }
void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promise<Unit> promise) { void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promise<Unit> promise) {
UserId my_id = get_my_id("on_delete_profile_photo"); UserId my_id = get_my_id();
UserFull *user_full = get_user_full(my_id); UserFull *user_full = get_user_full(my_id);
if (user_full != nullptr) { if (user_full != nullptr) {
@ -6854,7 +6853,7 @@ void ContactsManager::on_update_user_links(UserId user_id, tl_object_ptr<telegra
} }
void ContactsManager::on_update_user_links(User *u, UserId user_id, LinkState outbound, LinkState inbound) { void ContactsManager::on_update_user_links(User *u, UserId user_id, LinkState outbound, LinkState inbound) {
UserId my_id = get_my_id("on_update_user_links"); UserId my_id = get_my_id();
if (user_id == my_id) { if (user_id == my_id) {
if (outbound == LinkState::None && !td_->auth_manager_->is_bot()) { if (outbound == LinkState::None && !td_->auth_manager_->is_bot()) {
outbound = LinkState::KnowsPhoneNumber; outbound = LinkState::KnowsPhoneNumber;
@ -7564,7 +7563,7 @@ void ContactsManager::on_update_chat_edit_administrator(ChatId chat_id, UserId u
c->version = version; c->version = version;
c->is_changed = true; c->is_changed = true;
if (user_id == get_my_id("on_update_chat_edit_administrator")) { if (user_id == get_my_id()) {
on_update_chat_rights(c, chat_id, c->is_creator, is_administrator, c->everyone_is_administrator); on_update_chat_rights(c, chat_id, c->is_creator, is_administrator, c->everyone_is_administrator);
} }
update_chat(c, chat_id); update_chat(c, chat_id);
@ -7612,7 +7611,7 @@ void ContactsManager::on_update_chat_delete_user(ChatId chat_id, UserId user_id,
repair_chat_participants(chat_id); repair_chat_participants(chat_id);
return; return;
} }
if (user_id == get_my_id("on_update_chat_delete_user")) { if (user_id == get_my_id()) {
LOG_IF(WARNING, !c->left) << "User was removed from " << chat_id LOG_IF(WARNING, !c->left) << "User was removed from " << chat_id
<< " but it is not left the group. Possible if updates comes out of order"; << " but it is not left the group. Possible if updates comes out of order";
return; return;
@ -8000,7 +7999,7 @@ void ContactsManager::on_update_channel_is_all_history_available(ChannelId chann
} }
void ContactsManager::update_contacts_hints(const User *u, UserId user_id, bool from_database) { void ContactsManager::update_contacts_hints(const User *u, UserId user_id, bool from_database) {
bool is_contact = u->outbound == LinkState::Contact && user_id != get_my_id("update_contacts_hints"); bool is_contact = u->outbound == LinkState::Contact && user_id != get_my_id();
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
LOG_IF(ERROR, is_contact) << "Bot has " << user_id << " in the contacts list"; LOG_IF(ERROR, is_contact) << "Bot has " << user_id << " in the contacts list";
return; return;
@ -8102,7 +8101,7 @@ void ContactsManager::send_get_me_query(Td *td, Promise<Unit> &&promise) {
} }
UserId ContactsManager::get_me(Promise<Unit> &&promise) { UserId ContactsManager::get_me(Promise<Unit> &&promise) {
auto my_id = get_my_id("get_me"); auto my_id = get_my_id();
if (!have_user_force(my_id)) { if (!have_user_force(my_id)) {
send_get_me_query(td_, std::move(promise)); send_get_me_query(td_, std::move(promise));
return UserId(); return UserId();
@ -8814,7 +8813,7 @@ std::pair<int32, vector<UserId>> ContactsManager::search_among_users(const vecto
const string &query, int32 limit) { const string &query, int32 limit) {
Hints hints; // TODO cache Hints Hints hints; // TODO cache Hints
UserId my_user_id = get_my_id("search_among_users"); UserId my_user_id = get_my_id();
for (auto user_id : user_ids) { for (auto user_id : user_ids) {
auto u = get_user(user_id); auto u = get_user(user_id);
if (u == nullptr) { if (u == nullptr) {
@ -9527,7 +9526,7 @@ tl_object_ptr<td_api::UserStatus> ContactsManager::get_user_status_object(UserId
} }
int32 was_online = u->was_online; int32 was_online = u->was_online;
if (user_id == get_my_id("get_user_status_object") && my_was_online_local_ != 0) { if (user_id == get_my_id() && my_was_online_local_ != 0) {
was_online = my_was_online_local_; was_online = my_was_online_local_;
} }
switch (was_online) { switch (was_online) {

View File

@ -209,7 +209,7 @@ class ContactsManager : public Actor {
void on_get_channel_full_fail(ChannelId channel_id, Status &&error); void on_get_channel_full_fail(ChannelId channel_id, Status &&error);
UserId get_my_id(const char *source) const; UserId get_my_id() const;
void set_my_online_status(bool is_online, bool send_update, bool is_local); void set_my_online_status(bool is_online, bool send_update, bool is_local);

View File

@ -1583,7 +1583,7 @@ Result<InputMessageContent> create_input_message_content(
case td_api::inputMessageGame::ID: { case td_api::inputMessageGame::ID: {
TRY_RESULT(game, process_input_message_game(td->contacts_manager_.get(), std::move(input_message_content))); TRY_RESULT(game, process_input_message_game(td->contacts_manager_.get(), std::move(input_message_content)));
via_bot_user_id = game.get_bot_user_id(); via_bot_user_id = game.get_bot_user_id();
if (via_bot_user_id == td->contacts_manager_->get_my_id("send_message")) { if (via_bot_user_id == td->contacts_manager_->get_my_id()) {
via_bot_user_id = UserId(); via_bot_user_id = UserId();
} }

View File

@ -4483,8 +4483,8 @@ bool MessagesManager::is_allowed_useless_update(const tl_object_ptr<telegram_api
auto message = static_cast<const telegram_api::updateNewMessage *>(update.get())->message_.get(); auto message = static_cast<const telegram_api::updateNewMessage *>(update.get())->message_.get();
if (message->get_id() == telegram_api::message::ID) { if (message->get_id() == telegram_api::message::ID) {
auto m = static_cast<const telegram_api::message *>(message); auto m = static_cast<const telegram_api::message *>(message);
bool is_outgoing = (m->flags_ & MESSAGE_FLAG_IS_OUT) != 0 || bool is_outgoing =
UserId(m->from_id_) == td_->contacts_manager_->get_my_id("is_allowed_useless_update"); (m->flags_ & MESSAGE_FLAG_IS_OUT) != 0 || UserId(m->from_id_) == td_->contacts_manager_->get_my_id();
if (is_outgoing && m->media_ != nullptr && m->media_->get_id() != telegram_api::messageMediaEmpty::ID) { if (is_outgoing && m->media_ != nullptr && m->media_->get_id() != telegram_api::messageMediaEmpty::ID) {
// allow outgoing media, because they are returned if random_id coincided // allow outgoing media, because they are returned if random_id coincided
return true; return true;
@ -4492,8 +4492,8 @@ bool MessagesManager::is_allowed_useless_update(const tl_object_ptr<telegram_api
} }
if (message->get_id() == telegram_api::messageService::ID) { if (message->get_id() == telegram_api::messageService::ID) {
auto m = static_cast<const telegram_api::messageService *>(message); auto m = static_cast<const telegram_api::messageService *>(message);
bool is_outgoing = (m->flags_ & MESSAGE_FLAG_IS_OUT) != 0 || bool is_outgoing =
UserId(m->from_id_) == td_->contacts_manager_->get_my_id("is_allowed_useless_update"); (m->flags_ & MESSAGE_FLAG_IS_OUT) != 0 || UserId(m->from_id_) == td_->contacts_manager_->get_my_id();
if (is_outgoing && m->action_->get_id() == telegram_api::messageActionScreenshotTaken::ID) { if (is_outgoing && m->action_->get_id() == telegram_api::messageActionScreenshotTaken::ID) {
// allow outgoing messageActionScreenshotTaken, because they are returned if random_id coincided // allow outgoing messageActionScreenshotTaken, because they are returned if random_id coincided
return true; return true;
@ -6432,7 +6432,7 @@ void MessagesManager::after_get_difference() {
load_notification_settings(); load_notification_settings();
// TODO move to ContactsManager or delete after users will become persistent // TODO move to ContactsManager or delete after users will become persistent
td_->contacts_manager_->get_user(td_->contacts_manager_->get_my_id("after_get_difference"), 3, Promise<Unit>()); td_->contacts_manager_->get_user(td_->contacts_manager_->get_my_id(), 3, Promise<Unit>());
// TODO resend some messages // TODO resend some messages
} }
@ -9263,7 +9263,7 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
bool is_silent = (flags & MESSAGE_FLAG_IS_SILENT) != 0; bool is_silent = (flags & MESSAGE_FLAG_IS_SILENT) != 0;
bool is_channel_post = (flags & MESSAGE_FLAG_IS_POST) != 0; bool is_channel_post = (flags & MESSAGE_FLAG_IS_POST) != 0;
UserId my_id = td_->contacts_manager_->get_my_id("create_message"); UserId my_id = td_->contacts_manager_->get_my_id();
DialogId my_dialog_id = DialogId(my_id); DialogId my_dialog_id = DialogId(my_id);
if (dialog_id == my_dialog_id) { if (dialog_id == my_dialog_id) {
// dialog_id should be already fixed // dialog_id should be already fixed
@ -10832,7 +10832,7 @@ vector<DialogId> MessagesManager::get_common_dialogs(UserId user_id, DialogId of
return vector<DialogId>(); return vector<DialogId>();
} }
if (user_id == td_->contacts_manager_->get_my_id("get_common_dialogs")) { if (user_id == td_->contacts_manager_->get_my_id()) {
promise.set_error(Status::Error(6, "Can't get common chats with self")); promise.set_error(Status::Error(6, "Can't get common chats with self"));
return vector<DialogId>(); return vector<DialogId>();
} }
@ -11955,7 +11955,7 @@ Status MessagesManager::close_dialog(DialogId dialog_id) {
} }
DialogId MessagesManager::get_my_dialog_id() const { DialogId MessagesManager::get_my_dialog_id() const {
return DialogId(td_->contacts_manager_->get_my_id("get_my_dialog_id")); return DialogId(td_->contacts_manager_->get_my_id());
} }
Status MessagesManager::view_messages(DialogId dialog_id, const vector<MessageId> &message_ids, bool force_read) { Status MessagesManager::view_messages(DialogId dialog_id, const vector<MessageId> &message_ids, bool force_read) {
@ -14043,7 +14043,7 @@ MessagesManager::Message *MessagesManager::get_message_to_send(Dialog *d, Messag
LOG(INFO) << "Create " << message_id << " in " << dialog_id; LOG(INFO) << "Create " << message_id << " in " << dialog_id;
auto dialog_type = dialog_id.get_type(); auto dialog_type = dialog_id.get_type();
auto my_id = td_->contacts_manager_->get_my_id("get_message_to_send"); auto my_id = td_->contacts_manager_->get_my_id();
auto m = make_unique<Message>(); auto m = make_unique<Message>();
m->random_y = get_random_y(message_id); m->random_y = get_random_y(message_id);
@ -14428,7 +14428,7 @@ bool MessagesManager::is_message_auto_read(DialogId dialog_id, bool is_outgoing)
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: { case DialogType::User: {
auto user_id = dialog_id.get_user_id(); auto user_id = dialog_id.get_user_id();
if (user_id == td_->contacts_manager_->get_my_id("is_message_auto_read")) { if (user_id == td_->contacts_manager_->get_my_id()) {
return true; return true;
} }
if (is_outgoing && td_->contacts_manager_->is_user_bot(user_id)) { if (is_outgoing && td_->contacts_manager_->is_user_bot(user_id)) {
@ -15600,7 +15600,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
return false; return false;
} }
auto my_id = td_->contacts_manager_->get_my_id("can_edit_message"); auto my_id = td_->contacts_manager_->get_my_id();
if (m->via_bot_user_id.is_valid() && m->via_bot_user_id != my_id) { if (m->via_bot_user_id.is_valid() && m->via_bot_user_id != my_id) {
return false; return false;
} }
@ -16776,7 +16776,7 @@ Result<vector<MessageId>> MessagesManager::forward_messages(DialogId to_dialog_i
vector<MessageId> forwarded_message_ids; vector<MessageId> forwarded_message_ids;
vector<unique_ptr<MessageContent>> unforwarded_message_contents(message_ids.size()); vector<unique_ptr<MessageContent>> unforwarded_message_contents(message_ids.size());
vector<bool> unforwarded_message_disable_web_page_previews(message_ids.size()); vector<bool> unforwarded_message_disable_web_page_previews(message_ids.size());
auto my_id = td_->contacts_manager_->get_my_id("forward_message"); auto my_id = td_->contacts_manager_->get_my_id();
bool need_update_dialog_pos = false; bool need_update_dialog_pos = false;
for (size_t i = 0; i < message_ids.size(); i++) { for (size_t i = 0; i < message_ids.size(); i++) {
MessageId message_id = get_persistent_message_id(from_dialog, message_ids[i]); MessageId message_id = get_persistent_message_id(from_dialog, message_ids[i]);
@ -17054,7 +17054,7 @@ Result<MessageId> MessagesManager::add_local_message(
} }
auto dialog_type = dialog_id.get_type(); auto dialog_type = dialog_id.get_type();
auto my_id = td_->contacts_manager_->get_my_id("add_local_message"); auto my_id = td_->contacts_manager_->get_my_id();
if (sender_user_id != my_id) { if (sender_user_id != my_id) {
if (dialog_type == DialogType::User && DialogId(sender_user_id) != dialog_id) { if (dialog_type == DialogType::User && DialogId(sender_user_id) != dialog_id) {
return Status::Error(400, "Wrong sender user"); return Status::Error(400, "Wrong sender user");
@ -18992,7 +18992,7 @@ DialogParticipant MessagesManager::get_dialog_participant(DialogId dialog_id, Us
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: { case DialogType::User: {
auto peer_user_id = dialog_id.get_user_id(); auto peer_user_id = dialog_id.get_user_id();
if (user_id == td_->contacts_manager_->get_my_id("get_dialog_participant")) { if (user_id == td_->contacts_manager_->get_my_id()) {
promise.set_value(Unit()); promise.set_value(Unit());
return {user_id, peer_user_id, 0, DialogParticipantStatus::Member()}; return {user_id, peer_user_id, 0, DialogParticipantStatus::Member()};
} }
@ -19011,7 +19011,7 @@ DialogParticipant MessagesManager::get_dialog_participant(DialogId dialog_id, Us
std::move(promise)); std::move(promise));
case DialogType::SecretChat: { case DialogType::SecretChat: {
auto peer_user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()); auto peer_user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
if (user_id == td_->contacts_manager_->get_my_id("get_dialog_participant")) { if (user_id == td_->contacts_manager_->get_my_id()) {
promise.set_value(Unit()); promise.set_value(Unit());
return {user_id, peer_user_id, 0, DialogParticipantStatus::Member()}; return {user_id, peer_user_id, 0, DialogParticipantStatus::Member()};
} }
@ -19080,8 +19080,8 @@ std::pair<int32, vector<DialogParticipant>> MessagesManager::search_dialog_parti
switch (dialog_id.get_type()) { switch (dialog_id.get_type()) {
case DialogType::User: case DialogType::User:
promise.set_value(Unit()); promise.set_value(Unit());
return search_private_chat_participants(td_->contacts_manager_->get_my_id("search_dialog_participants"), return search_private_chat_participants(td_->contacts_manager_->get_my_id(), dialog_id.get_user_id(), query,
dialog_id.get_user_id(), query, limit, filter); limit, filter);
case DialogType::Chat: case DialogType::Chat:
return td_->contacts_manager_->search_chat_participants(dialog_id.get_chat_id(), query, limit, filter, force, return td_->contacts_manager_->search_chat_participants(dialog_id.get_chat_id(), query, limit, filter, force,
std::move(promise)); std::move(promise));
@ -19122,8 +19122,7 @@ std::pair<int32, vector<DialogParticipant>> MessagesManager::search_dialog_parti
case DialogType::SecretChat: { case DialogType::SecretChat: {
promise.set_value(Unit()); promise.set_value(Unit());
auto peer_user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()); auto peer_user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
return search_private_chat_participants(td_->contacts_manager_->get_my_id("search_dialog_participants"), return search_private_chat_participants(td_->contacts_manager_->get_my_id(), peer_user_id, query, limit, filter);
peer_user_id, query, limit, filter);
} }
case DialogType::None: case DialogType::None:
default: default:
@ -19979,7 +19978,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
} }
} }
UserId my_user_id(td_->contacts_manager_->get_my_id("add_message_to_dialog")); UserId my_user_id(td_->contacts_manager_->get_my_id());
DialogId my_dialog_id(my_user_id); DialogId my_dialog_id(my_user_id);
if (*need_update && message_id.get() > d->last_read_inbox_message_id.get() && !td_->auth_manager_->is_bot()) { if (*need_update && message_id.get() > d->last_read_inbox_message_id.get() && !td_->auth_manager_->is_bot()) {
if (!message->is_outgoing && dialog_id != my_dialog_id) { if (!message->is_outgoing && dialog_id != my_dialog_id) {

View File

@ -5433,16 +5433,16 @@ void Td::on_request(uint64 id, td_api::setChatClientData &request) {
void Td::on_request(uint64 id, const td_api::joinChat &request) { void Td::on_request(uint64 id, const td_api::joinChat &request) {
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_dialog_participant_status(DialogId(request.chat_id_), contacts_manager_->get_my_id("joinChat"), messages_manager_->set_dialog_participant_status(DialogId(request.chat_id_), contacts_manager_->get_my_id(),
td_api::make_object<td_api::chatMemberStatusMember>(), td_api::make_object<td_api::chatMemberStatusMember>(),
std::move(promise)); std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::leaveChat &request) { void Td::on_request(uint64 id, const td_api::leaveChat &request) {
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_dialog_participant_status( messages_manager_->set_dialog_participant_status(DialogId(request.chat_id_), contacts_manager_->get_my_id(),
DialogId(request.chat_id_), contacts_manager_->get_my_id("leaveChat"), td_api::make_object<td_api::chatMemberStatusLeft>(),
td_api::make_object<td_api::chatMemberStatusLeft>(), std::move(promise)); std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::addChatMember &request) { void Td::on_request(uint64 id, const td_api::addChatMember &request) {

View File

@ -286,7 +286,7 @@ void TopDialogManager::do_get_top_dialogs(GetTopDialogsQuery &&query) {
LOG(INFO) << "Skip deleted " << user_id; LOG(INFO) << "Skip deleted " << user_id;
continue; continue;
} }
if (G()->td().get_actor_unsafe()->contacts_manager_->get_my_id("do_get_top_dialogs") == user_id) { if (G()->td().get_actor_unsafe()->contacts_manager_->get_my_id() == user_id) {
LOG(INFO) << "Skip self " << user_id; LOG(INFO) << "Skip self " << user_id;
continue; continue;
} }

View File

@ -648,9 +648,8 @@ void UpdatesManager::on_get_updates(tl_object_ptr<telegram_api::Updates> &&updat
update->flags_ ^= MessagesManager::MESSAGE_FLAG_HAS_MEDIA; update->flags_ ^= MessagesManager::MESSAGE_FLAG_HAS_MEDIA;
} }
auto from_id = update->flags_ & MessagesManager::MESSAGE_FLAG_IS_OUT auto from_id = update->flags_ & MessagesManager::MESSAGE_FLAG_IS_OUT ? td_->contacts_manager_->get_my_id().get()
? td_->contacts_manager_->get_my_id("on_get_updates").get() : update->user_id_;
: update->user_id_;
update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID; update->flags_ |= MessagesManager::MESSAGE_FLAG_HAS_FROM_ID;
on_pending_update( on_pending_update(