Add td_api::toggleChatViewAsTopics.
This commit is contained in:
parent
57e9a6c5f7
commit
a2b133ead5
@ -7734,6 +7734,9 @@ setChatNotificationSettings chat_id:int53 notification_settings:chatNotification
|
||||
//@has_protected_content New value of has_protected_content
|
||||
toggleChatHasProtectedContent chat_id:int53 has_protected_content:Bool = Ok;
|
||||
|
||||
//@description Changes the view_as_topics setting of a forum chat @chat_id Chat identifier @view_as_topics New value of view_as_topics
|
||||
toggleChatViewAsTopics chat_id:int53 view_as_topics:Bool = Ok;
|
||||
|
||||
//@description Changes the translatable state of a chat @chat_id Chat identifier @is_translatable New value of is_translatable
|
||||
toggleChatIsTranslatable chat_id:int53 is_translatable:Bool = Ok;
|
||||
|
||||
|
@ -1523,6 +1523,48 @@ class ReorderPinnedDialogsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class ToggleViewForumAsMessagesQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
DialogId dialog_id_;
|
||||
bool view_as_messages_;
|
||||
|
||||
public:
|
||||
explicit ToggleViewForumAsMessagesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, bool view_as_messages) {
|
||||
dialog_id_ = dialog_id;
|
||||
view_as_messages_ = view_as_messages;
|
||||
|
||||
CHECK(dialog_id.get_type() == DialogType::Channel);
|
||||
auto input_channel = td_->contacts_manager_->get_input_channel(dialog_id.get_channel_id());
|
||||
CHECK(input_channel != nullptr);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::channels_toggleViewForumAsMessages(std::move(input_channel), view_as_messages), {{dialog_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::channels_toggleViewForumAsMessages>(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 ToggleViewForumAsMessagesQuery: " << to_string(ptr);
|
||||
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
if (!td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "ToggleViewForumAsMessagesQuery")) {
|
||||
LOG(ERROR) << "Receive error for ToggleViewForumAsMessagesQuery: " << status;
|
||||
}
|
||||
if (!G()->close_flag()) {
|
||||
td_->messages_manager_->on_update_dialog_view_as_messages(dialog_id_, !view_as_messages_);
|
||||
}
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ToggleDialogUnreadMarkQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
DialogId dialog_id_;
|
||||
@ -19353,6 +19395,69 @@ void MessagesManager::reorder_pinned_dialogs_on_server(FolderId folder_id, const
|
||||
->send(folder_id, dialog_ids);
|
||||
}
|
||||
|
||||
Status MessagesManager::toggle_dialog_view_as_messages(DialogId dialog_id, bool view_as_messages) {
|
||||
Dialog *d = get_dialog_force(dialog_id, "toggle_dialog_view_as_messages");
|
||||
if (d == nullptr) {
|
||||
return Status::Error(400, "Chat not found");
|
||||
}
|
||||
if (!have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
return Status::Error(400, "Can't access the chat");
|
||||
}
|
||||
if (!is_forum_channel(dialog_id)) {
|
||||
return Status::Error(400, "The method is available only in forum channels");
|
||||
}
|
||||
|
||||
if (view_as_messages == d->view_as_messages) {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
set_dialog_view_as_messages(d, view_as_messages);
|
||||
|
||||
toggle_dialog_view_as_messages_on_server(dialog_id, view_as_messages, 0);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
class MessagesManager::ToggleDialogViewAsMessagesOnServerLogEvent {
|
||||
public:
|
||||
DialogId dialog_id_;
|
||||
bool view_as_messages_;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(view_as_messages_);
|
||||
END_STORE_FLAGS();
|
||||
|
||||
td::store(dialog_id_, storer);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser) {
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(view_as_messages_);
|
||||
END_PARSE_FLAGS();
|
||||
|
||||
td::parse(dialog_id_, parser);
|
||||
}
|
||||
};
|
||||
|
||||
uint64 MessagesManager::save_toggle_dialog_view_as_messages_on_server_log_event(DialogId dialog_id,
|
||||
bool view_as_messages) {
|
||||
ToggleDialogViewAsMessagesOnServerLogEvent log_event{dialog_id, view_as_messages};
|
||||
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogViewAsMessagesOnServer,
|
||||
get_log_event_storer(log_event));
|
||||
}
|
||||
|
||||
void MessagesManager::toggle_dialog_view_as_messages_on_server(DialogId dialog_id, bool view_as_messages,
|
||||
uint64 log_event_id) {
|
||||
if (log_event_id == 0 && G()->use_message_database()) {
|
||||
log_event_id = save_toggle_dialog_view_as_messages_on_server_log_event(dialog_id, view_as_messages);
|
||||
}
|
||||
|
||||
td_->create_handler<ToggleViewForumAsMessagesQuery>(get_erase_log_event_promise(log_event_id))
|
||||
->send(dialog_id, view_as_messages);
|
||||
}
|
||||
|
||||
Status MessagesManager::toggle_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread) {
|
||||
Dialog *d = get_dialog_force(dialog_id, "toggle_dialog_is_marked_as_unread");
|
||||
if (d == nullptr) {
|
||||
@ -40182,6 +40287,25 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
||||
reorder_pinned_dialogs_on_server(log_event.folder_id_, dialog_ids, event.id_);
|
||||
break;
|
||||
}
|
||||
case LogEvent::HandlerType::ToggleDialogViewAsMessagesOnServer: {
|
||||
if (!have_old_message_database) {
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
break;
|
||||
}
|
||||
|
||||
ToggleDialogViewAsMessagesOnServerLogEvent log_event;
|
||||
log_event_parse(log_event, event.get_data()).ensure();
|
||||
|
||||
auto dialog_id = log_event.dialog_id_;
|
||||
if (!have_dialog_force(dialog_id, "ToggleDialogViewAsMessagesOnServerLogEvent") ||
|
||||
!have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
break;
|
||||
}
|
||||
|
||||
toggle_dialog_view_as_messages_on_server(dialog_id, log_event.view_as_messages_, event.id_);
|
||||
break;
|
||||
}
|
||||
case LogEvent::HandlerType::ToggleDialogIsTranslatableOnServer: {
|
||||
if (!have_old_message_database) {
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
|
@ -704,6 +704,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
Status toggle_dialog_is_pinned(DialogListId dialog_list_id, DialogId dialog_id, bool is_pinned) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Status toggle_dialog_view_as_messages(DialogId dialog_id, bool view_as_messages) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Status toggle_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Status toggle_dialog_is_translatable(DialogId dialog_id, bool is_translatable) TD_WARN_UNUSED_RESULT;
|
||||
@ -1678,6 +1680,7 @@ class MessagesManager final : public Actor {
|
||||
class SendScreenshotTakenNotificationMessageLogEvent;
|
||||
class SetDialogFolderIdOnServerLogEvent;
|
||||
class ToggleDialogIsBlockedOnServerLogEvent;
|
||||
class ToggleDialogViewAsMessagesOnServerLogEvent;
|
||||
class ToggleDialogIsMarkedAsUnreadOnServerLogEvent;
|
||||
class ToggleDialogIsTranslatableOnServerLogEvent;
|
||||
class ToggleDialogIsPinnedOnServerLogEvent;
|
||||
@ -2628,6 +2631,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
void toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 log_event_id);
|
||||
|
||||
void toggle_dialog_view_as_messages_on_server(DialogId dialog_id, bool view_as_messages, uint64 log_event_id);
|
||||
|
||||
void toggle_dialog_is_marked_as_unread_on_server(DialogId dialog_id, bool is_marked_as_unread, uint64 log_event_id);
|
||||
|
||||
void toggle_dialog_is_translatable_on_server(DialogId dialog_id, bool is_translatable, uint64 log_event_id);
|
||||
@ -3245,6 +3250,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
static uint64 save_reorder_pinned_dialogs_on_server_log_event(FolderId folder_id, const vector<DialogId> &dialog_ids);
|
||||
|
||||
static uint64 save_toggle_dialog_view_as_messages_on_server_log_event(DialogId dialog_id, bool view_as_messages);
|
||||
|
||||
static uint64 save_toggle_dialog_is_marked_as_unread_on_server_log_event(DialogId dialog_id,
|
||||
bool is_marked_as_unread);
|
||||
|
||||
|
@ -6532,6 +6532,12 @@ void Td::on_request(uint64 id, const td_api::toggleChatIsPinned &request) {
|
||||
DialogId(request.chat_id_), request.is_pinned_));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::toggleChatViewAsTopics &request) {
|
||||
CHECK_IS_USER();
|
||||
answer_ok_query(
|
||||
id, messages_manager_->toggle_dialog_view_as_messages(DialogId(request.chat_id_), !request.view_as_topics_));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::toggleChatIsTranslatable &request) {
|
||||
CHECK_IS_USER();
|
||||
answer_ok_query(
|
||||
|
@ -1016,6 +1016,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::toggleChatIsPinned &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::toggleChatViewAsTopics &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::toggleChatIsTranslatable &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::toggleChatIsMarkedAsUnread &request);
|
||||
|
@ -125,6 +125,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
|
||||
case LogEvent::HandlerType::ReadAllDialogReactionsOnServer:
|
||||
case LogEvent::HandlerType::DeleteTopicHistoryOnServer:
|
||||
case LogEvent::HandlerType::ToggleDialogIsTranslatableOnServer:
|
||||
case LogEvent::HandlerType::ToggleDialogViewAsMessagesOnServer:
|
||||
events.to_messages_manager.push_back(event.clone());
|
||||
break;
|
||||
case LogEvent::HandlerType::DeleteStoryOnServer:
|
||||
|
@ -4193,6 +4193,11 @@ class CliClient final : public Actor {
|
||||
bool is_marked_as_unread;
|
||||
get_args(args, chat_id, is_marked_as_unread);
|
||||
send_request(td_api::make_object<td_api::toggleChatIsMarkedAsUnread>(chat_id, is_marked_as_unread));
|
||||
} else if (op == "tcvat") {
|
||||
ChatId chat_id;
|
||||
bool view_as_topics;
|
||||
get_args(args, chat_id, view_as_topics);
|
||||
send_request(td_api::make_object<td_api::toggleChatViewAsTopics>(chat_id, view_as_topics));
|
||||
} else if (op == "tcit") {
|
||||
ChatId chat_id;
|
||||
bool is_translatable;
|
||||
|
@ -103,6 +103,7 @@ class LogEvent {
|
||||
ReadAllDialogReactionsOnServer = 0x124,
|
||||
DeleteTopicHistoryOnServer = 0x125,
|
||||
ToggleDialogIsTranslatableOnServer = 0x126,
|
||||
ToggleDialogViewAsMessagesOnServer = 0x127,
|
||||
GetChannelDifference = 0x140,
|
||||
AddMessagePushNotification = 0x200,
|
||||
EditMessagePushNotification = 0x201,
|
||||
|
Loading…
Reference in New Issue
Block a user