Add td_api::setChatDiscussionGroup.

GitOrigin-RevId: 59c2ec4a0b81973f4672ed2f3ca2a3fd01f36279
This commit is contained in:
levlam 2019-09-14 05:35:56 +03:00
parent 1021269634
commit 74219aa2d3
7 changed files with 156 additions and 7 deletions

View File

@ -440,7 +440,7 @@ basicGroupFullInfo description:string creator_user_id:int32 members:vector<chatM
//@date Point in time (Unix timestamp) when the current user joined, or the point in time when the supergroup or channel was created, in case the user is not a member
//@status Status of the current user in the supergroup or channel
//@member_count Member count; 0 if unknown. Currently it is guaranteed to be known only if the supergroup or channel was found through SearchPublicChats
//@has_linked_chat True, if the channel has a discussion supergroup, or the supergroup is a discussion supergroup for a channel
//@has_linked_chat True, if the channel has a discussion group, or the supergroup is a discussion group for a channel
//@sign_messages True, if messages sent to the channel should contain information about the sender. This field is only applicable to channels
//@is_channel True, if the supergroup is a channel
//@is_verified True, if the supergroup or channel is verified
@ -455,12 +455,12 @@ supergroup id:int32 username:string date:int32 status:ChatMemberStatus member_co
//@administrator_count Number of privileged users in the supergroup or channel; 0 if unknown
//@restricted_count Number of restricted users in the supergroup; 0 if unknown
//@banned_count Number of users banned from chat; 0 if unknown
//@linked_chat_id Chat identifier of a discussion supergroup for the channel, or a channel, for which the supergroup is a discussion supergroup; 0 if none or unknown
//@linked_chat_id Chat identifier of a discussion group for the channel, or a channel, for which the supergroup is a discussion group; 0 if none or unknown
//@can_get_members True, if members of the chat can be retrieved
//@can_set_username True, if the chat can be made public
//@can_set_sticker_set True, if the supergroup sticker set can be changed
//@can_view_statistics True, if the channel statistics is available through getChatStatisticsUrl
//@is_all_history_available True, if new chat members will have access to old messages. In public or discussion supergroups and both public and private channels, old messages are always available, so this option affects only private supergroups without a linked chat. The value of this field is only available for chat administrators
//@is_all_history_available True, if new chat members will have access to old messages. In public or discussion groups and both public and private channels, old messages are always available, so this option affects only private supergroups without a linked chat. The value of this field is only available for chat administrators
//@sticker_set_id Identifier of the supergroup sticker set; 0 if none
//@invite_link Invite link for this chat
//@upgraded_from_basic_group_id Identifier of the basic group from which supergroup was upgraded; 0 if none
@ -510,8 +510,8 @@ messageForwardOriginChannel chat_id:int53 message_id:int53 author_signature:stri
//@description Contains information about a forwarded message
//@origin Origin of a forwarded message
//@date Point in time (Unix timestamp) when the message was originally sent
//@from_chat_id For messages forwarded to the chat with the current user (saved messages) or to the channel discussion supergroup, the identifier of the chat from which the message was forwarded last time; 0 if unknown
//@from_message_id For messages forwarded to the chat with the current user (saved messages) or to the channel discussion supergroup, the identifier of the original message from which the new message was forwarded last time; 0 if unknown
//@from_chat_id For messages forwarded to the chat with the current user (saved messages) or to the channel's discussion group, the identifier of the chat from which the message was forwarded last time; 0 if unknown
//@from_message_id For messages forwarded to the chat with the current user (saved messages) or to the channel's discussion group, the identifier of the original message from which the new message was forwarded last time; 0 if unknown
messageForwardInfo origin:MessageForwardOrigin date:int32 from_chat_id:int53 from_message_id:int53 = MessageForwardInfo;
@ -3404,6 +3404,10 @@ setChatClientData chat_id:int53 client_data:string = Ok;
//@description Changes information about a chat. Available for basic groups, supergroups, and channels. Requires can_change_info rights @chat_id Identifier of the chat @param_description New chat description; 0-255 characters
setChatDescription chat_id:int53 description:string = Ok;
//@description Changes the discussion group of a channel chat; requires can_change_info rights @chat_id Identifier of the channel chat @discussion_chat_id Identifier of a new channel's discussion group. Use 0 to remove the discussion group.
//-If new chat members don't have access to old messages in the supergroup, then toggleSupergroupIsAllHistoryAvailable needs to be used first to change that
setChatDiscussionGroup chat_id:int53 discussion_chat_id:int53 = Ok;
//@description Pins a message in a chat; requires can_pin_messages rights @chat_id Identifier of the chat @message_id Identifier of the new pinned message @disable_notification True, if there should be no notification about the pinned message
pinChatMessage chat_id:int53 message_id:int53 disable_notification:Bool = Ok;

