Skip to content

Commit fe749cf

Browse files
committed
Add DialogManager::set_dialog_location.
1 parent 6c5441c commit fe749cf

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

td/telegram/ContactsManager.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7714,24 +7714,12 @@ void ContactsManager::set_channel_discussion_group(DialogId dialog_id, DialogId
77147714
std::move(group_input_channel));
77157715
}
77167716

7717-
void ContactsManager::set_channel_location(DialogId dialog_id, const DialogLocation &location,
7717+
void ContactsManager::set_channel_location(ChannelId channel_id, const DialogLocation &location,
77187718
Promise<Unit> &&promise) {
77197719
if (location.empty()) {
77207720
return promise.set_error(Status::Error(400, "Invalid chat location specified"));
77217721
}
77227722

7723-
if (!dialog_id.is_valid()) {
7724-
return promise.set_error(Status::Error(400, "Invalid chat identifier specified"));
7725-
}
7726-
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "set_channel_location")) {
7727-
return promise.set_error(Status::Error(400, "Chat not found"));
7728-
}
7729-
7730-
if (dialog_id.get_type() != DialogType::Channel) {
7731-
return promise.set_error(Status::Error(400, "Chat is not a supergroup"));
7732-
}
7733-
7734-
auto channel_id = dialog_id.get_channel_id();
77357723
const Channel *c = get_channel(channel_id);
77367724
if (c == nullptr) {
77377725
return promise.set_error(Status::Error(400, "Chat info not found"));

td/telegram/ContactsManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class ContactsManager final : public Actor {
506506

507507
void set_channel_discussion_group(DialogId dialog_id, DialogId discussion_dialog_id, Promise<Unit> &&promise);
508508

509-
void set_channel_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
509+
void set_channel_location(ChannelId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
510510

511511
void set_channel_slow_mode_delay(DialogId dialog_id, int32 slow_mode_delay, Promise<Unit> &&promise);
512512

td/telegram/DialogManager.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,24 @@ void DialogManager::set_dialog_description(DialogId dialog_id, const string &des
16071607
}
16081608
}
16091609

1610+
void DialogManager::set_dialog_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise) {
1611+
if (!have_dialog_force(dialog_id, "set_dialog_location")) {
1612+
return promise.set_error(Status::Error(400, "Chat not found"));
1613+
}
1614+
1615+
switch (dialog_id.get_type()) {
1616+
case DialogType::User:
1617+
case DialogType::Chat:
1618+
case DialogType::SecretChat:
1619+
return promise.set_error(Status::Error(400, "The chat can't have location"));
1620+
case DialogType::Channel:
1621+
return td_->contacts_manager_->set_channel_location(dialog_id.get_channel_id(), location, std::move(promise));
1622+
case DialogType::None:
1623+
default:
1624+
UNREACHABLE();
1625+
}
1626+
}
1627+
16101628
bool DialogManager::can_report_dialog(DialogId dialog_id) const {
16111629
// doesn't include possibility of report from action bar
16121630
switch (dialog_id.get_type()) {

td/telegram/DialogManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "td/telegram/ChannelId.h"
1212
#include "td/telegram/CustomEmojiId.h"
1313
#include "td/telegram/DialogId.h"
14+
#include "td/telegram/DialogLocation.h"
1415
#include "td/telegram/DialogParticipant.h"
1516
#include "td/telegram/EmojiStatus.h"
1617
#include "td/telegram/files/FileId.h"
@@ -158,6 +159,8 @@ class DialogManager final : public Actor {
158159

159160
void set_dialog_description(DialogId dialog_id, const string &description, Promise<Unit> &&promise);
160161

162+
void set_dialog_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
163+
161164
bool can_report_dialog(DialogId dialog_id) const;
162165

163166
void report_dialog(DialogId dialog_id, const vector<MessageId> &message_ids, ReportReason &&reason,

td/telegram/Td.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6867,8 +6867,8 @@ void Td::on_request(uint64 id, const td_api::setChatDiscussionGroup &request) {
68676867
void Td::on_request(uint64 id, td_api::setChatLocation &request) {
68686868
CHECK_IS_USER();
68696869
CREATE_OK_REQUEST_PROMISE();
6870-
contacts_manager_->set_channel_location(DialogId(request.chat_id_), DialogLocation(std::move(request.location_)),
6871-
std::move(promise));
6870+
dialog_manager_->set_dialog_location(DialogId(request.chat_id_), DialogLocation(std::move(request.location_)),
6871+
std::move(promise));
68726872
}
68736873

68746874
void Td::on_request(uint64 id, const td_api::setChatSlowModeDelay &request) {

0 commit comments

Comments
 (0)