Allow to edit forum topic by its creator.

This commit is contained in:
levlam 2022-10-27 19:18:25 +03:00
parent f79e67cab8
commit 25b7412042
3 changed files with 14 additions and 4 deletions

View File

@ -5300,14 +5300,14 @@ getForumTopicDefaultIcons = Stickers;
//@icon Icon of the topic. Icon color must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F. Telegram Premium users can use any custom emoji as topic icon, other users can use only a custom emoji returned by getForumTopicDefaultIcons
createForumTopic chat_id:int53 title:string icon:forumTopicIcon = ForumTopicInfo;
//@description Edits title and icon of a topic in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup
//@description Edits title and icon of a topic in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup unless the user is creator of the topic
//@chat_id Identifier of the chat
//@message_thread_id Message thread identifier of the forum topic
//@title New title of the topic
//@icon_custom_emoji_id Identifier of the new custom emoji for topic icon. Telegram Premium users can use any custom emoji, other users can use only a custom emoji returned by getForumTopicDefaultIcons
editForumTopic chat_id:int53 message_thread_id:int53 title:string icon_custom_emoji_id:int64 = Ok;
//@description Toggles is_closed state of a topic in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup
//@description Toggles is_closed state of a topic in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup unless the user is creator of the topic
//@chat_id Identifier of the chat
//@message_thread_id Message thread identifier of the forum topic
//@is_closed Pass true to close the topic; pass false to open it

View File

@ -55,6 +55,10 @@ class ForumTopicInfo {
return top_thread_message_id_;
}
bool is_outgoing() const {
return is_outgoing_;
}
bool apply_edited_data(const ForumTopicEditedData &edited_data);
td_api::object_ptr<td_api::forumTopicInfo> get_forum_topic_info_object(Td *td) const;

View File

@ -236,7 +236,10 @@ void ForumTopicManager::edit_forum_topic(DialogId dialog_id, MessageId top_threa
}
if (!td_->contacts_manager_->get_channel_permissions(channel_id).can_edit_topics()) {
return promise.set_error(Status::Error(400, "Not enough rights to edit a topic"));
auto topic_info = get_topic_info(dialog_id, top_thread_message_id);
if (topic_info != nullptr && !topic_info->is_outgoing()) {
return promise.set_error(Status::Error(400, "Not enough rights to edit the topic"));
}
}
auto new_title = clean_name(std::move(title), MAX_FORUM_TOPIC_TITLE_LENGTH);
@ -258,7 +261,10 @@ void ForumTopicManager::toggle_forum_topic_is_closed(DialogId dialog_id, Message
}
if (!td_->contacts_manager_->get_channel_permissions(channel_id).can_edit_topics()) {
return promise.set_error(Status::Error(400, "Not enough rights to edit a topic"));
auto topic_info = get_topic_info(dialog_id, top_thread_message_id);
if (topic_info != nullptr && !topic_info->is_outgoing()) {
return promise.set_error(Status::Error(400, "Not enough rights to close or open the topic"));
}
}
td_->create_handler<EditForumTopicQuery>(std::move(promise))->send(channel_id, top_thread_message_id, is_closed);