Binary file not shown.

View File

@ -1192,6 +1192,45 @@ class EditChatAboutQuery : public Td::ResultHandler {
}
};
class SetDiscussionGroupQuery : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId broadcast_channel_id_;
ChannelId group_channel_id_;
public:
explicit SetDiscussionGroupQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId broadcast_channel_id,
telegram_api::object_ptr<telegram_api::InputChannel> broadcast_input_channel, ChannelId group_channel_id,
telegram_api::object_ptr<telegram_api::InputChannel> group_input_channel) {
broadcast_channel_id_ = broadcast_channel_id;
group_channel_id_ = group_channel_id;
send_query(G()->net_query_creator().create(create_storer(telegram_api::channels_setDiscussionGroup(
std::move(broadcast_input_channel), std::move(group_input_channel)))));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::channels_setDiscussionGroup>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
bool result = result_ptr.move_as_ok();
LOG_IF(INFO, !result) << "Set discussion group has failed";
td->contacts_manager_->on_update_channel_linked_channel_id(broadcast_channel_id_, group_channel_id_);
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) override {
if (status.message() == "LINK_NOT_MODIFIED") {
return promise_.set_value(Unit());
}
promise_.set_error(std::move(status));
}
};
class ReportChannelSpamQuery : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
@ -4303,6 +4342,76 @@ void ContactsManager::set_channel_description(ChannelId channel_id, const string
td_->create_handler<EditChatAboutQuery>(std::move(promise))->send(DialogId(channel_id), new_description);
}
void ContactsManager::set_channel_discussion_group(DialogId dialog_id, DialogId discussion_dialog_id,
Promise<Unit> &&promise) {
if (!dialog_id.is_valid() && !discussion_dialog_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid chat identifiers specified"));
}
ChannelId broadcast_channel_id;
telegram_api::object_ptr<telegram_api::InputChannel> broadcast_input_channel;
if (dialog_id.is_valid()) {
if (!td_->messages_manager_->have_dialog_force(dialog_id)) {
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 channel"));
}
broadcast_channel_id = dialog_id.get_channel_id();
const Channel *c = get_channel(broadcast_channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (c->is_megagroup) {
return promise.set_error(Status::Error(400, "Chat is not a channel"));
}
if (!c->status.is_administrator() || !c->status.can_change_info_and_settings()) {
return promise.set_error(Status::Error(400, "Have not enough rights in the channel"));
}
broadcast_input_channel = td_->contacts_manager_->get_input_channel(broadcast_channel_id);
CHECK(broadcast_input_channel != nullptr);
} else {
broadcast_input_channel = telegram_api::make_object<telegram_api::inputChannelEmpty>();
}
ChannelId group_channel_id;
telegram_api::object_ptr<telegram_api::InputChannel> group_input_channel;
if (discussion_dialog_id.is_valid()) {
if (!td_->messages_manager_->have_dialog_force(discussion_dialog_id)) {
return promise.set_error(Status::Error(400, "Discussion chat not found"));
}
if (discussion_dialog_id.get_type() != DialogType::Channel) {
return promise.set_error(Status::Error(400, "Discussion chat is not a supergroup"));
}
group_channel_id = discussion_dialog_id.get_channel_id();
const Channel *c = get_channel(group_channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Discussion chat info not found"));
}
if (!c->is_megagroup) {
return promise.set_error(Status::Error(400, "Discussion chat is not a supergroup"));
}
if (!c->status.is_administrator() || !c->status.can_pin_messages()) {
return promise.set_error(Status::Error(400, "Have not enough rights in the supergroup"));
}
group_input_channel = td_->contacts_manager_->get_input_channel(group_channel_id);
CHECK(group_input_channel != nullptr);
} else {
group_input_channel = telegram_api::make_object<telegram_api::inputChannelEmpty>();
}
td_->create_handler<SetDiscussionGroupQuery>(std::move(promise))
->send(broadcast_channel_id, std::move(broadcast_input_channel), group_channel_id,
std::move(group_input_channel));
}
void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
@ -8180,13 +8289,13 @@ void ContactsManager::on_update_channel_full_invite_link(
void ContactsManager::on_update_channel_full_linked_channel_id(ChannelFull *channel_full, ChannelId channel_id,
ChannelId linked_channel_id) {
CHECK(channel_full != nullptr);
if (channel_full->linked_channel_id != linked_channel_id) {
if (channel_full != nullptr && channel_full->linked_channel_id != linked_channel_id) {
if (channel_full->linked_channel_id.is_valid()) {
// remove link from a previously linked channel_full
auto linked_channel = get_channel_force(channel_full->linked_channel_id);
if (linked_channel != nullptr && linked_channel->has_linked_channel) {
linked_channel->has_linked_channel = false;
linked_channel->need_send_update = true;
update_channel(linked_channel, channel_full->linked_channel_id);
reload_channel(channel_full->linked_channel_id, Auto());
}
@ -8206,6 +8315,7 @@ void ContactsManager::on_update_channel_full_linked_channel_id(ChannelFull *chan
auto linked_channel = get_channel_force(channel_full->linked_channel_id);
if (linked_channel != nullptr && !linked_channel->has_linked_channel) {
linked_channel->has_linked_channel = true;
linked_channel->need_send_update = true;
update_channel(linked_channel, channel_full->linked_channel_id);
reload_channel(channel_full->linked_channel_id, Auto());
}
@ -8972,6 +9082,23 @@ void ContactsManager::on_update_channel_sticker_set(ChannelId channel_id, int64
}
}
void ContactsManager::on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id) {
if (channel_id.is_valid()) {
auto channel_full = get_channel_full(channel_id);
on_update_channel_full_linked_channel_id(channel_full, channel_id, group_channel_id);
if (channel_full != nullptr) {
update_channel_full(channel_full, channel_id);
}
}
if (group_channel_id.is_valid()) {
auto channel_full = get_channel_full(group_channel_id);
on_update_channel_full_linked_channel_id(channel_full, group_channel_id, channel_id);
if (channel_full != nullptr) {
update_channel_full(channel_full, group_channel_id);
}
}
}
void ContactsManager::on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available) {
if (!channel_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << channel_id;

View File

@ -177,6 +177,7 @@ class ContactsManager : public Actor {
void on_update_channel_username(ChannelId channel_id, string &&username);
void on_update_channel_description(ChannelId channel_id, string &&description);
void on_update_channel_sticker_set(ChannelId channel_id, int64 sticker_set_id);
void on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id);
void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available);
void on_update_channel_default_permissions(ChannelId channel_id, RestrictedRights default_permissions);
@ -306,6 +307,8 @@ class ContactsManager : public Actor {
void set_channel_description(ChannelId channel_id, const string &description, Promise<Unit> &&promise);
void set_channel_discussion_group(DialogId dialog_id, DialogId discussion_dialog_id, Promise<Unit> &&promise);
void report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
Promise<Unit> &&promise);

View File

@ -6064,6 +6064,13 @@ void Td::on_request(uint64 id, td_api::setChatDescription &request) {
messages_manager_->set_dialog_description(DialogId(request.chat_id_), request.description_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatDiscussionGroup &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_channel_discussion_group(DialogId(request.chat_id_), DialogId(request.discussion_chat_id_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::pinChatMessage &request) {
CREATE_OK_REQUEST_PROMISE();
messages_manager_->pin_dialog_message(DialogId(request.chat_id_), MessageId(request.message_id_),

View File

@ -668,6 +668,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::setChatDescription &request);
void on_request(uint64 id, const td_api::setChatDiscussionGroup &request);
void on_request(uint64 id, const td_api::pinChatMessage &request);
void on_request(uint64 id, const td_api::unpinChatMessage &request);

View File

@ -3473,6 +3473,12 @@ class CliClient final : public Actor {
std::tie(chat_id, description) = split(args);
send_request(td_api::make_object<td_api::setChatDescription>(as_chat_id(chat_id), description));
} else if (op == "scdg") {
string chat_id;
string group_chat_id;
std::tie(chat_id, group_chat_id) = split(args);
send_request(td_api::make_object<td_api::setChatDiscussionGroup>(as_chat_id(chat_id), as_chat_id(group_chat_id)));
} else if (op == "pcm" || op == "pcms") {
string chat_id;
string message_id;