Merge commit 'bf945e05be9a9f696bdd866cc3427ac1bc7a4825'

This commit is contained in:
Andrea Cavalli 2020-10-26 21:55:16 +01:00
commit 134d20b7ec
9 changed files with 64 additions and 101 deletions

View File

@ -1,6 +1,6 @@
{
"name": "tdweb",
"version": "1.6.6",
"version": "1.6.9",
"description": "Javascript interface for TDLib (telegram library)",
"main": "dist/tdweb.js",
"repository": {

View File

@ -161,6 +161,7 @@ class ClientManager::Impl final {
return response;
}
Impl() = default;
Impl(const Impl &) = delete;
Impl &operator=(const Impl &) = delete;
Impl(Impl &&) = delete;

View File

@ -7571,11 +7571,17 @@ ContactsManager::User *ContactsManager::get_user_force(UserId user_id) {
profile_photo_local_id = 13226;
} else if (user_id == get_replies_bot_user_id()) {
flags |= telegram_api::user::USERNAME_MASK | telegram_api::user::BOT_MASK;
if (!G()->is_test_dc()) {
flags |= telegram_api::user::BOT_NOCHATS_MASK;
}
first_name = "Replies";
username = "replies";
bot_info_version = G()->is_test_dc() ? 1 : 3;
} else if (user_id == get_anonymous_bot_user_id()) {
flags |= telegram_api::user::USERNAME_MASK | telegram_api::user::BOT_MASK;
if (!G()->is_test_dc()) {
flags |= telegram_api::user::BOT_NOCHATS_MASK;
}
first_name = "Group";
username = G()->is_test_dc() ? "izgroupbot" : "GroupAnonymousBot";
bot_info_version = G()->is_test_dc() ? 1 : 3;

View File

@ -2890,10 +2890,11 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
new_file_view.remote_location().get_file_reference() ||
old_file_view.main_remote_location().get_access_hash() !=
new_file_view.remote_location().get_access_hash()) {
auto volume_id = -new_file_view.remote_location().get_id();
FileId file_id = td->file_manager_->register_remote(
FullRemoteFileLocation({FileType::Photo, 'i'}, new_file_view.remote_location().get_id(),
new_file_view.remote_location().get_access_hash(), 0, 0, DcId::invalid(),
new_file_view.remote_location().get_file_reference().str()),
new_file_view.remote_location().get_access_hash(), 0, volume_id,
DcId::invalid(), new_file_view.remote_location().get_file_reference().str()),
FileLocationSource::FromServer, dialog_id, old_photo->photos.back().size, 0, "");
LOG_STATUS(td->file_manager_->merge(file_id, old_file_id));
}

View File

@ -10146,63 +10146,19 @@ void MessagesManager::delete_dialog_history_from_server(DialogId dialog_id, Mess
}
}
void MessagesManager::find_discussed_messages(const Message *m, ChannelId old_channel_id, ChannelId new_channel_id,
vector<MessageId> &message_ids) {
void MessagesManager::find_messages(const Message *m, vector<MessageId> &message_ids,
const std::function<bool(const Message *)> &condition) {
if (m == nullptr) {
return;
}
find_discussed_messages(m->left.get(), old_channel_id, new_channel_id, message_ids);
find_messages(m->left.get(), message_ids, condition);
if (!m->reply_info.is_empty() && m->reply_info.channel_id.is_valid() &&
(m->reply_info.channel_id == old_channel_id || m->reply_info.channel_id == new_channel_id)) {
if (condition(m)) {
message_ids.push_back(m->message_id);
}
find_discussed_messages(m->right.get(), old_channel_id, new_channel_id, message_ids);
}
void MessagesManager::find_messages_from_user(const Message *m, UserId user_id, vector<MessageId> &message_ids) {
if (m == nullptr) {
return;
}
find_messages_from_user(m->left.get(), user_id, message_ids);
if (m->sender_user_id == user_id) {
message_ids.push_back(m->message_id);
}
find_messages_from_user(m->right.get(), user_id, message_ids);
}
void MessagesManager::find_incoming_messages_forwarded_from_user(const Message *m, UserId user_id,
vector<MessageId> &message_ids) {
if (m == nullptr) {
return;
}
find_incoming_messages_forwarded_from_user(m->left.get(), user_id, message_ids);
if (!m->is_outgoing && m->forward_info != nullptr && m->forward_info->sender_user_id == user_id) {
message_ids.push_back(m->message_id);
}
find_incoming_messages_forwarded_from_user(m->right.get(), user_id, message_ids);
}
void MessagesManager::find_unread_mentions(const Message *m, vector<MessageId> &message_ids) {
if (m == nullptr) {
return;
}
find_unread_mentions(m->left.get(), message_ids);
if (m->contains_unread_mention) {
message_ids.push_back(m->message_id);
}
find_unread_mentions(m->right.get(), message_ids);
find_messages(m->right.get(), message_ids, condition);
}
void MessagesManager::find_old_messages(const Message *m, MessageId max_message_id, vector<MessageId> &message_ids) {
@ -10307,7 +10263,7 @@ void MessagesManager::delete_dialog_messages_from_user(DialogId dialog_id, UserI
}
vector<MessageId> message_ids;
find_messages_from_user(d->messages.get(), user_id, message_ids);
find_messages(d->messages.get(), message_ids, [user_id](const Message *m) { return m->sender_user_id == user_id; });
vector<int64> deleted_message_ids;
bool need_update_dialog_pos = false;
@ -10544,7 +10500,7 @@ void MessagesManager::read_all_dialog_mentions(DialogId dialog_id, Promise<Unit>
}
vector<MessageId> message_ids;
find_unread_mentions(d->messages.get(), message_ids);
find_messages(d->messages.get(), message_ids, [](const Message *m) { return m->contains_unread_mention; });
LOG(INFO) << "Found " << message_ids.size() << " messages with unread mentions in memory";
bool is_update_sent = false;
@ -13498,7 +13454,7 @@ void MessagesManager::remove_dialog_mention_notifications(Dialog *d) {
vector<MessageId> message_ids;
std::unordered_set<NotificationId, NotificationIdHash> removed_notification_ids_set;
find_unread_mentions(d->messages.get(), message_ids);
find_messages(d->messages.get(), message_ids, [](const Message *m) { return m->contains_unread_mention; });
VLOG(notifications) << "Found unread mentions in " << message_ids;
for (auto &message_id : message_ids) {
auto m = get_message(d, message_id);
@ -15908,7 +15864,9 @@ void MessagesManager::block_dialog_from_replies(MessageId message_id, bool delet
}
if (delete_all_messages && sender_user_id.is_valid()) {
vector<MessageId> message_ids;
find_incoming_messages_forwarded_from_user(d->messages.get(), sender_user_id, message_ids);
find_messages(d->messages.get(), message_ids, [sender_user_id](const Message *m) {
return !m->is_outgoing && m->forward_info != nullptr && m->forward_info->sender_user_id == sender_user_id;
});
for (auto user_message_id : message_ids) {
auto p = this->delete_message(d, user_message_id, true, &need_update_dialog_pos, "block_dialog_from_replies 2");
@ -22025,21 +21983,18 @@ tl_object_ptr<td_api::messages> MessagesManager::get_messages_object(
return td_api::make_object<td_api::messages>(total_count, std::move(messages));
}
bool MessagesManager::is_anonymous_administrator(DialogId dialog_id) const {
bool MessagesManager::is_anonymous_administrator(DialogId dialog_id, string *author_signature) const {
CHECK(dialog_id.is_valid());
if (is_broadcast_channel(dialog_id)) {
return true;
}
return is_anonymous_administrator(td_->contacts_manager_->get_my_id(), dialog_id, nullptr);
}
bool MessagesManager::is_anonymous_administrator(UserId sender_user_id, DialogId dialog_id,
string *author_signature) const {
if (!sender_user_id.is_valid()) {
if (td_->auth_manager_->is_bot()) {
return false;
}
CHECK(dialog_id.is_valid());
if (dialog_id.get_type() != DialogType::Channel || is_broadcast_channel(dialog_id)) {
if (dialog_id.get_type() != DialogType::Channel) {
return false;
}
@ -22081,7 +22036,7 @@ MessagesManager::Message *MessagesManager::get_message_to_send(
}
m->sender_dialog_id = d->dialog_id;
} else {
if (is_anonymous_administrator(my_id, d->dialog_id, &m->author_signature)) {
if (is_anonymous_administrator(d->dialog_id, &m->author_signature)) {
m->sender_dialog_id = d->dialog_id;
} else {
m->sender_user_id = my_id;
@ -23483,11 +23438,14 @@ void MessagesManager::on_yet_unsent_media_queue_updated(DialogId dialog_id) {
}
auto m = get_message({dialog_id, MessageId(first_it->first)});
auto promise = std::move(first_it->second);
queue.erase(first_it);
if (m != nullptr) {
LOG(INFO) << "Can send " << FullMessageId{dialog_id, m->message_id};
first_it->second.set_value(std::move(m));
promise.set_value(std::move(m));
} else {
promise.set_error(Status::Error(400, "Message not found"));
}
queue.erase(first_it);
}
LOG(INFO) << "Queue for " << dialog_id << " now has size " << queue.size();
if (queue.empty()) {
@ -25064,7 +25022,7 @@ Result<unique_ptr<ReplyMarkup>> MessagesManager::get_dialog_reply_markup(
}
auto dialog_type = dialog_id.get_type();
bool is_anonymous = is_anonymous_administrator(dialog_id);
bool is_anonymous = is_anonymous_administrator(dialog_id, nullptr);
bool only_inline_keyboard = is_anonymous;
bool request_buttons_allowed = dialog_type == DialogType::User;
@ -25746,11 +25704,7 @@ Result<MessageId> MessagesManager::add_local_message(
}
m->sender_dialog_id = dialog_id;
} else {
if (is_anonymous_administrator(sender_user_id, dialog_id, &m->author_signature)) {
m->sender_dialog_id = dialog_id;
} else {
m->sender_user_id = sender_user_id;
}
m->sender_user_id = sender_user_id;
}
m->date = G()->unix_time();
m->reply_to_message_id = get_reply_to_message_id(d, MessageId(), reply_to_message_id);
@ -26002,6 +25956,9 @@ Result<MessagesManager::MessagePushNotificationInfo> MessagesManager::get_messag
} else if (contains_mention && is_dialog_mention_notifications_disabled(d)) {
contains_mention = false;
}
if (dialog_id.get_type() == DialogType::User) {
contains_mention = false;
}
DialogId settings_dialog_id = dialog_id;
Dialog *settings_dialog = d;
@ -28814,7 +28771,10 @@ void MessagesManager::on_dialog_linked_channel_updated(DialogId dialog_id, Chann
auto d = get_dialog(dialog_id); // no need to create the dialog
if (d != nullptr && d->is_update_new_chat_sent) {
vector<MessageId> message_ids;
find_discussed_messages(d->messages.get(), old_linked_channel_id, new_linked_channel_id, message_ids);
find_messages(d->messages.get(), message_ids, [old_linked_channel_id, new_linked_channel_id](const Message *m) {
return !m->reply_info.is_empty() && m->reply_info.channel_id.is_valid() &&
(m->reply_info.channel_id == old_linked_channel_id || m->reply_info.channel_id == new_linked_channel_id);
});
LOG(INFO) << "Found discussion messages " << message_ids;
for (auto message_id : message_ids) {
send_update_message_interaction_info(dialog_id, get_message(d, message_id));
@ -29180,7 +29140,7 @@ bool MessagesManager::get_dialog_has_scheduled_messages(const Dialog *d) const {
}
bool MessagesManager::is_dialog_action_unneeded(DialogId dialog_id) const {
if (is_anonymous_administrator(dialog_id)) {
if (is_anonymous_administrator(dialog_id, nullptr)) {
return true;
}
@ -34127,6 +34087,12 @@ void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool
after_get_channel_difference(dialog_id, false);
return;
}
if (!have_input_peer(dialog_id, AccessRights::Read)) {
LOG(INFO) << "Skip running channels.getDifference for " << dialog_id << " from " << source
<< " because have no read access to it";
after_get_channel_difference(dialog_id, false);
return;
}
if (force && get_channel_difference_to_log_event_id_.count(dialog_id) == 0 && !G()->ignore_backgrond_updates()) {
auto channel_id = dialog_id.get_channel_id();
@ -34151,14 +34117,6 @@ void MessagesManager::do_get_channel_difference(DialogId dialog_id, int32 pts, b
<< " because it has already been run";
return;
}
bool have_access = have_input_peer(dialog_id, AccessRights::Read);
if (!have_access) {
LOG(INFO) << "Skip running channels.getDifference for " << dialog_id << " from " << source
<< " because have no read access to it";
active_get_channel_differencies_.erase(dialog_id);
after_get_channel_difference(dialog_id, false);
return;
}
// can be called multiple times before after_get_channel_difference
const Dialog *d = get_dialog(dialog_id);

View File

@ -1753,9 +1753,7 @@ class MessagesManager : public Actor {
Status can_use_top_thread_message_id(Dialog *d, MessageId top_thread_message_id, MessageId reply_to_message_id);
bool is_anonymous_administrator(DialogId dialog_id) const;
bool is_anonymous_administrator(UserId sender_user_id, DialogId dialog_id, string *author_signature) const;
bool is_anonymous_administrator(DialogId dialog_id, string *author_signature) const;
Message *get_message_to_send(Dialog *d, MessageId top_thread_message_id, MessageId reply_to_message_id,
const MessageSendOptions &options, unique_ptr<MessageContent> &&content,
@ -1915,15 +1913,8 @@ class MessagesManager : public Actor {
static MessageId find_message_by_date(const Message *m, int32 date);
static void find_discussed_messages(const Message *m, ChannelId old_channel_id, ChannelId new_channel_id,
vector<MessageId> &message_ids);
static void find_messages_from_user(const Message *m, UserId user_id, vector<MessageId> &message_ids);
static void find_incoming_messages_forwarded_from_user(const Message *m, UserId user_id,
vector<MessageId> &message_ids);
static void find_unread_mentions(const Message *m, vector<MessageId> &message_ids);
static void find_messages(const Message *m, vector<MessageId> &message_ids,
const std::function<bool(const Message *)> &condition);
static void find_old_messages(const Message *m, MessageId max_message_id, vector<MessageId> &message_ids);

View File

@ -342,7 +342,7 @@ PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice
// generate some random remote location to save
auto dc_id = DcId::invalid();
auto local_id = Random::secure_int32();
auto local_id = -(Random::secure_int32() & 0x7FFFFFFF);
auto volume_id = Random::secure_int64();
res.file_id = file_manager->register_remote(

View File

@ -36,11 +36,15 @@ string implode(const vector<string> &v, char delimiter) {
return result;
}
string lpad0(string str, size_t size) {
string lpad(string str, size_t size, char c) {
if (str.size() >= size) {
return str;
}
return string(size - str.size(), '0') + str;
return string(size - str.size(), c) + str;
}
string lpad0(string str, size_t size) {
return lpad(std::move(str), size, '0');
}
string oneline(Slice str) {
@ -48,7 +52,7 @@ string oneline(Slice str) {
result.reserve(str.size());
bool after_new_line = true;
for (auto c : str) {
if (c != '\n') {
if (c != '\n' && c != '\r') {
if (after_new_line) {
if (c == ' ') {
continue;
@ -56,7 +60,7 @@ string oneline(Slice str) {
after_new_line = false;
}
result += c;
} else {
} else if (!after_new_line) {
after_new_line = true;
result += ' ';
}

View File

@ -269,7 +269,9 @@ T trim(T str) {
return T(begin, end);
}
string lpad0(string str, size_t size);
string lpad(string str, size_t size, char c);
string lpad0(const string str, size_t size);
string oneline(Slice str);