Add toggleSupergroupIsForum.
This commit is contained in:
parent
9edfdcfd1e
commit
9b304557c2
@ -6380,6 +6380,9 @@ toggleSupergroupJoinByRequest supergroup_id:int53 join_by_request:Bool = Ok;
|
||||
//@description Toggles whether the message history of a supergroup is available to new members; requires can_change_info administrator right @supergroup_id The identifier of the supergroup @is_all_history_available The new value of is_all_history_available
|
||||
toggleSupergroupIsAllHistoryAvailable supergroup_id:int53 is_all_history_available:Bool = Ok;
|
||||
|
||||
//@description Toggles whether the supergroup is a forum; requires owner privileges in the supergroup @supergroup_id Identifier of the supergroup @is_forum New value of is_forum
|
||||
toggleSupergroupIsForum supergroup_id:int53 is_forum:Bool = Ok;
|
||||
|
||||
//@description Upgrades supergroup to a broadcast group; requires owner privileges in the supergroup @supergroup_id Identifier of the supergroup
|
||||
toggleSupergroupIsBroadcastGroup supergroup_id:int53 = Ok;
|
||||
|
||||
|
@ -1213,6 +1213,47 @@ class TogglePrehistoryHiddenQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class ToggleForumQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
ChannelId channel_id_;
|
||||
|
||||
public:
|
||||
explicit ToggleForumQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(ChannelId channel_id, bool is_forum) {
|
||||
channel_id_ = channel_id;
|
||||
|
||||
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
|
||||
CHECK(input_channel != nullptr);
|
||||
send_query(G()->net_query_creator().create(telegram_api::channels_toggleForum(std::move(input_channel), is_forum),
|
||||
{{channel_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::channels_toggleForum>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for ToggleForumQuery: " << to_string(ptr);
|
||||
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
if (status.message() == "CHAT_NOT_MODIFIED") {
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
promise_.set_value(Unit());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ToggleForumQuery");
|
||||
}
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ConvertToGigagroupQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
ChannelId channel_id_;
|
||||
@ -7189,6 +7230,24 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_
|
||||
td_->create_handler<TogglePrehistoryHiddenQuery>(std::move(promise))->send(channel_id, is_all_history_available);
|
||||
}
|
||||
|
||||
void ContactsManager::toggle_channel_is_forum(ChannelId channel_id, bool is_forum, Promise<Unit> &&promise) {
|
||||
auto c = get_channel(channel_id);
|
||||
if (c == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Supergroup not found"));
|
||||
}
|
||||
if (c->is_forum == is_forum) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
if (!get_channel_permissions(c).is_creator()) {
|
||||
return promise.set_error(Status::Error(400, "Not enough rights to convert the group to a forum"));
|
||||
}
|
||||
if (get_channel_type(c) != ChannelType::Megagroup) {
|
||||
return promise.set_error(Status::Error(400, "Forums can be enabled in supergroups only"));
|
||||
}
|
||||
|
||||
td_->create_handler<ToggleForumQuery>(std::move(promise))->send(channel_id, is_forum);
|
||||
}
|
||||
|
||||
void ContactsManager::convert_channel_to_gigagroup(ChannelId channel_id, Promise<Unit> &&promise) {
|
||||
auto c = get_channel(channel_id);
|
||||
if (c == nullptr) {
|
||||
|
@ -387,6 +387,8 @@ class ContactsManager final : public Actor {
|
||||
void toggle_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void toggle_channel_is_forum(ChannelId channel_id, bool is_forum, Promise<Unit> &&promise);
|
||||
|
||||
void convert_channel_to_gigagroup(ChannelId channel_id, Promise<Unit> &&promise);
|
||||
|
||||
void set_channel_description(ChannelId channel_id, const string &description, Promise<Unit> &&promise);
|
||||
|
@ -6922,6 +6922,12 @@ void Td::on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailab
|
||||
request.is_all_history_available_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::toggleSupergroupIsForum &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->toggle_channel_is_forum(ChannelId(request.supergroup_id_), request.is_forum_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::toggleSupergroupIsBroadcastGroup &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1083,6 +1083,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailable &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::toggleSupergroupIsForum &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::toggleSupergroupIsBroadcastGroup &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::reportSupergroupSpam &request);
|
||||
|
@ -4584,6 +4584,11 @@ class CliClient final : public Actor {
|
||||
get_args(args, supergroup_id, is_all_history_available);
|
||||
send_request(td_api::make_object<td_api::toggleSupergroupIsAllHistoryAvailable>(as_supergroup_id(supergroup_id),
|
||||
is_all_history_available));
|
||||
} else if (op == "tsgif") {
|
||||
string supergroup_id;
|
||||
bool is_forum;
|
||||
get_args(args, supergroup_id, is_forum);
|
||||
send_request(td_api::make_object<td_api::toggleSupergroupIsForum>(as_supergroup_id(supergroup_id), is_forum));
|
||||
} else if (op == "ToggleSupergroupIsBroadcastGroup") {
|
||||
string supergroup_id;
|
||||
get_args(args, supergroup_id);
|
||||
|
Loading…
Reference in New Issue
Block a user