From 2ccd37584f054df154d9fbab5aa4b15892d74d93 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 10 Apr 2019 01:57:15 +0300 Subject: [PATCH] Delete downlaoded files when a temporary message push notification is deleted. GitOrigin-RevId: c0ad85377cf336d98fa5d79697f0389e3c65ec7c --- td/telegram/NotificationManager.cpp | 3 +++ td/telegram/NotificationType.cpp | 20 ++++++++++++++++++++ td/telegram/NotificationType.h | 3 +++ 3 files changed, 26 insertions(+) diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index e4788fe21..0659fb098 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -1902,6 +1902,9 @@ void NotificationManager::remove_temporary_notification_by_message_id(Notificati auto remove_notification_by_message_id = [&](auto ¬ifications) { for (auto ¬ification : notifications) { if (notification.type->get_message_id() == message_id) { + for (auto file_id : notification.type->get_file_ids(td_)) { + this->td_->file_manager_->delete_file(file_id, Promise<>(), "remove_temporary_notification_by_message_id"); + } return this->remove_notification(group_id, notification.notification_id, true, force_update, Auto()); } } diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index 725eaa884..7875bd894 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -36,6 +36,10 @@ class NotificationTypeMessage : public NotificationType { return message_id_; } + vector get_file_ids(const Td *td) const override { + return {}; + } + td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { auto message_object = G()->td().get_actor_unsafe()->messages_manager_->get_message_object({dialog_id, message_id_}); if (message_object == nullptr) { @@ -72,6 +76,10 @@ class NotificationTypeSecretChat : public NotificationType { return MessageId(); } + vector get_file_ids(const Td *td) const override { + return {}; + } + td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { return td_api::make_object(); } @@ -102,6 +110,10 @@ class NotificationTypeCall : public NotificationType { return MessageId::max(); } + vector get_file_ids(const Td *td) const override { + return {}; + } + td_api::object_ptr get_notification_type_object(DialogId dialog_id) const override { return td_api::make_object(call_id_.get()); } @@ -134,6 +146,14 @@ class NotificationTypePushMessage : public NotificationType { return message_id_; } + vector get_file_ids(const Td *td) const override { + if (!document_.empty()) { + return document_.get_file_ids(td); + } + + return photo_get_file_ids(photo_); + } + static td_api::object_ptr get_push_message_content_object(Slice key, const string &arg, const Photo &photo, const Document &document) { diff --git a/td/telegram/NotificationType.h b/td/telegram/NotificationType.h index 3e69b09d2..b359e8dc5 100644 --- a/td/telegram/NotificationType.h +++ b/td/telegram/NotificationType.h @@ -9,6 +9,7 @@ #include "td/telegram/CallId.h" #include "td/telegram/DialogId.h" #include "td/telegram/Document.h" +#include "td/telegram/files/FileId.h" #include "td/telegram/MessageId.h" #include "td/telegram/Photo.h" #include "td/telegram/td_api.h" @@ -36,6 +37,8 @@ class NotificationType { virtual MessageId get_message_id() const = 0; + virtual vector get_file_ids(const Td *td) const = 0; + virtual td_api::object_ptr get_notification_type_object(DialogId dialog_id) const = 0; virtual StringBuilder &to_string_builder(StringBuilder &string_builder) const = 0;