Add DialogManager::set_dialog_location.

This commit is contained in:
levlam 2024-02-20 00:43:04 +03:00
parent 6c5441c8ff
commit fe749cfb9b
5 changed files with 25 additions and 16 deletions

View File

@ -7714,24 +7714,12 @@ void ContactsManager::set_channel_discussion_group(DialogId dialog_id, DialogId
std::move(group_input_channel));
}
void ContactsManager::set_channel_location(DialogId dialog_id, const DialogLocation &location,
void ContactsManager::set_channel_location(ChannelId channel_id, const DialogLocation &location,
Promise<Unit> &&promise) {
if (location.empty()) {
return promise.set_error(Status::Error(400, "Invalid chat location specified"));
}
if (!dialog_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid chat identifier specified"));
}
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "set_channel_location")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (dialog_id.get_type() != DialogType::Channel) {
return promise.set_error(Status::Error(400, "Chat is not a supergroup"));
}
auto channel_id = dialog_id.get_channel_id();
const Channel *c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Chat info not found"));

View File

@ -506,7 +506,7 @@ class ContactsManager final : public Actor {
void set_channel_discussion_group(DialogId dialog_id, DialogId discussion_dialog_id, Promise<Unit> &&promise);
void set_channel_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
void set_channel_location(ChannelId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
void set_channel_slow_mode_delay(DialogId dialog_id, int32 slow_mode_delay, Promise<Unit> &&promise);

View File

@ -1607,6 +1607,24 @@ void DialogManager::set_dialog_description(DialogId dialog_id, const string &des
}
}
void DialogManager::set_dialog_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise) {
if (!have_dialog_force(dialog_id, "set_dialog_location")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
case DialogType::Chat:
case DialogType::SecretChat:
return promise.set_error(Status::Error(400, "The chat can't have location"));
case DialogType::Channel:
return td_->contacts_manager_->set_channel_location(dialog_id.get_channel_id(), location, std::move(promise));
case DialogType::None:
default:
UNREACHABLE();
}
}
bool DialogManager::can_report_dialog(DialogId dialog_id) const {
// doesn't include possibility of report from action bar
switch (dialog_id.get_type()) {

View File

@ -11,6 +11,7 @@
#include "td/telegram/ChannelId.h"
#include "td/telegram/CustomEmojiId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogLocation.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/EmojiStatus.h"
#include "td/telegram/files/FileId.h"
@ -158,6 +159,8 @@ class DialogManager final : public Actor {
void set_dialog_description(DialogId dialog_id, const string &description, Promise<Unit> &&promise);
void set_dialog_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
bool can_report_dialog(DialogId dialog_id) const;
void report_dialog(DialogId dialog_id, const vector<MessageId> &message_ids, ReportReason &&reason,

View File

@ -6867,8 +6867,8 @@ void Td::on_request(uint64 id, const td_api::setChatDiscussionGroup &request) {
void Td::on_request(uint64 id, td_api::setChatLocation &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_channel_location(DialogId(request.chat_id_), DialogLocation(std::move(request.location_)),
std::move(promise));
dialog_manager_->set_dialog_location(DialogId(request.chat_id_), DialogLocation(std::move(request.location_)),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatSlowModeDelay &request) {