From 4e591bcd1cd1ecb8f0a6cce96cc9439cfb8fdbd9 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Thu, 26 Jan 2023 15:15:59 +0100 Subject: [PATCH] feat(Widget): Default to currently active user's account in Widget --- WidgetExtension/FollowersWidgetExtension.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/WidgetExtension/FollowersWidgetExtension.swift b/WidgetExtension/FollowersWidgetExtension.swift index 7c3bb526d..2f01e74ea 100644 --- a/WidgetExtension/FollowersWidgetExtension.swift +++ b/WidgetExtension/FollowersWidgetExtension.swift @@ -124,14 +124,23 @@ private extension FollowersProvider { let authBox = WidgetExtension.appContext .authenticationService .mastodonAuthenticationBoxes - .first, - let account = configuration.account + .first else { return completion(.unconfigured) } + + guard let desiredAccount: String = { + guard let account = configuration.account else { + return authBox.authenticationRecord.object(in: WidgetExtension.appContext.managedObjectContext)?.user.acct + } + return account + }() else { + return completion(.unconfigured) + } + let resultingAccount = try await WidgetExtension.appContext .apiService - .search(query: .init(q: account, type: .accounts), authenticationBox: authBox) + .search(query: .init(q: desiredAccount, type: .accounts), authenticationBox: authBox) .value .accounts .first!