Move get_message_sender_dialog_id to MessageSender.cpp.
This commit is contained in:
parent
a56c34c4dd
commit
5987ca69ff
@ -14846,32 +14846,6 @@ std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const v
|
|||||||
return {narrow_cast<int32>(result.first), transform(result.second, [](int64 key) { return DialogId(key); })};
|
return {narrow_cast<int32>(result.first), transform(result.second, [](int64 key) { return DialogId(key); })};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<DialogId> ContactsManager::get_participant_dialog_id(
|
|
||||||
const td_api::object_ptr<td_api::MessageSender> &participant_id) {
|
|
||||||
if (participant_id == nullptr) {
|
|
||||||
return Status::Error(400, "Member identifier is not specified");
|
|
||||||
}
|
|
||||||
switch (participant_id->get_id()) {
|
|
||||||
case td_api::messageSenderUser::ID: {
|
|
||||||
auto user_id = UserId(static_cast<const td_api::messageSenderUser *>(participant_id.get())->user_id_);
|
|
||||||
if (!user_id.is_valid()) {
|
|
||||||
return Status::Error(400, "Invalid user identifier specified");
|
|
||||||
}
|
|
||||||
return DialogId(user_id);
|
|
||||||
}
|
|
||||||
case td_api::messageSenderChat::ID: {
|
|
||||||
auto dialog_id = DialogId(static_cast<const td_api::messageSenderChat *>(participant_id.get())->chat_id_);
|
|
||||||
if (!dialog_id.is_valid()) {
|
|
||||||
return Status::Error(400, "Invalid chat identifier specified");
|
|
||||||
}
|
|
||||||
return dialog_id;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
return DialogId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
|
void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
|
||||||
Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "add_dialog_participant")) {
|
if (!td_->messages_manager_->have_dialog_force(dialog_id, "add_dialog_participant")) {
|
||||||
@ -14915,12 +14889,9 @@ void ContactsManager::add_dialog_participants(DialogId dialog_id, const vector<U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::set_dialog_participant_status(DialogId dialog_id,
|
void ContactsManager::set_dialog_participant_status(DialogId dialog_id, DialogId participant_dialog_id,
|
||||||
const tl_object_ptr<td_api::MessageSender> &participant_id,
|
|
||||||
const tl_object_ptr<td_api::ChatMemberStatus> &chat_member_status,
|
const tl_object_ptr<td_api::ChatMemberStatus> &chat_member_status,
|
||||||
Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_participant_dialog_id(participant_id));
|
|
||||||
|
|
||||||
auto status = get_dialog_participant_status(chat_member_status);
|
auto status = get_dialog_participant_status(chat_member_status);
|
||||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_participant_status")) {
|
if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_participant_status")) {
|
||||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||||
@ -14950,11 +14921,8 @@ void ContactsManager::set_dialog_participant_status(DialogId dialog_id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::ban_dialog_participant(DialogId dialog_id,
|
void ContactsManager::ban_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||||
const tl_object_ptr<td_api::MessageSender> &participant_id,
|
|
||||||
int32 banned_until_date, bool revoke_messages, Promise<Unit> &&promise) {
|
int32 banned_until_date, bool revoke_messages, Promise<Unit> &&promise) {
|
||||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_participant_dialog_id(participant_id));
|
|
||||||
|
|
||||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "ban_dialog_participant")) {
|
if (!td_->messages_manager_->have_dialog_force(dialog_id, "ban_dialog_participant")) {
|
||||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||||
}
|
}
|
||||||
@ -14979,18 +14947,15 @@ void ContactsManager::ban_dialog_participant(DialogId dialog_id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::get_dialog_participant(DialogId dialog_id,
|
void ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||||
const tl_object_ptr<td_api::MessageSender> &participant_id,
|
|
||||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise) {
|
Promise<td_api::object_ptr<td_api::chatMember>> &&promise) {
|
||||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_participant_dialog_id(participant_id));
|
|
||||||
|
|
||||||
auto new_promise = PromiseCreator::lambda(
|
auto new_promise = PromiseCreator::lambda(
|
||||||
[actor_id = actor_id(this), promise = std::move(promise)](Result<DialogParticipant> &&result) mutable {
|
[actor_id = actor_id(this), promise = std::move(promise)](Result<DialogParticipant> &&result) mutable {
|
||||||
TRY_RESULT_PROMISE(promise, dialog_participant, std::move(result));
|
TRY_RESULT_PROMISE(promise, dialog_participant, std::move(result));
|
||||||
send_closure(actor_id, &ContactsManager::finish_get_dialog_participant, std::move(dialog_participant),
|
send_closure(actor_id, &ContactsManager::finish_get_dialog_participant, std::move(dialog_participant),
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
});
|
});
|
||||||
get_dialog_participant(dialog_id, participant_dialog_id, std::move(new_promise));
|
do_get_dialog_participant(dialog_id, participant_dialog_id, std::move(new_promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::finish_get_dialog_participant(DialogParticipant &&dialog_participant,
|
void ContactsManager::finish_get_dialog_participant(DialogParticipant &&dialog_participant,
|
||||||
@ -15007,10 +14972,10 @@ void ContactsManager::finish_get_dialog_participant(DialogParticipant &&dialog_p
|
|||||||
promise.set_value(get_chat_member_object(dialog_participant));
|
promise.set_value(get_chat_member_object(dialog_participant));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
void ContactsManager::do_get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||||
Promise<DialogParticipant> &&promise) {
|
Promise<DialogParticipant> &&promise) {
|
||||||
LOG(INFO) << "Receive GetChatMember request to get " << participant_dialog_id << " in " << dialog_id;
|
LOG(INFO) << "Receive GetChatMember request to get " << participant_dialog_id << " in " << dialog_id;
|
||||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_participant")) {
|
if (!td_->messages_manager_->have_dialog_force(dialog_id, "do_get_dialog_participant")) {
|
||||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,14 +526,14 @@ class ContactsManager final : public Actor {
|
|||||||
|
|
||||||
void add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
|
void add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void set_dialog_participant_status(DialogId dialog_id, const tl_object_ptr<td_api::MessageSender> &participant_id,
|
void set_dialog_participant_status(DialogId dialog_id, DialogId participant_dialog_id,
|
||||||
const tl_object_ptr<td_api::ChatMemberStatus> &chat_member_status,
|
const tl_object_ptr<td_api::ChatMemberStatus> &chat_member_status,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void ban_dialog_participant(DialogId dialog_id, const tl_object_ptr<td_api::MessageSender> &participant_id,
|
void ban_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id, int32 banned_until_date,
|
||||||
int32 banned_until_date, bool revoke_messages, Promise<Unit> &&promise);
|
bool revoke_messages, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void get_dialog_participant(DialogId dialog_id, const tl_object_ptr<td_api::MessageSender> &participant_id,
|
void get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
||||||
|
|
||||||
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantsFilter filter,
|
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantsFilter filter,
|
||||||
@ -1419,8 +1419,6 @@ class ContactsManager final : public Actor {
|
|||||||
|
|
||||||
bool update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link);
|
bool update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link);
|
||||||
|
|
||||||
static Result<DialogId> get_participant_dialog_id(const td_api::object_ptr<td_api::MessageSender> &participant_id);
|
|
||||||
|
|
||||||
void add_chat_participant(ChatId chat_id, UserId user_id, int32 forward_limit, Promise<Unit> &&promise);
|
void add_chat_participant(ChatId chat_id, UserId user_id, int32 forward_limit, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void add_channel_participant(ChannelId channel_id, UserId user_id, const DialogParticipantStatus &old_status,
|
void add_channel_participant(ChannelId channel_id, UserId user_id, const DialogParticipantStatus &old_status,
|
||||||
@ -1441,7 +1439,8 @@ class ContactsManager final : public Actor {
|
|||||||
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
|
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
|
||||||
int32 limit, DialogParticipantsFilter filter) const;
|
int32 limit, DialogParticipantsFilter filter) const;
|
||||||
|
|
||||||
void get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id, Promise<DialogParticipant> &&promise);
|
void do_get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||||
|
Promise<DialogParticipant> &&promise);
|
||||||
|
|
||||||
void finish_get_dialog_participant(DialogParticipant &&dialog_participant,
|
void finish_get_dialog_participant(DialogParticipant &&dialog_participant,
|
||||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
||||||
|
@ -54,4 +54,29 @@ td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, Dial
|
|||||||
return get_message_sender_object(td, UserId(), dialog_id, source);
|
return get_message_sender_object(td, UserId(), dialog_id, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<DialogId> get_message_sender_dialog_id(const td_api::object_ptr<td_api::MessageSender> &message_sender_id) {
|
||||||
|
if (message_sender_id == nullptr) {
|
||||||
|
return Status::Error(400, "Member identifier is not specified");
|
||||||
|
}
|
||||||
|
switch (message_sender_id->get_id()) {
|
||||||
|
case td_api::messageSenderUser::ID: {
|
||||||
|
auto user_id = UserId(static_cast<const td_api::messageSenderUser *>(message_sender_id.get())->user_id_);
|
||||||
|
if (!user_id.is_valid()) {
|
||||||
|
return Status::Error(400, "Invalid user identifier specified");
|
||||||
|
}
|
||||||
|
return DialogId(user_id);
|
||||||
|
}
|
||||||
|
case td_api::messageSenderChat::ID: {
|
||||||
|
auto dialog_id = DialogId(static_cast<const td_api::messageSenderChat *>(message_sender_id.get())->chat_id_);
|
||||||
|
if (!dialog_id.is_valid()) {
|
||||||
|
return Status::Error(400, "Invalid chat identifier specified");
|
||||||
|
}
|
||||||
|
return dialog_id;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return DialogId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "td/telegram/UserId.h"
|
#include "td/telegram/UserId.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/Status.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -27,4 +28,6 @@ td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, User
|
|||||||
|
|
||||||
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, DialogId dialog_id, const char *source);
|
td_api::object_ptr<td_api::MessageSender> get_message_sender_object(Td *td, DialogId dialog_id, const char *source);
|
||||||
|
|
||||||
|
Result<DialogId> get_message_sender_dialog_id(const td_api::object_ptr<td_api::MessageSender> &message_sender_id);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
#include "td/telegram/MessageId.h"
|
#include "td/telegram/MessageId.h"
|
||||||
#include "td/telegram/MessageLinkInfo.h"
|
#include "td/telegram/MessageLinkInfo.h"
|
||||||
#include "td/telegram/MessageSearchFilter.h"
|
#include "td/telegram/MessageSearchFilter.h"
|
||||||
|
#include "td/telegram/MessageSender.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
#include "td/telegram/MessageThreadInfo.h"
|
#include "td/telegram/MessageThreadInfo.h"
|
||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
@ -6227,8 +6228,7 @@ void Td::on_request(uint64 id, const td_api::leaveChat &request) {
|
|||||||
td_api::make_object<td_api::chatMemberStatusCreator>(status.get_rank(), status.is_anonymous(), false);
|
td_api::make_object<td_api::chatMemberStatusCreator>(status.get_rank(), status.is_anonymous(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contacts_manager_->set_dialog_participant_status(
|
contacts_manager_->set_dialog_participant_status(dialog_id, DialogId(contacts_manager_->get_my_id()), new_status,
|
||||||
dialog_id, td_api::make_object<td_api::messageSenderUser>(contacts_manager_->get_my_id().get()), new_status,
|
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6246,16 +6246,18 @@ void Td::on_request(uint64 id, const td_api::addChatMembers &request) {
|
|||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::setChatMemberStatus &request) {
|
void Td::on_request(uint64 id, const td_api::setChatMemberStatus &request) {
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
contacts_manager_->set_dialog_participant_status(DialogId(request.chat_id_), request.member_id_, request.status_,
|
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_message_sender_dialog_id(request.member_id_));
|
||||||
|
contacts_manager_->set_dialog_participant_status(DialogId(request.chat_id_), participant_dialog_id, request.status_,
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::banChatMember &request) {
|
void Td::on_request(uint64 id, const td_api::banChatMember &request) {
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
contacts_manager_->ban_dialog_participant(DialogId(request.chat_id_), request.member_id_, request.banned_until_date_,
|
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_message_sender_dialog_id(request.member_id_));
|
||||||
request.revoke_messages_, std::move(promise));
|
contacts_manager_->ban_dialog_participant(DialogId(request.chat_id_), participant_dialog_id,
|
||||||
|
request.banned_until_date_, request.revoke_messages_, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::canTransferOwnership &request) {
|
void Td::on_request(uint64 id, const td_api::canTransferOwnership &request) {
|
||||||
@ -6280,9 +6282,10 @@ void Td::on_request(uint64 id, td_api::transferChatOwnership &request) {
|
|||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::getChatMember &request) {
|
void Td::on_request(uint64 id, const td_api::getChatMember &request) {
|
||||||
CREATE_REQUEST_PROMISE();
|
CREATE_REQUEST_PROMISE();
|
||||||
contacts_manager_->get_dialog_participant(DialogId(request.chat_id_), request.member_id_, std::move(promise));
|
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_message_sender_dialog_id(request.member_id_));
|
||||||
|
contacts_manager_->get_dialog_participant(DialogId(request.chat_id_), participant_dialog_id, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::searchChatMembers &request) {
|
void Td::on_request(uint64 id, td_api::searchChatMembers &request) {
|
||||||
@ -6300,7 +6303,7 @@ void Td::on_request(uint64 id, td_api::searchChatMembers &request) {
|
|||||||
DialogParticipantsFilter(request.filter_), std::move(query_promise));
|
DialogParticipantsFilter(request.filter_), std::move(query_promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::getChatAdministrators &request) {
|
void Td::on_request(uint64 id, const td_api::getChatAdministrators &request) {
|
||||||
CREATE_REQUEST(GetChatAdministratorsRequest, request.chat_id_);
|
CREATE_REQUEST(GetChatAdministratorsRequest, request.chat_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,7 +852,7 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, const td_api::addChatMembers &request);
|
void on_request(uint64 id, const td_api::addChatMembers &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::setChatMemberStatus &request);
|
void on_request(uint64 id, const td_api::setChatMemberStatus &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::banChatMember &request);
|
void on_request(uint64 id, const td_api::banChatMember &request);
|
||||||
|
|
||||||
@ -860,11 +860,11 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, td_api::transferChatOwnership &request);
|
void on_request(uint64 id, td_api::transferChatOwnership &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getChatMember &request);
|
void on_request(uint64 id, const td_api::getChatMember &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::searchChatMembers &request);
|
void on_request(uint64 id, td_api::searchChatMembers &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getChatAdministrators &request);
|
void on_request(uint64 id, const td_api::getChatAdministrators &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::replacePrimaryChatInviteLink &request);
|
void on_request(uint64 id, const td_api::replacePrimaryChatInviteLink &request);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user