Widget: Remove optional parameters

This commit is contained in:
Thomas Ricouard 2024-05-05 19:41:04 +02:00
parent a6fd8d1137
commit 7328c00006
4 changed files with 12 additions and 26 deletions

View file

@ -28,20 +28,14 @@ struct HashtagPostsWidgetProvider: AppIntentTimelineProvider {
} }
private func timeline(for configuration: HashtagPostsWidgetConfiguration, context: Context) async -> Timeline<PostsWidgetEntry> { private func timeline(for configuration: HashtagPostsWidgetConfiguration, context: Context) async -> Timeline<PostsWidgetEntry> {
guard let account = configuration.account, let hashgtag = configuration.hashgtag else {
return Timeline(entries: [.init(date: Date(),
timeline: .hashtag(tag: "Mastodon", accountId: nil),
statuses: [],
images: [:])],
policy: .atEnd)
}
do { do {
let statuses = await loadStatuses(for: .hashtag(tag: hashgtag, accountId: nil), let statuses = await loadStatuses(for: .hashtag(tag: configuration.hashgtag, accountId: nil),
account: account, account: configuration.account,
widgetFamily: context.family) widgetFamily: context.family)
let images = try await loadImages(urls: statuses.map{ $0.account.avatar } ) let images = try await loadImages(urls: statuses.map{ $0.account.avatar } )
return Timeline(entries: [.init(date: Date(), return Timeline(entries: [.init(date: Date(),
timeline: .hashtag(tag: hashgtag, accountId: nil), timeline: .hashtag(tag: configuration.hashgtag,
accountId: nil),
statuses: statuses, statuses: statuses,
images: images)], policy: .atEnd) images: images)], policy: .atEnd)
} catch { } catch {

View file

@ -6,10 +6,10 @@ struct HashtagPostsWidgetConfiguration: WidgetConfigurationIntent {
static let description = IntentDescription("Choose the account and hashtag for this widget") static let description = IntentDescription("Choose the account and hashtag for this widget")
@Parameter(title: "Account") @Parameter(title: "Account")
var account: AppAccountEntity? var account: AppAccountEntity
@Parameter(title: "Hashtag") @Parameter(title: "Hashtag")
var hashgtag: String? var hashgtag: String
} }
extension HashtagPostsWidgetConfiguration { extension HashtagPostsWidgetConfiguration {

View file

@ -27,21 +27,13 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider {
} }
private func timeline(for configuration: LatestPostsWidgetConfiguration, context: Context) async -> Timeline<PostsWidgetEntry> { private func timeline(for configuration: LatestPostsWidgetConfiguration, context: Context) async -> Timeline<PostsWidgetEntry> {
guard let account = configuration.account, let timeline = configuration.timeline else {
return Timeline(entries: [.init(date: Date(),
timeline: .home,
statuses: [],
images: [:])],
policy: .atEnd)
}
do { do {
let statuses = await loadStatuses(for: timeline.timeline, let statuses = await loadStatuses(for: configuration.timeline.timeline,
account: account, account: configuration.account,
widgetFamily: context.family) widgetFamily: context.family)
let images = try await loadImages(urls: statuses.map{ $0.account.avatar } ) let images = try await loadImages(urls: statuses.map{ $0.account.avatar } )
return Timeline(entries: [.init(date: Date(), return Timeline(entries: [.init(date: Date(),
timeline: timeline.timeline, timeline: configuration.timeline.timeline,
statuses: statuses, statuses: statuses,
images: images)], policy: .atEnd) images: images)], policy: .atEnd)
} catch { } catch {

View file

@ -6,10 +6,10 @@ struct LatestPostsWidgetConfiguration: WidgetConfigurationIntent {
static let description = IntentDescription("Choose the account and timeline for this widget") static let description = IntentDescription("Choose the account and timeline for this widget")
@Parameter(title: "Account") @Parameter(title: "Account")
var account: AppAccountEntity? var account: AppAccountEntity
@Parameter(title: "Timeline") @Parameter(title: "Timeline")
var timeline: TimelineFilterEntity? var timeline: TimelineFilterEntity
} }
extension LatestPostsWidgetConfiguration { extension LatestPostsWidgetConfiguration {