Fix remaining FlatHashMap usages.
This commit is contained in:
parent
10c59db842
commit
d5d4f4acf7
@ -7437,6 +7437,7 @@ void ContactsManager::check_dialog_invite_link(const string &invite_link, Promis
|
||||
return promise.set_error(Status::Error(400, "Wrong invite link"));
|
||||
}
|
||||
|
||||
CHECK(!invite_link.empty());
|
||||
td_->create_handler<CheckChatInviteQuery>(std::move(promise))->send(invite_link);
|
||||
}
|
||||
|
||||
@ -7980,7 +7981,7 @@ void ContactsManager::on_import_contacts_finished(int64 random_id, vector<UserId
|
||||
CHECK(unimported_contact_invites.size() == add_size);
|
||||
CHECK(imported_contacts_unique_id_.size() == result_size);
|
||||
|
||||
FlatHashMap<size_t, int32> unique_id_to_unimported_contact_invites;
|
||||
std::unordered_map<size_t, int32> unique_id_to_unimported_contact_invites;
|
||||
for (size_t i = 0; i < add_size; i++) {
|
||||
auto unique_id = imported_contacts_pos_[i];
|
||||
get_user_id_object(imported_contact_user_ids[i], "on_import_contacts_finished"); // to ensure updateUser
|
||||
@ -11147,7 +11148,7 @@ void ContactsManager::register_user_photo(User *u, UserId user_id, const Photo &
|
||||
CHECK(file_type == FileType::Photo);
|
||||
CHECK(u != nullptr);
|
||||
auto photo_id = photo.id.get();
|
||||
if (u->photo_ids.emplace(photo_id).second) {
|
||||
if (photo_id != 0 && u->photo_ids.emplace(photo_id).second) {
|
||||
VLOG(file_references) << "Register photo " << photo_id << " of " << user_id;
|
||||
if (user_id == get_my_id()) {
|
||||
my_photo_file_id_[photo_id] = first_file_id;
|
||||
@ -11644,7 +11645,7 @@ void ContactsManager::update_user_online_member_count(User *u) {
|
||||
|
||||
auto now = G()->unix_time_cached();
|
||||
vector<DialogId> expired_dialog_ids;
|
||||
for (auto &it : u->online_member_dialogs) {
|
||||
for (const auto &it : u->online_member_dialogs) {
|
||||
auto dialog_id = it.first;
|
||||
auto time = it.second;
|
||||
if (time < now - MessagesManager::ONLINE_MEMBER_COUNT_CACHE_EXPIRE_TIME) {
|
||||
@ -11701,6 +11702,7 @@ void ContactsManager::update_dialog_online_member_count(const vector<DialogParti
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
CHECK(dialog_id.is_valid());
|
||||
|
||||
int32 online_member_count = 0;
|
||||
int32 time = G()->unix_time();
|
||||
@ -12083,6 +12085,8 @@ bool ContactsManager::have_channel_participant_cache(ChannelId channel_id) const
|
||||
void ContactsManager::add_channel_participant_to_cache(ChannelId channel_id,
|
||||
const DialogParticipant &dialog_participant,
|
||||
bool allow_replace) {
|
||||
CHECK(channel_id.is_valid());
|
||||
CHECK(dialog_participant.is_valid());
|
||||
auto &participants = channel_participants_[channel_id];
|
||||
if (participants.participants_.empty()) {
|
||||
channel_participant_cache_timeout_.set_timeout_in(channel_id.get(), CHANNEL_PARTICIPANT_CACHE_TIME);
|
||||
@ -12748,7 +12752,7 @@ void ContactsManager::on_get_dialog_invite_link_info(const string &invite_link,
|
||||
invite_link_info = make_unique<InviteLinkInfo>();
|
||||
}
|
||||
invite_link_info->dialog_id = dialog_id;
|
||||
if (accessible_before != 0) {
|
||||
if (accessible_before != 0 && dialog_id.is_valid()) {
|
||||
auto &access = dialog_access_by_invite_link_[dialog_id];
|
||||
access.invite_links.insert(invite_link);
|
||||
if (access.accessible_before < accessible_before) {
|
||||
@ -14610,7 +14614,7 @@ const MinChannel *ContactsManager::get_min_channel(ChannelId channel_id) const {
|
||||
}
|
||||
|
||||
void ContactsManager::add_min_channel(ChannelId channel_id, const MinChannel &min_channel) {
|
||||
if (have_channel(channel_id) || have_min_channel(channel_id)) {
|
||||
if (have_channel(channel_id) || have_min_channel(channel_id) || !channel_id.is_valid()) {
|
||||
return;
|
||||
}
|
||||
min_channels_[channel_id] = td::make_unique<MinChannel>(min_channel);
|
||||
@ -15255,7 +15259,9 @@ void ContactsManager::finish_get_channel_participant(ChannelId channel_id, Dialo
|
||||
Promise<DialogParticipant> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
LOG(INFO) << "Receive a member " << dialog_participant.dialog_id_ << " of a channel " << channel_id;
|
||||
CHECK(dialog_participant.is_valid()); // checked in GetChannelParticipantQuery
|
||||
|
||||
LOG(INFO) << "Receive " << dialog_participant.dialog_id_ << " as a member of a channel " << channel_id;
|
||||
|
||||
dialog_participant.status_.update_restrictions();
|
||||
if (have_channel_participant_cache(channel_id)) {
|
||||
@ -15422,6 +15428,7 @@ void ContactsManager::on_update_dialog_administrators(DialogId dialog_id, vector
|
||||
bool have_access, bool from_database) {
|
||||
LOG(INFO) << "Update administrators in " << dialog_id << " to " << format::as_array(administrators);
|
||||
if (have_access) {
|
||||
CHECK(dialog_id.is_valid());
|
||||
std::sort(administrators.begin(), administrators.end(),
|
||||
[](const DialogAdministrator &lhs, const DialogAdministrator &rhs) {
|
||||
return lhs.get_user_id().get() < rhs.get_user_id().get();
|
||||
@ -16415,30 +16422,30 @@ void ContactsManager::get_current_state(vector<td_api::object_ptr<td_api::Update
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &it : users_) {
|
||||
for (const auto &it : users_) {
|
||||
updates.push_back(td_api::make_object<td_api::updateUser>(get_user_object(it.first, it.second.get())));
|
||||
}
|
||||
for (auto &it : channels_) {
|
||||
for (const auto &it : channels_) {
|
||||
updates.push_back(td_api::make_object<td_api::updateSupergroup>(get_supergroup_object(it.first, it.second.get())));
|
||||
}
|
||||
for (auto &it : chats_) { // chat object can contain channel_id, so it must be sent after channels
|
||||
for (const auto &it : chats_) { // chat object can contain channel_id, so it must be sent after channels
|
||||
updates.push_back(
|
||||
td_api::make_object<td_api::updateBasicGroup>(get_basic_group_object_const(it.first, it.second.get())));
|
||||
}
|
||||
for (auto &it : secret_chats_) { // secret chat object contains user_id, so it must be sent after users
|
||||
for (const auto &it : secret_chats_) { // secret chat object contains user_id, so it must be sent after users
|
||||
updates.push_back(
|
||||
td_api::make_object<td_api::updateSecretChat>(get_secret_chat_object_const(it.first, it.second.get())));
|
||||
}
|
||||
|
||||
for (auto &it : users_full_) {
|
||||
for (const auto &it : users_full_) {
|
||||
updates.push_back(td_api::make_object<td_api::updateUserFullInfo>(
|
||||
it.first.get(), get_user_full_info_object(it.first, it.second.get())));
|
||||
}
|
||||
for (auto &it : channels_full_) {
|
||||
for (const auto &it : channels_full_) {
|
||||
updates.push_back(td_api::make_object<td_api::updateSupergroupFullInfo>(
|
||||
it.first.get(), get_supergroup_full_info_object(it.second.get(), it.first)));
|
||||
}
|
||||
for (auto &it : chats_full_) {
|
||||
for (const auto &it : chats_full_) {
|
||||
updates.push_back(td_api::make_object<td_api::updateBasicGroupFullInfo>(
|
||||
it.first.get(), get_basic_group_full_info_object(it.second.get())));
|
||||
}
|
||||
|
@ -204,6 +204,10 @@ static td_api::object_ptr<td_api::ChatEventAction> get_chat_event_action_object(
|
||||
auto action = move_tl_object_as<telegram_api::channelAdminLogEventActionChangeStickerSet>(action_ptr);
|
||||
auto old_sticker_set_id = td->stickers_manager_->add_sticker_set(std::move(action->prev_stickerset_));
|
||||
auto new_sticker_set_id = td->stickers_manager_->add_sticker_set(std::move(action->new_stickerset_));
|
||||
if (!old_sticker_set_id.is_valid() || !new_sticker_set_id.is_valid()) {
|
||||
LOG(ERROR) << "Skip " << to_string(action);
|
||||
return nullptr;
|
||||
}
|
||||
return td_api::make_object<td_api::chatEventStickerSetChanged>(old_sticker_set_id.get(),
|
||||
new_sticker_set_id.get());
|
||||
}
|
||||
|
@ -6556,7 +6556,7 @@ void MessagesManager::skip_old_pending_pts_update(tl_object_ptr<telegram_api::Up
|
||||
update_sent_message->date_, update_sent_message->ttl_period_, FileId(),
|
||||
"process old updateSentMessage");
|
||||
return;
|
||||
} else {
|
||||
} else if (update_sent_message->random_id_ != 0) {
|
||||
LOG(ERROR) << "Receive awaited sent " << update_sent_message->message_id_ << " from " << source << " with pts "
|
||||
<< new_pts << " and pts_count " << pts_count << ", but current pts is " << old_pts;
|
||||
dump_debug_message_op(get_dialog(being_sent_messages_[update_sent_message->random_id_].get_dialog_id()), 3);
|
||||
@ -6580,7 +6580,7 @@ MessagesManager::Dialog *MessagesManager::get_service_notifications_dialog() {
|
||||
void MessagesManager::save_auth_notification_ids() {
|
||||
auto min_date = G()->unix_time() - AUTH_NOTIFICATION_ID_CACHE_TIME;
|
||||
vector<string> ids;
|
||||
for (auto &it : auth_notification_id_date_) {
|
||||
for (const auto &it : auth_notification_id_date_) {
|
||||
auto date = it.second;
|
||||
if (date < min_date) {
|
||||
continue;
|
||||
@ -6605,7 +6605,7 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
|
||||
LOG(ERROR) << "Receive message date " << date << " in " << to_string(update);
|
||||
return;
|
||||
}
|
||||
bool is_auth_notification = begins_with(update->type_, "auth");
|
||||
bool is_auth_notification = update->type_.size() >= 5 && begins_with(update->type_, "auth");
|
||||
if (is_auth_notification) {
|
||||
auto &old_date = auth_notification_id_date_[update->type_.substr(4)];
|
||||
if (date <= old_date) {
|
||||
@ -8123,9 +8123,9 @@ void MessagesManager::update_scope_unmute_timeout(NotificationSettingsScope scop
|
||||
auto is_muted = new_mute_until != 0;
|
||||
if (was_muted != is_muted) {
|
||||
if (G()->parameters().use_message_db) {
|
||||
FlatHashMap<DialogListId, int32, DialogListIdHash> delta;
|
||||
FlatHashMap<DialogListId, int32, DialogListIdHash> total_count;
|
||||
FlatHashMap<DialogListId, int32, DialogListIdHash> marked_count;
|
||||
std::unordered_map<DialogListId, int32, DialogListIdHash> delta;
|
||||
std::unordered_map<DialogListId, int32, DialogListIdHash> total_count;
|
||||
std::unordered_map<DialogListId, int32, DialogListIdHash> marked_count;
|
||||
std::unordered_set<DialogListId, DialogListIdHash> dialog_list_ids;
|
||||
for (auto &dialog : dialogs_) {
|
||||
Dialog *d = dialog.second.get();
|
||||
@ -13067,7 +13067,8 @@ void MessagesManager::init() {
|
||||
dialog_filters_updated_date_ = G()->ignore_background_updates() ? 0 : log_event.updated_date;
|
||||
std::unordered_set<DialogFilterId, DialogFilterIdHash> server_dialog_filter_ids;
|
||||
for (auto &dialog_filter : log_event.server_dialog_filters_out) {
|
||||
if (server_dialog_filter_ids.insert(dialog_filter->dialog_filter_id).second) {
|
||||
if (dialog_filter->dialog_filter_id.is_valid() &&
|
||||
server_dialog_filter_ids.insert(dialog_filter->dialog_filter_id).second) {
|
||||
server_dialog_filters_.push_back(std::move(dialog_filter));
|
||||
}
|
||||
}
|
||||
@ -13169,6 +13170,10 @@ void MessagesManager::init() {
|
||||
CHECK(list->pinned_dialogs_.empty());
|
||||
for (auto &r_dialog_id : reversed(r_dialog_ids)) {
|
||||
auto dialog_id = r_dialog_id.move_as_ok();
|
||||
if (!dialog_id.is_valid()) {
|
||||
LOG(ERROR) << "Loaded " << dialog_id << " as a pinned dialog";
|
||||
continue;
|
||||
}
|
||||
auto order = get_next_pinned_dialog_order();
|
||||
list->pinned_dialogs_.emplace_back(order, dialog_id);
|
||||
list->pinned_dialog_id_orders_.emplace(dialog_id, order);
|
||||
@ -13280,7 +13285,7 @@ void MessagesManager::init() {
|
||||
auto min_date = G()->unix_time() - AUTH_NOTIFICATION_ID_CACHE_TIME;
|
||||
for (size_t i = 0; i < ids.size(); i += 2) {
|
||||
auto date = to_integer_safe<int32>(ids[i + 1]).ok();
|
||||
if (date < min_date) {
|
||||
if (date < min_date || ids[i].empty()) {
|
||||
is_changed = true;
|
||||
continue;
|
||||
}
|
||||
@ -15109,7 +15114,7 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
|
||||
|
||||
if (from_get_dialog && dialog_folders.size() == 1 && dialog_folders[0]->get_id() == telegram_api::dialog::ID) {
|
||||
DialogId dialog_id(static_cast<const telegram_api::dialog *>(dialog_folders[0].get())->peer_);
|
||||
if (running_get_channel_difference(dialog_id)) {
|
||||
if (dialog_id.is_valid() && running_get_channel_difference(dialog_id)) {
|
||||
LOG(INFO) << "Postpone result of channels getDialogs for " << dialog_id;
|
||||
pending_channel_on_get_dialogs_.emplace(
|
||||
dialog_id, PendingOnGetDialogs{folder_id, std::move(dialog_folders), total_count, std::move(messages),
|
||||
@ -15154,6 +15159,9 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
|
||||
FlatHashMap<FullMessageId, tl_object_ptr<telegram_api::Message>, FullMessageIdHash> full_message_id_to_message;
|
||||
for (auto &message : messages) {
|
||||
auto full_message_id = get_full_message_id(message, false);
|
||||
if (!full_message_id.get_message_id().is_valid()) {
|
||||
continue;
|
||||
}
|
||||
if (from_dialog_list) {
|
||||
auto message_date = get_message_date(message);
|
||||
int64 order = get_dialog_order(full_message_id.get_message_id(), message_date);
|
||||
@ -15316,10 +15324,11 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
|
||||
bool has_pts = (dialog->flags_ & DIALOG_FLAG_HAS_PTS) != 0;
|
||||
if (last_message_id.is_valid()) {
|
||||
FullMessageId full_message_id(dialog_id, last_message_id);
|
||||
auto last_message = std::move(full_message_id_to_message[full_message_id]);
|
||||
if (last_message == nullptr) {
|
||||
auto it = full_message_id_to_message.find(full_message_id);
|
||||
if (it == full_message_id_to_message.end()) {
|
||||
LOG(ERROR) << "Last " << full_message_id << " not found";
|
||||
} else if (!has_pts || d->pts == 0 || dialog->pts_ <= d->pts || d->is_channel_difference_finished) {
|
||||
auto last_message = std::move(it->second);
|
||||
auto added_full_message_id =
|
||||
on_get_message(std::move(last_message), false, has_pts, false, false, false, "get chats");
|
||||
CHECK(d->last_new_message_id == MessageId());
|
||||
@ -17195,6 +17204,7 @@ vector<DialogId> MessagesManager::search_public_dialogs(const string &query, Pro
|
||||
}
|
||||
|
||||
void MessagesManager::send_search_public_dialogs_query(const string &query, Promise<Unit> &&promise) {
|
||||
CHECK(!query.empty());
|
||||
auto &promises = search_public_dialogs_queries_[query];
|
||||
promises.push_back(std::move(promise));
|
||||
if (promises.size() != 1) {
|
||||
@ -17376,6 +17386,7 @@ std::pair<int32, vector<DialogId>> MessagesManager::get_common_dialogs(UserId us
|
||||
|
||||
void MessagesManager::on_get_common_dialogs(UserId user_id, int64 offset_chat_id,
|
||||
vector<tl_object_ptr<telegram_api::Chat>> &&chats, int32 total_count) {
|
||||
CHECK(user_id.is_valid());
|
||||
td_->contacts_manager_->on_update_user_common_chat_count(user_id, total_count);
|
||||
|
||||
auto &common_dialogs = found_common_dialogs_[user_id];
|
||||
@ -18289,7 +18300,7 @@ void MessagesManager::get_messages_from_server(vector<FullMessageId> &&message_i
|
||||
auto dialog_id = full_message_id.get_dialog_id();
|
||||
auto message_id = full_message_id.get_message_id();
|
||||
if (!message_id.is_valid() || !message_id.is_server()) {
|
||||
if (message_id.is_valid_scheduled() && message_id.is_scheduled_server()) {
|
||||
if (message_id.is_valid_scheduled() && message_id.is_scheduled_server() && dialog_id.is_valid()) {
|
||||
scheduled_message_ids[dialog_id].push_back(message_id.get_scheduled_server_message_id().get());
|
||||
}
|
||||
continue;
|
||||
@ -19119,6 +19130,9 @@ void MessagesManager::add_dialog_filter(unique_ptr<DialogFilter> dialog_filter,
|
||||
|
||||
for (const auto &input_dialog_id : reversed(dialog_filters_.back()->pinned_dialog_ids)) {
|
||||
auto dialog_id = input_dialog_id.get_dialog_id();
|
||||
if (!dialog_id.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
auto order = get_next_pinned_dialog_order();
|
||||
list.pinned_dialogs_.emplace_back(order, dialog_id);
|
||||
list.pinned_dialog_id_orders_.emplace(dialog_id, order);
|
||||
@ -19163,6 +19177,9 @@ void MessagesManager::edit_dialog_filter(unique_ptr<DialogFilter> new_dialog_fil
|
||||
auto old_it = old_list.pinned_dialogs_.rbegin();
|
||||
for (const auto &input_dialog_id : reversed(new_dialog_filter->pinned_dialog_ids)) {
|
||||
auto dialog_id = input_dialog_id.get_dialog_id();
|
||||
if (!dialog_id.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
while (old_it < old_list.pinned_dialogs_.rend()) {
|
||||
if (old_it->get_dialog_id() == dialog_id) {
|
||||
break;
|
||||
@ -27871,8 +27888,8 @@ Result<MessagesManager::ForwardedMessages> MessagesManager::get_forwarded_messag
|
||||
auto &copied_messages = result.copied_messages;
|
||||
auto &forwarded_message_contents = result.forwarded_message_contents;
|
||||
|
||||
FlatHashMap<int64, std::pair<int64, int32>> new_copied_media_album_ids;
|
||||
FlatHashMap<int64, std::pair<int64, int32>> new_forwarded_media_album_ids;
|
||||
std::unordered_map<int64, std::pair<int64, int32>> new_copied_media_album_ids;
|
||||
std::unordered_map<int64, std::pair<int64, int32>> new_forwarded_media_album_ids;
|
||||
|
||||
for (size_t i = 0; i < message_ids.size(); i++) {
|
||||
MessageId message_id = get_persistent_message_id(from_dialog, message_ids[i]);
|
||||
@ -28138,7 +28155,7 @@ Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, v
|
||||
}
|
||||
|
||||
vector<unique_ptr<MessageContent>> new_contents(message_ids.size());
|
||||
FlatHashMap<int64, std::pair<int64, int32>> new_media_album_ids;
|
||||
std::unordered_map<int64, std::pair<int64, int32>> new_media_album_ids;
|
||||
for (size_t i = 0; i < message_ids.size(); i++) {
|
||||
MessageId message_id = message_ids[i];
|
||||
const Message *m = get_message(d, message_id);
|
||||
@ -28522,11 +28539,9 @@ void MessagesManager::upload_imported_messages(DialogId dialog_id, FileId file_i
|
||||
bool is_reupload, Promise<Unit> &&promise, vector<int> bad_parts) {
|
||||
CHECK(file_id.is_valid());
|
||||
LOG(INFO) << "Ask to upload imported messages file " << file_id;
|
||||
bool is_inserted =
|
||||
being_uploaded_imported_messages_
|
||||
.emplace(file_id, td::make_unique<UploadedImportedMessagesInfo>(dialog_id, std::move(attached_file_ids),
|
||||
is_reupload, std::move(promise)))
|
||||
.second;
|
||||
auto info = td::make_unique<UploadedImportedMessagesInfo>(dialog_id, std::move(attached_file_ids), is_reupload,
|
||||
std::move(promise));
|
||||
bool is_inserted = being_uploaded_imported_messages_.emplace(file_id, std::move(info)).second;
|
||||
CHECK(is_inserted);
|
||||
// TODO use force_reupload if is_reupload
|
||||
td_->file_manager_->resume_upload(file_id, std::move(bad_parts), upload_imported_messages_callback_, 1, 0, false,
|
||||
@ -28570,11 +28585,10 @@ void MessagesManager::upload_imported_message_attachment(DialogId dialog_id, int
|
||||
vector<int> bad_parts) {
|
||||
CHECK(file_id.is_valid());
|
||||
LOG(INFO) << "Ask to upload improted message attached file " << file_id;
|
||||
CHECK(being_uploaded_imported_message_attachments_.find(file_id) ==
|
||||
being_uploaded_imported_message_attachments_.end());
|
||||
being_uploaded_imported_message_attachments_.emplace(
|
||||
file_id,
|
||||
td::make_unique<UploadedImportedMessageAttachmentInfo>(dialog_id, import_id, is_reupload, std::move(promise)));
|
||||
auto info =
|
||||
td::make_unique<UploadedImportedMessageAttachmentInfo>(dialog_id, import_id, is_reupload, std::move(promise));
|
||||
bool is_inserted = being_uploaded_imported_message_attachments_.emplace(file_id, std::move(info)).second;
|
||||
CHECK(is_inserted);
|
||||
// TODO use force_reupload if is_reupload
|
||||
td_->file_manager_->resume_upload(file_id, std::move(bad_parts), upload_imported_message_attachment_callback_, 1, 0,
|
||||
false, true);
|
||||
@ -28932,11 +28946,7 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat
|
||||
}
|
||||
}
|
||||
|
||||
LOG_CHECK(d->message_notification_group.group_id == group_id || d->mention_notification_group.group_id == group_id)
|
||||
<< group_id << " " << d->message_notification_group.group_id << " " << d->mention_notification_group.group_id
|
||||
<< " " << d->dialog_id << " " << notification_group_id_to_dialog_id_[group_id] << " "
|
||||
<< notification_group_id_to_dialog_id_[d->message_notification_group.group_id] << " "
|
||||
<< notification_group_id_to_dialog_id_[d->mention_notification_group.group_id];
|
||||
LOG_CHECK(d->message_notification_group.group_id == group_id || d->mention_notification_group.group_id == group_id);
|
||||
|
||||
bool from_mentions = d->mention_notification_group.group_id == group_id;
|
||||
auto &group_info = from_mentions ? d->mention_notification_group : d->message_notification_group;
|
||||
@ -29206,6 +29216,7 @@ vector<NotificationGroupKey> MessagesManager::get_message_notification_group_key
|
||||
|
||||
vector<NotificationGroupKey> result;
|
||||
for (auto &group_key : group_keys) {
|
||||
CHECK(group_key.group_id.is_valid());
|
||||
CHECK(group_key.dialog_id.is_valid());
|
||||
const Dialog *d = get_dialog_force(group_key.dialog_id, "get_message_notification_group_keys_from_database");
|
||||
if (d == nullptr || (d->message_notification_group.group_id != group_key.group_id &&
|
||||
@ -32388,7 +32399,10 @@ void MessagesManager::on_dialog_username_updated(DialogId dialog_id, const strin
|
||||
if (!new_username.empty()) {
|
||||
auto cache_time = is_update_about_username_change_received(dialog_id) ? USERNAME_CACHE_EXPIRE_TIME
|
||||
: USERNAME_CACHE_EXPIRE_TIME_SHORT;
|
||||
resolved_usernames_[clean_username(new_username)] = ResolvedUsername{dialog_id, Time::now() + cache_time};
|
||||
auto cleaned_username = clean_username(new_username);
|
||||
if (!cleaned_username.empty()) {
|
||||
resolved_usernames_[cleaned_username] = ResolvedUsername{dialog_id, Time::now() + cache_time};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32398,14 +32412,19 @@ void MessagesManager::on_resolved_username(const string &username, DialogId dial
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = resolved_usernames_.find(clean_username(username));
|
||||
auto cleaned_username = clean_username(username);
|
||||
if (cleaned_username.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = resolved_usernames_.find(cleaned_username);
|
||||
if (it != resolved_usernames_.end()) {
|
||||
LOG_IF(ERROR, it->second.dialog_id != dialog_id)
|
||||
<< "Resolve username \"" << username << "\" to " << dialog_id << ", but have it in " << it->second.dialog_id;
|
||||
return;
|
||||
}
|
||||
|
||||
inaccessible_resolved_usernames_[clean_username(username)] = dialog_id;
|
||||
inaccessible_resolved_usernames_[cleaned_username] = dialog_id;
|
||||
}
|
||||
|
||||
void MessagesManager::drop_username(const string &username) {
|
||||
@ -36589,8 +36608,8 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen
|
||||
}
|
||||
|
||||
void MessagesManager::update_dialog_lists(
|
||||
Dialog *d, FlatHashMap<DialogListId, DialogPositionInList, DialogListIdHash> &&old_positions, bool need_send_update,
|
||||
bool is_loaded_from_database, const char *source) {
|
||||
Dialog *d, std::unordered_map<DialogListId, DialogPositionInList, DialogListIdHash> &&old_positions,
|
||||
bool need_send_update, bool is_loaded_from_database, const char *source) {
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
@ -37188,10 +37207,10 @@ MessagesManager::DialogPositionInList MessagesManager::get_dialog_position_in_li
|
||||
return position;
|
||||
}
|
||||
|
||||
FlatHashMap<DialogListId, MessagesManager::DialogPositionInList, DialogListIdHash>
|
||||
std::unordered_map<DialogListId, MessagesManager::DialogPositionInList, DialogListIdHash>
|
||||
MessagesManager::get_dialog_positions(const Dialog *d) const {
|
||||
CHECK(d != nullptr);
|
||||
FlatHashMap<DialogListId, MessagesManager::DialogPositionInList, DialogListIdHash> positions;
|
||||
std::unordered_map<DialogListId, MessagesManager::DialogPositionInList, DialogListIdHash> positions;
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
for (const auto &dialog_list : dialog_lists_) {
|
||||
positions.emplace(dialog_list.first, get_dialog_position_in_list(&dialog_list.second, d));
|
||||
@ -37674,6 +37693,9 @@ void MessagesManager::on_get_channel_dialog(DialogId dialog_id, MessageId last_m
|
||||
FlatHashMap<FullMessageId, tl_object_ptr<telegram_api::Message>, FullMessageIdHash> full_message_id_to_message;
|
||||
for (auto &message : messages) {
|
||||
auto message_id = get_message_id(message, false);
|
||||
if (!message_id.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
auto message_dialog_id = get_message_dialog_id(message);
|
||||
if (!message_dialog_id.is_valid()) {
|
||||
message_dialog_id = dialog_id;
|
||||
@ -37736,8 +37758,11 @@ void MessagesManager::on_get_channel_dialog(DialogId dialog_id, MessageId last_m
|
||||
d->last_new_message_id = MessageId();
|
||||
set_dialog_last_message_id(d, MessageId(), "on_get_channel_dialog 20");
|
||||
send_update_chat_last_message(d, "on_get_channel_dialog 30");
|
||||
auto added_full_message_id = on_get_message(std::move(full_message_id_to_message[last_full_message_id]), true, true,
|
||||
false, true, true, "channel difference too long");
|
||||
FullMessageId added_full_message_id;
|
||||
if (last_full_message_id.get_message_id().is_valid()) {
|
||||
last_full_message_id = on_get_message(std::move(full_message_id_to_message[last_full_message_id]), true, true,
|
||||
false, true, true, "channel difference too long");
|
||||
}
|
||||
if (added_full_message_id.get_message_id().is_valid()) {
|
||||
if (added_full_message_id.get_message_id() == d->last_new_message_id) {
|
||||
CHECK(last_full_message_id == added_full_message_id);
|
||||
@ -39101,6 +39126,11 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
||||
log_event_parse(log_event, event.data_).ensure();
|
||||
|
||||
DialogId dialog_id(log_event.channel_id);
|
||||
if (dialog_id.get_type() != DialogType::Channel) {
|
||||
LOG(ERROR) << "Trying to run GetChannelDifference in " << dialog_id;
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
break;
|
||||
}
|
||||
LOG(INFO) << "Continue to run getChannelDifference in " << dialog_id;
|
||||
get_channel_difference_to_log_event_id_.emplace(dialog_id, event.id_);
|
||||
do_get_channel_difference(
|
||||
@ -39528,7 +39558,7 @@ void MessagesManager::get_current_state(vector<td_api::object_ptr<td_api::Update
|
||||
}
|
||||
|
||||
vector<td_api::object_ptr<td_api::Update>> last_message_updates;
|
||||
for (auto &it : dialogs_) {
|
||||
for (const auto &it : dialogs_) {
|
||||
const Dialog *d = it.second.get();
|
||||
auto update = td_api::make_object<td_api::updateNewChat>(get_chat_object(d));
|
||||
if (update->chat_->last_message_ != nullptr && update->chat_->last_message_->forward_info_ != nullptr) {
|
||||
|
@ -79,6 +79,7 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
@ -1231,7 +1232,7 @@ class MessagesManager final : public Actor {
|
||||
unique_ptr<DialogActionBar> action_bar;
|
||||
LogEventIdWithGeneration save_draft_message_log_event_id;
|
||||
LogEventIdWithGeneration save_notification_settings_log_event_id;
|
||||
FlatHashMap<int64, LogEventIdWithGeneration> read_history_log_event_ids;
|
||||
std::unordered_map<int64, LogEventIdWithGeneration> read_history_log_event_ids;
|
||||
std::unordered_set<MessageId, MessageIdHash> updated_read_history_message_ids;
|
||||
LogEventIdWithGeneration set_folder_id_log_event_id;
|
||||
InputGroupCallId active_group_call_id;
|
||||
@ -1324,11 +1325,11 @@ class MessagesManager final : public Actor {
|
||||
bool suffix_load_done_ = false;
|
||||
bool suffix_load_has_query_ = false;
|
||||
|
||||
int32 pts = 0; // for channels only
|
||||
int32 pending_read_channel_inbox_pts = 0; // for channels only
|
||||
int32 pending_read_channel_inbox_server_unread_count = 0; // for channels only
|
||||
MessageId pending_read_channel_inbox_max_message_id; // for channels only
|
||||
FlatHashMap<int64, MessageId> random_id_to_message_id; // for secret chats only
|
||||
int32 pts = 0; // for channels only
|
||||
int32 pending_read_channel_inbox_pts = 0; // for channels only
|
||||
int32 pending_read_channel_inbox_server_unread_count = 0; // for channels only
|
||||
MessageId pending_read_channel_inbox_max_message_id; // for channels only
|
||||
std::unordered_map<int64, MessageId> random_id_to_message_id; // for secret chats only
|
||||
|
||||
MessageId last_assigned_message_id; // identifier of the last local or yet unsent message, assigned after
|
||||
// application start, used to guarantee that all assigned message identifiers
|
||||
@ -2773,7 +2774,7 @@ class MessagesManager final : public Actor {
|
||||
|
||||
DialogPositionInList get_dialog_position_in_list(const DialogList *list, const Dialog *d, bool actual = false) const;
|
||||
|
||||
FlatHashMap<DialogListId, DialogPositionInList, DialogListIdHash> get_dialog_positions(const Dialog *d) const;
|
||||
std::unordered_map<DialogListId, DialogPositionInList, DialogListIdHash> get_dialog_positions(const Dialog *d) const;
|
||||
|
||||
static vector<DialogListId> get_dialog_list_ids(const Dialog *d);
|
||||
|
||||
@ -3020,7 +3021,8 @@ class MessagesManager final : public Actor {
|
||||
bool set_dialog_order(Dialog *d, int64 new_order, bool need_send_update, bool is_loaded_from_database,
|
||||
const char *source);
|
||||
|
||||
void update_dialog_lists(Dialog *d, FlatHashMap<DialogListId, DialogPositionInList, DialogListIdHash> &&old_positions,
|
||||
void update_dialog_lists(Dialog *d,
|
||||
std::unordered_map<DialogListId, DialogPositionInList, DialogListIdHash> &&old_positions,
|
||||
bool need_send_update, bool is_loaded_from_database, const char *source);
|
||||
|
||||
void update_last_dialog_date(FolderId folder_id);
|
||||
@ -3495,8 +3497,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
int64 current_pinned_dialog_order_ = static_cast<int64>(MIN_PINNED_DIALOG_DATE) << 32;
|
||||
|
||||
FlatHashMap<DialogListId, DialogList, DialogListIdHash> dialog_lists_;
|
||||
FlatHashMap<FolderId, DialogFolder, FolderIdHash> dialog_folders_;
|
||||
std::unordered_map<DialogListId, DialogList, DialogListIdHash> dialog_lists_;
|
||||
std::unordered_map<FolderId, DialogFolder, FolderIdHash> dialog_folders_;
|
||||
|
||||
bool are_dialog_filters_being_synchronized_ = false;
|
||||
bool are_dialog_filters_being_reloaded_ = false;
|
||||
|
@ -1358,6 +1358,7 @@ void StickersManager::reload_reactions() {
|
||||
}
|
||||
|
||||
StickersManager::SpecialStickerSet &StickersManager::add_special_sticker_set(const SpecialStickerSetType &type) {
|
||||
CHECK(!type.is_empty());
|
||||
auto &result = special_sticker_sets_[type];
|
||||
if (result.type_.is_empty()) {
|
||||
result.type_ = type;
|
||||
@ -1403,7 +1404,9 @@ void StickersManager::load_special_sticker_set_info_from_binlog(SpecialStickerSe
|
||||
}
|
||||
|
||||
add_sticker_set(sticker_set.id_, sticker_set.access_hash_);
|
||||
short_name_to_sticker_set_id_.emplace(sticker_set.short_name_, sticker_set.id_);
|
||||
if (!sticker_set.short_name_.empty()) {
|
||||
short_name_to_sticker_set_id_.emplace(sticker_set.short_name_, sticker_set.id_);
|
||||
}
|
||||
}
|
||||
|
||||
void StickersManager::load_special_sticker_set_by_type(SpecialStickerSetType type) {
|
||||
@ -2379,6 +2382,9 @@ StickerSetId StickersManager::add_sticker_set(tl_object_ptr<telegram_api::InputS
|
||||
}
|
||||
|
||||
StickersManager::StickerSet *StickersManager::add_sticker_set(StickerSetId sticker_set_id, int64 access_hash) {
|
||||
if (!sticker_set_id.is_valid()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto &s = sticker_sets_[sticker_set_id];
|
||||
if (s == nullptr) {
|
||||
s = make_unique<StickerSet>();
|
||||
@ -2795,6 +2801,9 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
|
||||
CHECK(set != nullptr);
|
||||
StickerSetId set_id{set->id_};
|
||||
StickerSet *s = add_sticker_set(set_id, set->access_hash_);
|
||||
if (s == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool is_installed = (set->flags_ & telegram_api::stickerSet::INSTALLED_DATE_MASK) != 0;
|
||||
bool is_archived = set->archived_;
|
||||
@ -2907,7 +2916,10 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
|
||||
LOG_IF(ERROR, s->is_masks != is_masks) << "Masks type of " << set_id << "/" << s->short_name << " has changed from "
|
||||
<< s->is_masks << " to " << is_masks << " from " << source;
|
||||
}
|
||||
short_name_to_sticker_set_id_.emplace(clean_username(s->short_name), set_id);
|
||||
auto cleaned_username = clean_username(s->short_name);
|
||||
if (!cleaned_username.empty()) {
|
||||
short_name_to_sticker_set_id_.emplace(cleaned_username, set_id);
|
||||
}
|
||||
|
||||
on_update_sticker_set(s, is_installed, is_archived, is_changed);
|
||||
|
||||
@ -3063,10 +3075,13 @@ StickerSetId StickersManager::on_get_messages_sticker_set(StickerSetId sticker_s
|
||||
stickers.push_back(it->second);
|
||||
s->sticker_emojis_map_[it->second].push_back(pack->emoticon_);
|
||||
}
|
||||
auto &sticker_ids = s->emoji_stickers_map_[remove_emoji_modifiers(pack->emoticon_).str()];
|
||||
for (auto sticker_id : stickers) {
|
||||
if (!td::contains(sticker_ids, sticker_id)) {
|
||||
sticker_ids.push_back(sticker_id);
|
||||
auto cleaned_emoji = remove_emoji_modifiers(pack->emoticon_).str();
|
||||
if (!cleaned_emoji.empty()) {
|
||||
auto &sticker_ids = s->emoji_stickers_map_[cleaned_emoji];
|
||||
for (auto sticker_id : stickers) {
|
||||
if (!td::contains(sticker_ids, sticker_id)) {
|
||||
sticker_ids.push_back(sticker_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4086,7 +4101,8 @@ void StickersManager::load_sticker_sets(vector<StickerSetId> &&sticker_set_ids,
|
||||
return;
|
||||
}
|
||||
|
||||
auto load_request_id = current_sticker_set_load_request_++;
|
||||
CHECK(current_sticker_set_load_request_ < std::numeric_limits<uint32>::max());
|
||||
auto load_request_id = ++current_sticker_set_load_request_;
|
||||
StickerSetLoadRequest &load_request = sticker_set_load_requests_[load_request_id];
|
||||
load_request.promise = std::move(promise);
|
||||
load_request.left_queries = sticker_set_ids.size();
|
||||
@ -4120,7 +4136,8 @@ void StickersManager::load_sticker_sets_without_stickers(vector<StickerSetId> &&
|
||||
return;
|
||||
}
|
||||
|
||||
auto load_request_id = current_sticker_set_load_request_++;
|
||||
CHECK(current_sticker_set_load_request_ < std::numeric_limits<uint32>::max());
|
||||
auto load_request_id = ++current_sticker_set_load_request_;
|
||||
StickerSetLoadRequest &load_request = sticker_set_load_requests_[load_request_id];
|
||||
load_request.promise = std::move(promise);
|
||||
load_request.left_queries = sticker_set_ids.size();
|
||||
@ -4369,8 +4386,11 @@ void StickersManager::on_update_emoji_sounds() {
|
||||
FullRemoteFileLocation(FileType::VoiceNote, id, access_hash, dc_id, std::move(file_reference)),
|
||||
FileLocationSource::FromServer, DialogId(), 0, expected_size, std::move(suggested_file_name));
|
||||
CHECK(file_id.is_valid());
|
||||
emoji_sounds_.emplace(remove_fitzpatrick_modifier(sounds[i]).str(), file_id);
|
||||
new_file_ids.push_back(file_id);
|
||||
auto cleaned_emoji = remove_fitzpatrick_modifier(sounds[i]).str();
|
||||
if (!cleaned_emoji.empty()) {
|
||||
emoji_sounds_.emplace(cleaned_emoji, file_id);
|
||||
new_file_ids.push_back(file_id);
|
||||
}
|
||||
}
|
||||
td_->file_manager_->change_files_source(get_app_config_file_source_id(), old_file_ids, new_file_ids);
|
||||
|
||||
@ -5478,6 +5498,7 @@ void StickersManager::send_get_attached_stickers_query(FileId file_id, Promise<U
|
||||
|
||||
void StickersManager::on_get_attached_sticker_sets(
|
||||
FileId file_id, vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets) {
|
||||
CHECK(file_id.is_valid());
|
||||
vector<StickerSetId> &sticker_set_ids = attached_sticker_sets_[file_id];
|
||||
sticker_set_ids.clear();
|
||||
for (auto &sticker_set_covered : sticker_sets) {
|
||||
@ -5867,6 +5888,7 @@ void StickersManager::upload_sticker_file(UserId user_id, FileId file_id, Promis
|
||||
upload_file_id = td_->documents_manager_->dup_document(td_->file_manager_->dup_file_id(file_id), file_id);
|
||||
}
|
||||
|
||||
CHECK(upload_file_id.is_valid());
|
||||
being_uploaded_files_[upload_file_id] = {user_id, std::move(promise)};
|
||||
LOG(INFO) << "Ask to upload sticker file " << upload_file_id;
|
||||
td_->file_manager_->upload(upload_file_id, upload_sticker_file_callback_, 2, 0);
|
||||
@ -7136,6 +7158,9 @@ int32 StickersManager::get_emoji_language_code_version(const string &language_co
|
||||
if (it != emoji_language_code_versions_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
if (language_code.empty()) {
|
||||
return 0;
|
||||
}
|
||||
auto &result = emoji_language_code_versions_[language_code];
|
||||
result = to_integer<int32>(
|
||||
G()->td_db()->get_sqlite_sync_pmc()->get(get_emoji_language_code_version_database_key(language_code)));
|
||||
@ -7151,6 +7176,9 @@ double StickersManager::get_emoji_language_code_last_difference_time(const strin
|
||||
if (it != emoji_language_code_last_difference_times_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
if (language_code.empty()) {
|
||||
return Time::now_cached() - G()->unix_time();
|
||||
}
|
||||
auto &result = emoji_language_code_last_difference_times_[language_code];
|
||||
auto old_unix_time = to_integer<int32>(G()->td_db()->get_sqlite_sync_pmc()->get(
|
||||
get_emoji_language_code_last_difference_time_database_key(language_code)));
|
||||
@ -7290,6 +7318,13 @@ vector<string> StickersManager::get_emoji_language_codes(const vector<string> &i
|
||||
auto it = emoji_language_codes_.find(key);
|
||||
if (it == emoji_language_codes_.end()) {
|
||||
it = emoji_language_codes_.emplace(key, full_split(G()->td_db()->get_sqlite_sync_pmc()->get(key), '$')).first;
|
||||
td::remove_if(it->second, [](const string &language_code) {
|
||||
if (language_code.empty() || language_code.find('$') != string::npos) {
|
||||
LOG(ERROR) << "Loaded language_code \"" << language_code << '"';
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if (it->second.empty()) {
|
||||
load_language_codes(std::move(language_codes), std::move(key), std::move(promise));
|
||||
@ -7405,6 +7440,7 @@ void StickersManager::on_get_emoji_keywords(
|
||||
|
||||
void StickersManager::load_emoji_keywords_difference(const string &language_code) {
|
||||
LOG(INFO) << "Load emoji keywords difference for language " << language_code;
|
||||
CHECK(!language_code.empty());
|
||||
emoji_language_code_last_difference_times_[language_code] =
|
||||
Time::now_cached() + 1e9; // prevent simultaneous requests
|
||||
int32 from_version = get_emoji_language_code_version(language_code);
|
||||
@ -7534,6 +7570,7 @@ vector<string> StickersManager::search_emojis(const string &text, bool exact_mat
|
||||
|
||||
vector<string> languages_to_load;
|
||||
for (auto &language_code : language_codes) {
|
||||
CHECK(!language_code.empty());
|
||||
auto version = get_emoji_language_code_version(language_code);
|
||||
if (version == 0) {
|
||||
languages_to_load.push_back(language_code);
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
@ -825,8 +826,8 @@ class StickersManager final : public Actor {
|
||||
FlatHashMap<string, FoundStickers> found_stickers_;
|
||||
FlatHashMap<string, vector<Promise<Unit>>> search_stickers_queries_;
|
||||
|
||||
FlatHashMap<string, vector<StickerSetId>> found_sticker_sets_;
|
||||
FlatHashMap<string, vector<Promise<Unit>>> search_sticker_sets_queries_;
|
||||
std::unordered_map<string, vector<StickerSetId>> found_sticker_sets_;
|
||||
std::unordered_map<string, vector<Promise<Unit>>> search_sticker_sets_queries_;
|
||||
|
||||
std::unordered_set<StickerSetId, StickerSetIdHash> pending_viewed_featured_sticker_set_ids_;
|
||||
Timeout pending_featured_sticker_set_views_timeout_;
|
||||
|
Loading…
Reference in New Issue
Block a user