From 32541e68e1ba632f82b87db847d2a14b52e62e81 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Tue, 1 Dec 2020 15:23:47 -0800 Subject: [PATCH] View muted and blocked users --- Localizations/Localizable.strings | 2 ++ .../MastodonAPI/Endpoints/AccountsEndpoint.swift | 13 +++++++++---- .../ServiceLayer/Services/IdentityService.swift | 7 +++++++ .../Sources/ViewModels/PreferencesViewModel.swift | 14 ++++++++++++++ Views/PreferencesView.swift | 6 ++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index d6e7ac9..95ade39 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -50,6 +50,7 @@ "pending.pending-confirmation" = "Your account is pending confirmation"; "preferences" = "Preferences"; "preferences.app" = "App Preferences"; +"preferences.blocked-users" = "Blocked Users"; "preferences.media" = "Media"; "preferences.media.use-system-reduce-motion" = "Use system reduce motion setting"; "preferences.media.avatars" = "Avatars"; @@ -83,6 +84,7 @@ "preferences.notification-types.reblog" = "Reblog"; "preferences.notification-types.mention" = "Mention"; "preferences.notification-types.poll" = "Poll"; +"preferences.muted-users" = "Muted Users"; "preferences.startup-and-syncing" = "Startup and Syncing"; "preferences.startup-and-syncing.home-timeline" = "Home timeline"; "preferences.startup-and-syncing.notifications-tab" = "Notifications tab"; diff --git a/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift b/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift index e6ac297..fde02be 100644 --- a/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift +++ b/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift @@ -7,6 +7,8 @@ import Mastodon public enum AccountsEndpoint { case rebloggedBy(id: Status.Id) case favouritedBy(id: Status.Id) + case mutes + case blocks } extension AccountsEndpoint: Endpoint { @@ -16,6 +18,8 @@ extension AccountsEndpoint: Endpoint { switch self { case .rebloggedBy, .favouritedBy: return defaultContext + ["statuses"] + case .mutes, .blocks: + return defaultContext } } @@ -25,13 +29,14 @@ extension AccountsEndpoint: Endpoint { return [id, "reblogged_by"] case let .favouritedBy(id): return [id, "favourited_by"] + case .mutes: + return ["mutes"] + case .blocks: + return ["blocks"] } } public var method: HTTPMethod { - switch self { - case .rebloggedBy, .favouritedBy: - return .get - } + .get } } diff --git a/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift b/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift index 732f38b..d5e160d 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/IdentityService.swift @@ -210,6 +210,13 @@ public extension IdentityService { TimelineService(timeline: timeline, mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase) } + func service(accountList: AccountsEndpoint) -> AccountListService { + AccountListService( + endpoint: accountList, + mastodonAPIClient: mastodonAPIClient, + contentDatabase: contentDatabase) + } + func notificationsService() -> NotificationsService { NotificationsService(mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase) } diff --git a/ViewModels/Sources/ViewModels/PreferencesViewModel.swift b/ViewModels/Sources/ViewModels/PreferencesViewModel.swift index 2180212..c75d0ca 100644 --- a/ViewModels/Sources/ViewModels/PreferencesViewModel.swift +++ b/ViewModels/Sources/ViewModels/PreferencesViewModel.swift @@ -16,3 +16,17 @@ public final class PreferencesViewModel: ObservableObject { shouldShowNotificationTypePreferences = identification.identity.lastRegisteredDeviceToken != nil } } + +public extension PreferencesViewModel { + func mutedUsersViewModel() -> CollectionViewModel { + CollectionItemsViewModel( + collectionService: identification.service.service(accountList: .mutes), + identification: identification) + } + + func blockedUsersViewModel() -> CollectionViewModel { + CollectionItemsViewModel( + collectionService: identification.service.service(accountList: .blocks), + identification: identification) + } +} diff --git a/Views/PreferencesView.swift b/Views/PreferencesView.swift index 31db4c0..80f453a 100644 --- a/Views/PreferencesView.swift +++ b/Views/PreferencesView.swift @@ -21,6 +21,12 @@ struct PreferencesView: View { destination: NotificationTypesPreferencesView( viewModel: .init(identification: identification))) } + NavigationLink("preferences.muted-users", + destination: TableView(viewModel: viewModel.mutedUsersViewModel()) + .navigationTitle(Text("preferences.muted-users"))) + NavigationLink("preferences.blocked-users", + destination: TableView(viewModel: viewModel.blockedUsersViewModel()) + .navigationTitle(Text("preferences.blocked-users"))) } Section(header: Text("preferences.app")) { NavigationLink("preferences.media",