From 54a75d4138490a75dcef02d90c79af85a52e7130 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Fri, 25 Nov 2022 14:43:36 +0100 Subject: [PATCH] feat: Delete Status and Notification Feeds for Blocked/Muted Users --- .../Service/API/APIService+Block.swift | 20 ++++++++++++++----- .../Service/API/APIService+Mute.swift | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift index 60f15367e..19c5ff437 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift @@ -54,7 +54,7 @@ extension APIService { let users = try managedObjectContext.fetch(fetchRequest) as! [MastodonUser] for user in users { - user.statuses.deleteAllFeedsForBlockOrMute(in: managedObjectContext) + user.deleteStatusAndNotificationFeeds(in: managedObjectContext) } } @@ -150,10 +150,20 @@ extension APIService { } -extension Set { - func deleteAllFeedsForBlockOrMute(in managedObjectContext: NSManagedObjectContext) { - map { $0.feeds.union($0.reblogFrom.map { $0.feeds }.flatMap { $0 }) } +extension MastodonUser { + func deleteStatusAndNotificationFeeds(in context: NSManagedObjectContext) { + statuses.map { + $0.feeds + .union($0.reblogFrom.map { $0.feeds }.flatMap { $0 }) + .union($0.notifications.map { $0.feeds }.flatMap { $0 }) + } .flatMap { $0 } - .forEach(managedObjectContext.delete) + .forEach(context.delete) + + notifications.map { + $0.feeds + } + .flatMap { $0 } + .forEach(context.delete) } } diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift index e0e95fd35..cc46872f4 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift @@ -53,7 +53,7 @@ extension APIService { let users = try managedObjectContext.fetch(fetchRequest) as! [MastodonUser] for user in users { - user.statuses.deleteAllFeedsForBlockOrMute(in: managedObjectContext) + user.deleteStatusAndNotificationFeeds(in: managedObjectContext) } }