Move static MessageId helpers to MessageId class.
This commit is contained in:
parent
8ee04b37e6
commit
b634948c15
@ -1564,7 +1564,7 @@ class ReportChannelSpamQuery final : public Td::ResultHandler {
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::channels_reportSpam(
|
||||
std::move(input_channel), std::move(input_peer), MessagesManager::get_server_message_ids(message_ids))));
|
||||
std::move(input_channel), std::move(input_peer), MessageId::get_server_message_ids(message_ids))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/MessageId.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
|
||||
@ -24,6 +25,19 @@ MessageId::MessageId(ScheduledServerMessageId server_message_id, int32 send_date
|
||||
SCHEDULED_MASK;
|
||||
}
|
||||
|
||||
vector<MessageId> MessageId::get_message_ids(const vector<int64> &input_message_ids) {
|
||||
return transform(input_message_ids, [](int64 input_message_id) { return MessageId(input_message_id); });
|
||||
}
|
||||
|
||||
vector<int32> MessageId::get_server_message_ids(const vector<MessageId> &message_ids) {
|
||||
return transform(message_ids, [](MessageId message_id) { return message_id.get_server_message_id().get(); });
|
||||
}
|
||||
|
||||
vector<int32> MessageId::get_scheduled_server_message_ids(const vector<MessageId> &message_ids) {
|
||||
return transform(message_ids,
|
||||
[](MessageId message_id) { return message_id.get_scheduled_server_message_id().get(); });
|
||||
}
|
||||
|
||||
bool MessageId::is_valid() const {
|
||||
if (id <= 0 || id > max().get()) {
|
||||
return false;
|
||||
|
@ -73,6 +73,12 @@ class MessageId {
|
||||
return MessageId(static_cast<int64>(std::numeric_limits<int32>::max()) << SERVER_ID_SHIFT);
|
||||
}
|
||||
|
||||
static vector<MessageId> get_message_ids(const vector<int64> &input_message_ids);
|
||||
|
||||
static vector<int32> get_server_message_ids(const vector<MessageId> &message_ids);
|
||||
|
||||
static vector<int32> get_scheduled_server_message_ids(const vector<MessageId> &message_ids);
|
||||
|
||||
bool is_valid() const;
|
||||
|
||||
bool is_valid_scheduled() const;
|
||||
|
@ -135,7 +135,7 @@ class GetMessagesReactionsQuery final : public Td::ResultHandler {
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getMessagesReactions(
|
||||
std::move(input_peer), MessagesManager::get_server_message_ids(message_ids_))));
|
||||
std::move(input_peer), MessageId::get_server_message_ids(message_ids_))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
|
@ -1931,7 +1931,7 @@ class GetMessagesViewsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getMessagesViews(
|
||||
std::move(input_peer), MessagesManager::get_server_message_ids(message_ids_), increment_view_counter)));
|
||||
std::move(input_peer), MessageId::get_server_message_ids(message_ids_), increment_view_counter)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -1983,7 +1983,7 @@ class GetExtendedMediaQuery final : public Td::ResultHandler {
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getExtendedMedia(
|
||||
std::move(input_peer), MessagesManager::get_server_message_ids(message_ids_))));
|
||||
std::move(input_peer), MessageId::get_server_message_ids(message_ids_))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -2013,7 +2013,7 @@ class ReadMessagesContentsQuery final : public Td::ResultHandler {
|
||||
|
||||
void send(vector<MessageId> &&message_ids) {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_readMessageContents(MessagesManager::get_server_message_ids(message_ids))));
|
||||
telegram_api::messages_readMessageContents(MessageId::get_server_message_ids(message_ids))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -2061,7 +2061,7 @@ class ReadChannelMessagesContentsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::channels_readMessageContents(
|
||||
std::move(input_channel), MessagesManager::get_server_message_ids(message_ids))));
|
||||
std::move(input_channel), MessageId::get_server_message_ids(message_ids))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -4098,7 +4098,7 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
|
||||
auto query = G()->net_query_creator().create(
|
||||
telegram_api::messages_forwardMessages(
|
||||
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
||||
false /*ignored*/, std::move(from_input_peer), MessagesManager::get_server_message_ids(message_ids),
|
||||
false /*ignored*/, std::move(from_input_peer), MessageId::get_server_message_ids(message_ids),
|
||||
std::move(random_ids), std::move(to_input_peer), top_thread_message_id.get_server_message_id().get(),
|
||||
schedule_date, std::move(as_input_peer)),
|
||||
{{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}});
|
||||
@ -4395,7 +4395,7 @@ class DeleteScheduledMessagesQuery final : public Td::ResultHandler {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_deleteScheduledMessages(
|
||||
std::move(input_peer), MessagesManager::get_scheduled_server_message_ids(message_ids_))));
|
||||
std::move(input_peer), MessageId::get_scheduled_server_message_ids(message_ids_))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -4551,7 +4551,7 @@ class ReportPeerQuery final : public Td::ResultHandler {
|
||||
std::move(input_peer), report_reason.get_input_report_reason(), report_reason.get_message())));
|
||||
} else {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_report(std::move(input_peer), MessagesManager::get_server_message_ids(message_ids),
|
||||
telegram_api::messages_report(std::move(input_peer), MessageId::get_server_message_ids(message_ids),
|
||||
report_reason.get_input_report_reason(), report_reason.get_message())));
|
||||
}
|
||||
}
|
||||
@ -6423,24 +6423,6 @@ void MessagesManager::update_message_reply_count(Dialog *d, MessageId message_id
|
||||
}
|
||||
}
|
||||
|
||||
vector<MessageId> MessagesManager::get_message_ids(const vector<int64> &input_message_ids) {
|
||||
vector<MessageId> message_ids;
|
||||
message_ids.reserve(input_message_ids.size());
|
||||
for (auto &input_message_id : input_message_ids) {
|
||||
message_ids.push_back(MessageId(input_message_id));
|
||||
}
|
||||
return message_ids;
|
||||
}
|
||||
|
||||
vector<int32> MessagesManager::get_server_message_ids(const vector<MessageId> &message_ids) {
|
||||
return transform(message_ids, [](MessageId message_id) { return message_id.get_server_message_id().get(); });
|
||||
}
|
||||
|
||||
vector<int32> MessagesManager::get_scheduled_server_message_ids(const vector<MessageId> &message_ids) {
|
||||
return transform(message_ids,
|
||||
[](MessageId message_id) { return message_id.get_scheduled_server_message_id().get(); });
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputPeer> MessagesManager::get_input_peer(DialogId dialog_id,
|
||||
AccessRights access_rights) const {
|
||||
switch (dialog_id.get_type()) {
|
||||
@ -11179,7 +11161,7 @@ void MessagesManager::delete_messages_on_server(DialogId dialog_id, vector<Messa
|
||||
case DialogType::User:
|
||||
case DialogType::Chat:
|
||||
case DialogType::Channel: {
|
||||
auto server_message_ids = MessagesManager::get_server_message_ids(message_ids);
|
||||
auto server_message_ids = MessageId::get_server_message_ids(message_ids);
|
||||
const size_t MAX_SLICE_SIZE = 100; // server side limit
|
||||
for (size_t i = 0; i < server_message_ids.size(); i += MAX_SLICE_SIZE) {
|
||||
auto end_i = i + MAX_SLICE_SIZE;
|
||||
|
@ -160,12 +160,6 @@ class MessagesManager final : public Actor {
|
||||
MessagesManager &operator=(MessagesManager &&) = delete;
|
||||
~MessagesManager() final;
|
||||
|
||||
static vector<MessageId> get_message_ids(const vector<int64> &input_message_ids);
|
||||
|
||||
static vector<int32> get_server_message_ids(const vector<MessageId> &message_ids);
|
||||
|
||||
static vector<int32> get_scheduled_server_message_ids(const vector<MessageId> &message_ids);
|
||||
|
||||
static MessageId get_message_id(const telegram_api::Message *message_ptr, bool is_scheduled);
|
||||
|
||||
static MessageId get_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr, bool is_scheduled);
|
||||
|
@ -1060,7 +1060,7 @@ class GetMessagesRequest final : public RequestOnceActor {
|
||||
GetMessagesRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id, const vector<int64> &message_ids)
|
||||
: RequestOnceActor(std::move(td), request_id)
|
||||
, dialog_id_(dialog_id)
|
||||
, message_ids_(MessagesManager::get_message_ids(message_ids)) {
|
||||
, message_ids_(MessageId::get_message_ids(message_ids)) {
|
||||
}
|
||||
};
|
||||
|
||||
@ -5066,9 +5066,9 @@ void Td::on_request(uint64 id, const td_api::closeChat &request) {
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::viewMessages &request) {
|
||||
CHECK_IS_USER();
|
||||
answer_ok_query(id, messages_manager_->view_messages(
|
||||
DialogId(request.chat_id_), MessageId(request.message_thread_id_),
|
||||
MessagesManager::get_message_ids(request.message_ids_), request.force_read_));
|
||||
answer_ok_query(
|
||||
id, messages_manager_->view_messages(DialogId(request.chat_id_), MessageId(request.message_thread_id_),
|
||||
MessageId::get_message_ids(request.message_ids_), request.force_read_));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::openMessageContent &request) {
|
||||
@ -5331,7 +5331,7 @@ void Td::on_request(uint64 id, const td_api::removeNotificationGroup &request) {
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::deleteMessages &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->delete_messages(DialogId(request.chat_id_), MessagesManager::get_message_ids(request.message_ids_),
|
||||
messages_manager_->delete_messages(DialogId(request.chat_id_), MessageId::get_message_ids(request.message_ids_),
|
||||
request.revoke_, std::move(promise));
|
||||
}
|
||||
|
||||
@ -5657,7 +5657,7 @@ void Td::on_request(uint64 id, td_api::sendChatScreenshotTakenNotification &requ
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::forwardMessages &request) {
|
||||
auto input_message_ids = MessagesManager::get_message_ids(request.message_ids_);
|
||||
auto input_message_ids = MessageId::get_message_ids(request.message_ids_);
|
||||
auto message_copy_options =
|
||||
transform(input_message_ids, [send_copy = request.send_copy_, remove_caption = request.remove_caption_](
|
||||
MessageId) { return MessageCopyOptions(send_copy, remove_caption); });
|
||||
@ -5674,8 +5674,7 @@ void Td::on_request(uint64 id, td_api::forwardMessages &request) {
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::resendMessages &request) {
|
||||
DialogId dialog_id(request.chat_id_);
|
||||
auto r_message_ids =
|
||||
messages_manager_->resend_messages(dialog_id, MessagesManager::get_message_ids(request.message_ids_));
|
||||
auto r_message_ids = messages_manager_->resend_messages(dialog_id, MessageId::get_message_ids(request.message_ids_));
|
||||
if (r_message_ids.is_error()) {
|
||||
return send_closure(actor_id(this), &Td::send_error, id, r_message_ids.move_as_error());
|
||||
}
|
||||
@ -7066,7 +7065,7 @@ void Td::on_request(uint64 id, const td_api::reportSupergroupSpam &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->report_channel_spam(ChannelId(request.supergroup_id_),
|
||||
MessagesManager::get_message_ids(request.message_ids_), std::move(promise));
|
||||
MessageId::get_message_ids(request.message_ids_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::reportSupergroupAntiSpamFalsePositive &request) {
|
||||
@ -7385,7 +7384,7 @@ void Td::on_request(uint64 id, td_api::reportChat &request) {
|
||||
return send_error_raw(id, r_report_reason.error().code(), r_report_reason.error().message());
|
||||
}
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->report_dialog(DialogId(request.chat_id_), MessagesManager::get_message_ids(request.message_ids_),
|
||||
messages_manager_->report_dialog(DialogId(request.chat_id_), MessageId::get_message_ids(request.message_ids_),
|
||||
r_report_reason.move_as_ok(), std::move(promise));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user