Merge commit '7d5b47990b4878f6a2a560d8cf064e28d46672ed'

This commit is contained in:
Andrea Cavalli 2020-10-01 23:45:32 +02:00
commit e8e9dc4abf
8 changed files with 62 additions and 29 deletions

View File

@ -136,6 +136,9 @@ abstract class TlDocumentationGenerator
$this->printError('Wrong description begin');
}
if (preg_match('/[^ ]@/', $description)) {
$this->printError("Wrong documentation '@' usage: $description");
}
$docs = explode('@', $description);
array_shift($docs);
$info = array();

View File

@ -2189,7 +2189,7 @@ inlineQueryResults inline_query_id:int64 next_offset:string results:vector<Inlin
//@description The payload for a general callback button @data Data that was attached to the callback button
callbackQueryPayloadData data:bytes = CallbackQueryPayload;
//@description The payload for a callback button requiring password @password The password for the current user@data Data that was attached to the callback button
//@description The payload for a callback button requiring password @password The password for the current user @data Data that was attached to the callback button
callbackQueryPayloadDataWithPassword password:string data:bytes = CallbackQueryPayload;
//@description The payload for a game callback button @game_short_name A short name of the game that was attached to the callback button

View File

@ -331,6 +331,10 @@ DialogAction DialogAction::get_uploading_action(MessageContentType message_conte
}
}
DialogAction DialogAction::get_typing_action() {
return DialogAction(Type::Typing, 0);
}
StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &action) {
string_builder << "ChatAction";
const char *type = [action_type = action.type_] {

View File

@ -18,7 +18,6 @@
namespace td {
class DialogAction {
public:
enum class Type : int32 {
Cancel,
Typing,
@ -37,10 +36,15 @@ class DialogAction {
Type type_ = Type::Cancel;
int32 progress_ = 0;
DialogAction() = default;
DialogAction(Type type, int32 progress);
void init(Type type);
void init(Type type, int32 progress);
public:
DialogAction() = default;
explicit DialogAction(tl_object_ptr<td_api::ChatAction> &&action);
explicit DialogAction(tl_object_ptr<telegram_api::SendMessageAction> &&action);
@ -55,14 +59,14 @@ class DialogAction {
static DialogAction get_uploading_action(MessageContentType message_content_type, int32 progress);
private:
void init(Type type);
void init(Type type, int32 progress);
};
static DialogAction get_typing_action();
inline bool operator==(const DialogAction &lhs, const DialogAction &rhs) {
return lhs.type_ == rhs.type_ && lhs.progress_ == rhs.progress_;
}
friend bool operator==(const DialogAction &lhs, const DialogAction &rhs) {
return lhs.type_ == rhs.type_ && lhs.progress_ == rhs.progress_;
}
friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &action);
};
inline bool operator!=(const DialogAction &lhs, const DialogAction &rhs) {
return !(lhs == rhs);

View File

@ -36,7 +36,7 @@ MessageReplyInfo::MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &
}
if (is_comment) {
for (auto &peer : reply_info->recent_repliers_) {
for (const auto &peer : reply_info->recent_repliers_) {
DialogId dialog_id(peer);
if (dialog_id.is_valid()) {
recent_replier_dialog_ids.push_back(dialog_id);
@ -58,6 +58,7 @@ MessageReplyInfo::MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &
<< ", but max_message_id = " << max_message_id;
max_message_id = last_read_inbox_message_id;
}
LOG(DEBUG) << "Parsed " << oneline(to_string(reply_info)) << " to " << *this;
}
bool MessageReplyInfo::need_update_to(const MessageReplyInfo &other) const {
@ -68,7 +69,8 @@ bool MessageReplyInfo::need_update_to(const MessageReplyInfo &other) const {
if (other.pts < pts) {
return false;
}
return reply_count != other.reply_count || recent_replier_dialog_ids != other.recent_replier_dialog_ids;
return reply_count != other.reply_count || recent_replier_dialog_ids != other.recent_replier_dialog_ids ||
is_comment != other.is_comment || channel_id != other.channel_id;
}
bool MessageReplyInfo::update_max_message_ids(const MessageReplyInfo &other) {

View File

@ -1838,6 +1838,7 @@ class SearchMessagesQuery : public Td::ResultHandler {
MessageSearchFilter filter_;
MessageId top_thread_message_id_;
int64 random_id_;
bool handle_errors_ = true;
public:
explicit SearchMessagesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
@ -1868,6 +1869,8 @@ class SearchMessagesQuery : public Td::ResultHandler {
telegram_api::messages_getUnreadMentions(std::move(input_peer), from_message_id.get_server_message_id().get(),
offset, limit, std::numeric_limits<int32>::max(), 0)));
} else if (top_thread_message_id.is_valid() && !sender_user_id.is_valid() && filter == MessageSearchFilter::Empty) {
handle_errors_ = dialog_id.get_type() != DialogType::Channel ||
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ChannelType::Broadcast;
send_query(G()->net_query_creator().create(telegram_api::messages_getReplies(
std::move(input_peer), top_thread_message_id.get_server_message_id().get(),
from_message_id.get_server_message_id().get(), 0, offset, limit, std::numeric_limits<int32>::max(), 0, 0)));
@ -1909,7 +1912,9 @@ class SearchMessagesQuery : public Td::ResultHandler {
}
void on_error(uint64 id, Status status) override {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SearchMessagesQuery");
if (!handle_errors_) {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SearchMessagesQuery");
}
td->messages_manager_->on_failed_dialog_messages_search(dialog_id_, random_id_);
promise_.set_error(std::move(status));
}
@ -6376,7 +6381,7 @@ void MessagesManager::on_update_read_message_comments(DialogId dialog_id, Messag
return;
}
if (m->reply_info.update_max_message_ids(max_message_id, last_read_inbox_message_id, last_read_outbox_message_id)) {
send_update_message_interaction_info(dialog_id, m);
on_message_reply_info_changed(dialog_id, m);
on_message_changed(d, m, true, "on_update_read_message_comments");
}
}
@ -6546,6 +6551,16 @@ bool MessagesManager::is_visible_message_reply_info(DialogId dialog_id, const Me
return is_active_message_reply_info(dialog_id, m->reply_info);
}
void MessagesManager::on_message_reply_info_changed(DialogId dialog_id, const Message *m) const {
if (td_->auth_manager_->is_bot()) {
return;
}
if (is_visible_message_reply_info(dialog_id, m)) {
send_update_message_interaction_info(dialog_id, m);
}
}
td_api::object_ptr<td_api::messageInteractionInfo> MessagesManager::get_message_interaction_info_object(
DialogId dialog_id, const Message *m) const {
bool is_visible_reply_info = is_visible_message_reply_info(dialog_id, m);
@ -6592,7 +6607,7 @@ bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Messag
} else {
if (m->reply_info.update_max_message_ids(reply_info) && view_count <= m->view_count &&
forward_count <= m->forward_count) {
send_update_message_interaction_info(dialog_id, m);
on_message_reply_info_changed(dialog_id, m);
on_message_changed(get_dialog(dialog_id), m, true, "update_message_interaction_info");
}
}
@ -6612,17 +6627,16 @@ bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Messag
}
if (need_update_reply_info) {
if (m->reply_info.channel_id != reply_info.channel_id) {
if (m->reply_info.channel_id.is_valid() && reply_info.channel_id.is_valid()) {
if (m->reply_info.channel_id.is_valid() && reply_info.channel_id.is_valid() && m->message_id.is_server()) {
LOG(ERROR) << "Reply info changed from " << m->reply_info << " to " << reply_info;
}
}
m->reply_info = std::move(reply_info);
need_update |=
m->message_id.is_valid() && m->message_id.is_server() && !m->had_reply_markup && m->reply_markup == nullptr;
if (!m->top_thread_message_id.is_valid() && !is_broadcast_channel(dialog_id) &&
is_visible_message_reply_info(dialog_id, m)) {
m->top_thread_message_id = m->message_id;
}
need_update |= is_visible_message_reply_info(dialog_id, m);
}
if (need_update) {
send_update_message_interaction_info(dialog_id, m);
@ -18436,7 +18450,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, MessageId top_thread_m
if (top_m != nullptr && is_active_message_reply_info(dialog_id, top_m->reply_info)) {
prev_last_read_inbox_message_id = top_m->reply_info.last_read_inbox_message_id;
if (top_m->reply_info.update_max_message_ids(MessageId(), max_message_id, MessageId())) {
send_update_message_interaction_info(dialog_id, top_m);
on_message_reply_info_changed(dialog_id, top_m);
on_message_changed(d, top_m, true, "view_messages 3");
}
max_thread_message_id = top_m->reply_info.max_message_id;
@ -18452,7 +18466,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, MessageId top_thread_m
prev_last_read_inbox_message_id = linked_m->reply_info.last_read_inbox_message_id;
}
if (linked_m->reply_info.update_max_message_ids(MessageId(), max_message_id, MessageId())) {
send_update_message_interaction_info(linked_dialog_id, linked_m);
on_message_reply_info_changed(linked_dialog_id, linked_m);
on_message_changed(linked_d, linked_m, true, "view_messages 5");
}
if (linked_m->reply_info.max_message_id > max_thread_message_id) {
@ -21833,13 +21847,17 @@ MessagesManager::Message *MessagesManager::get_message_to_send(
if (td_->auth_manager_->is_bot()) {
return false;
}
if (is_channel_post) {
return td_->contacts_manager_->get_channel_has_linked_channel(dialog_id.get_channel_id());
}
return !reply_to_message_id.is_valid() &&
return (is_channel_post || !reply_to_message_id.is_valid()) &&
td_->contacts_manager_->get_channel_has_linked_channel(dialog_id.get_channel_id());
}()) {
m->reply_info.reply_count = 0;
if (is_channel_post) {
auto linked_channel_id = td_->contacts_manager_->get_channel_linked_channel_id(dialog_id.get_channel_id());
if (linked_channel_id.is_valid()) {
m->reply_info.is_comment = true;
m->reply_info.channel_id = linked_channel_id;
}
}
}
m->content = std::move(content);
m->forward_info = std::move(forward_info);
@ -31006,7 +31024,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
auto replier_dialog_id =
has_message_sender_user_id(dialog_id, m) ? DialogId(m->sender_user_id) : m->sender_dialog_id;
top_m->reply_info.add_reply(replier_dialog_id, message_id);
send_update_message_interaction_info(dialog_id, top_m);
on_message_reply_info_changed(dialog_id, top_m);
on_message_changed(d, top_m, true, "update_message_reply_count 1");
if (is_discussion_message(dialog_id, top_m)) {
@ -31014,7 +31032,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
Message *channel_m = get_message({channel_dialog_id, top_m->forward_info->message_id});
if (channel_m != nullptr && is_active_message_reply_info(channel_dialog_id, channel_m->reply_info)) {
channel_m->reply_info.add_reply(replier_dialog_id, message_id);
send_update_message_interaction_info(channel_dialog_id, channel_m);
on_message_reply_info_changed(channel_dialog_id, channel_m);
on_message_changed(get_dialog(channel_dialog_id), channel_m, true, "update_message_reply_count 2");
}
}

View File

@ -1937,6 +1937,8 @@ class MessagesManager : public Actor {
bool is_visible_message_reply_info(DialogId dialog_id, const Message *m) const;
void on_message_reply_info_changed(DialogId dialog_id, const Message *m) const;
Result<FullMessageId> get_top_thread_full_message_id(DialogId dialog_id, const Message *m) const;
td_api::object_ptr<td_api::messageInteractionInfo> get_message_interaction_info_object(DialogId dialog_id,

View File

@ -1898,8 +1898,8 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEncryptedChatTy
return;
}
td_->messages_manager_->on_user_dialog_action(dialog_id, MessageId(), user_id,
DialogAction(DialogAction::Type::Typing, 0), get_short_update_date());
td_->messages_manager_->on_user_dialog_action(dialog_id, MessageId(), user_id, DialogAction::get_typing_action(),
get_short_update_date());
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateUserStatus> update, bool /*force_apply*/) {