Support STORY_DELETED push notification.

This commit is contained in:
levlam 2023-06-22 15:56:34 +03:00
parent 579eef5f10
commit f39b906b28
3 changed files with 38 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatId.h"
#include "td/telegram/ServerMessageId.h" #include "td/telegram/ServerMessageId.h"
#include "td/telegram/StateManager.h" #include "td/telegram/StateManager.h"
#include "td/telegram/StoryManager.h"
#include "td/telegram/Td.h" #include "td/telegram/Td.h"
#include "td/telegram/TdDb.h" #include "td/telegram/TdDb.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
@ -3215,6 +3216,26 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
return Status::Error(406, "Notifications about muted messages force loading data from the server"); return Status::Error(406, "Notifications about muted messages force loading data from the server");
} }
if (loc_key == "STORY_DELETED") {
if (dialog_id.get_type() != DialogType::SecretChat) {
return Status::Error("Receive STORY_DELETED in a secret chat");
}
TRY_RESULT(server_story_ids_str, get_json_object_string_field(custom, "story_id", false));
auto server_story_ids = full_split(server_story_ids_str, ',');
vector<StoryId> story_ids;
for (const auto &server_story_id_str : server_story_ids) {
TRY_RESULT(story_id_int, to_integer_safe<int32>(server_story_id_str));
StoryId story_id(story_id_int);
if (!story_id.is_server()) {
return Status::Error("Receive invalid story identifier");
}
story_ids.push_back(story_id);
}
td_->story_manager_->remove_story_notifications_by_story_ids(dialog_id, story_ids);
promise.set_value(Unit());
return Status::OK();
}
TRY_RESULT(msg_id, get_json_object_int_field(custom, "msg_id")); TRY_RESULT(msg_id, get_json_object_int_field(custom, "msg_id"));
ServerMessageId server_message_id(msg_id); ServerMessageId server_message_id(msg_id);
if (server_message_id != ServerMessageId() && !server_message_id.is_valid()) { if (server_message_id != ServerMessageId() && !server_message_id.is_valid()) {

View File

@ -16,6 +16,7 @@
#include "td/telegram/logevent/LogEventHelper.h" #include "td/telegram/logevent/LogEventHelper.h"
#include "td/telegram/MessageEntity.h" #include "td/telegram/MessageEntity.h"
#include "td/telegram/MessagesManager.h" #include "td/telegram/MessagesManager.h"
#include "td/telegram/NotificationManager.h"
#include "td/telegram/OptionManager.h" #include "td/telegram/OptionManager.h"
#include "td/telegram/ReportReason.h" #include "td/telegram/ReportReason.h"
#include "td/telegram/StoryContent.h" #include "td/telegram/StoryContent.h"
@ -2283,6 +2284,20 @@ telegram_api::object_ptr<telegram_api::InputMedia> StoryManager::get_input_media
story_full_id.get_story_id().get()); story_full_id.get_story_id().get());
} }
void StoryManager::remove_story_notifications_by_story_ids(DialogId dialog_id, const vector<StoryId> &story_ids) {
VLOG(notifications) << "Trying to remove notification about " << story_ids << " in " << dialog_id;
for (auto story_id : story_ids) {
if (!have_story_force({dialog_id, story_id})) {
LOG(INFO) << "Can't delete " << story_id << " because it is not found";
// call synchronously to remove them before ProcessPush returns
// td_->notification_manager_->remove_temporary_notification_by_story_id(
// story_notification_group_id, story_id, true, "remove_story_notifications_by_story_ids");
continue;
}
on_delete_story(dialog_id, story_id);
}
}
void StoryManager::on_binlog_events(vector<BinlogEvent> &&events) { void StoryManager::on_binlog_events(vector<BinlogEvent> &&events) {
if (G()->close_flag()) { if (G()->close_flag()) {
return; return;

View File

@ -135,6 +135,8 @@ class StoryManager final : public Actor {
void report_story(StoryFullId story_full_id, ReportReason &&reason, Promise<Unit> &&promise); void report_story(StoryFullId story_full_id, ReportReason &&reason, Promise<Unit> &&promise);
void remove_story_notifications_by_story_ids(DialogId dialog_id, const vector<StoryId> &story_ids);
StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr); StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr);
std::pair<int32, vector<StoryId>> on_get_stories(DialogId owner_dialog_id, vector<StoryId> &&expected_story_ids, std::pair<int32, vector<StoryId>> on_get_stories(DialogId owner_dialog_id, vector<StoryId> &&expected_story_ids,