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> {
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 {
let statuses = await loadStatuses(for: .hashtag(tag: hashgtag, accountId: nil),
account: account,
let statuses = await loadStatuses(for: .hashtag(tag: configuration.hashgtag, accountId: nil),
account: configuration.account,
widgetFamily: context.family)
let images = try await loadImages(urls: statuses.map{ $0.account.avatar } )
return Timeline(entries: [.init(date: Date(),
timeline: .hashtag(tag: hashgtag, accountId: nil),
timeline: .hashtag(tag: configuration.hashgtag,
accountId: nil),
statuses: statuses,
images: images)], policy: .atEnd)
} catch {

View File

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

View File

@ -27,21 +27,13 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider {
}
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 {
let statuses = await loadStatuses(for: timeline.timeline,
account: account,
widgetFamily: context.family)
let statuses = await loadStatuses(for: configuration.timeline.timeline,
account: configuration.account,
widgetFamily: context.family)
let images = try await loadImages(urls: statuses.map{ $0.account.avatar } )
return Timeline(entries: [.init(date: Date(),
timeline: timeline.timeline,
timeline: configuration.timeline.timeline,
statuses: statuses,
images: images)], policy: .atEnd)
} catch {

View File

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