Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed May 6, 2024
1 parent 189e10f commit a37316c
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 102 deletions.
11 changes: 5 additions & 6 deletions IceCubesAppIntents/AppAccountEntity.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import AppIntents
import AppAccount
import AppIntents
import Env
import Foundation
import Models
import Network


extension IntentDescription: @unchecked Sendable { }
extension TypeDisplayRepresentation: @unchecked Sendable { }
extension IntentDescription: @unchecked Sendable {}
extension TypeDisplayRepresentation: @unchecked Sendable {}

public struct AppAccountEntity: Identifiable, AppEntity {
public var id: String { account.id }
Expand All @@ -24,8 +23,8 @@ public struct AppAccountEntity: Identifiable, AppEntity {
}

public struct DefaultAppAccountEntityQuery: EntityQuery {
public init() { }
public init() {}

public func entities(for identifiers: [AppAccountEntity.ID]) async throws -> [AppAccountEntity] {
return await AppAccountsManager.shared.availableAccounts.filter { account in
identifiers.contains { id in
Expand Down
12 changes: 6 additions & 6 deletions IceCubesAppIntents/TimelineFilterEntity.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AppIntents
import AppAccount
import AppIntents
import Env
import Foundation
import Models
Expand All @@ -21,14 +21,14 @@ public struct TimelineFilterEntity: Identifiable, AppEntity {
}

public struct DefaultTimelineEntityQuery: EntityQuery {
public init() { }
public func entities(for identifiers: [TimelineFilter.ID]) async throws -> [TimelineFilterEntity] {
[.home, .trending, .federated, .local].map{ .init(timeline: $0) }
public init() {}

public func entities(for _: [TimelineFilter.ID]) async throws -> [TimelineFilterEntity] {
[.home, .trending, .federated, .local].map { .init(timeline: $0) }
}

public func suggestedEntities() async throws -> [TimelineFilterEntity] {
[.home, .trending, .federated, .local].map{ .init(timeline: $0) }
[.home, .trending, .federated, .local].map { .init(timeline: $0) }
}

public func defaultResult() async -> TimelineFilterEntity? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import WidgetKit
import SwiftUI
import Network
import DesignSystem
import Models
import Network
import SwiftUI
import Timeline
import WidgetKit

struct HashtagPostsWidgetProvider: AppIntentTimelineProvider {
func placeholder(in context: Context) -> PostsWidgetEntry {
func placeholder(in _: Context) -> PostsWidgetEntry {
.init(date: Date(),
title: "#Mastodon",
statuses: [.placeholder()],
images: [:])
}

func snapshot(for configuration: HashtagPostsWidgetConfiguration, in context: Context) async -> PostsWidgetEntry {
if let entry = await timeline(for: configuration, context: context).entries.first {
return entry
Expand All @@ -22,39 +22,40 @@ struct HashtagPostsWidgetProvider: AppIntentTimelineProvider {
statuses: [],
images: [:])
}

func timeline(for configuration: HashtagPostsWidgetConfiguration, in context: Context) async -> Timeline<PostsWidgetEntry> {
await timeline(for: configuration, context: context)
}

private func timeline(for configuration: HashtagPostsWidgetConfiguration, context: Context) async -> Timeline<PostsWidgetEntry> {
do {
let timeline: TimelineFilter = .hashtag(tag: configuration.hashgtag, accountId: nil)
let statuses = await loadStatuses(for: timeline,
account: configuration.account,
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(),
title: timeline.title,
statuses: statuses,
images: images)], policy: .atEnd)
title: timeline.title,
statuses: statuses,
images: images)], policy: .atEnd)
} catch {
return Timeline(entries: [.init(date: Date(),
title: "#Mastodon",
statuses: [],
images: [:])],
policy: .atEnd)
policy: .atEnd)
}
}
}

struct HashtagPostsWidget: Widget {
let kind: String = "HashtagPostsWidget"

var body: some WidgetConfiguration {
AppIntentConfiguration(kind: kind,
intent: HashtagPostsWidgetConfiguration.self,
provider: HashtagPostsWidgetProvider()) { entry in
provider: HashtagPostsWidgetProvider())
{ entry in
PostsWidgetView(entry: entry)
.containerBackground(Color("WidgetBackground").gradient, for: .widget)
}
Expand All @@ -64,12 +65,11 @@ struct HashtagPostsWidget: Widget {
}
}


#Preview(as: .systemMedium) {
HashtagPostsWidget()
} timeline: {
PostsWidgetEntry(date: .now,
title: "#Mastodon",
statuses: [.placeholder(), .placeholder(), .placeholder(), .placeholder()],
images: [:])
title: "#Mastodon",
statuses: [.placeholder(), .placeholder(), .placeholder(), .placeholder()],
images: [:])
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import WidgetKit
import AppIntents
import WidgetKit

struct HashtagPostsWidgetConfiguration: WidgetConfigurationIntent {
static let title: LocalizedStringResource = "Configuration"
static let description = IntentDescription("Choose the account and hashtag for this widget")

@Parameter(title: "Account")
var account: AppAccountEntity

@Parameter(title: "Hashtag")
var hashgtag: String
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import WidgetKit
import SwiftUI
import WidgetKit

@main
struct IceCubesAppWidgetsExtensionBundle: WidgetBundle {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import WidgetKit
import SwiftUI
import Network
import DesignSystem
import Models
import Network
import SwiftUI
import Timeline
import WidgetKit

struct LatestPostsWidgetProvider: AppIntentTimelineProvider {
func placeholder(in context: Context) -> PostsWidgetEntry {
func placeholder(in _: Context) -> PostsWidgetEntry {
.init(date: Date(),
title: "Home",
statuses: [.placeholder()],
images: [:])
}

func snapshot(for configuration: LatestPostsWidgetConfiguration, in context: Context) async -> PostsWidgetEntry {
if let entry = await timeline(for: configuration, context: context).entries.first {
return entry
Expand All @@ -22,30 +22,30 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider {
statuses: [],
images: [:])
}

func timeline(for configuration: LatestPostsWidgetConfiguration, in context: Context) async -> Timeline<PostsWidgetEntry> {
await timeline(for: configuration, context: context)
}

private func timeline(for configuration: LatestPostsWidgetConfiguration, context: Context) async -> Timeline<PostsWidgetEntry> {
do {
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 } )
let images = try await loadImages(urls: statuses.map { $0.account.avatar })
return Timeline(entries: [.init(date: Date(),
title: configuration.timeline.timeline.title,
statuses: statuses,
images: images)], policy: .atEnd)
statuses: statuses,
images: images)], policy: .atEnd)
} catch {
return Timeline(entries: [.init(date: Date(),
title: configuration.timeline.timeline.title,
statuses: [],
images: [:])],
policy: .atEnd)
policy: .atEnd)
}
}

private func loadImages(urls: [URL]) async throws -> [URL: UIImage] {
try await withThrowingTaskGroup(of: (URL, UIImage?).self) { group in
for url in urls {
Expand All @@ -54,25 +54,26 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider {
return (url, UIImage(data: response.0))
}
}

var images: [URL: UIImage] = [:]

for try await (url, image) in group {
images[url] = image
}

return images
}
}
}

struct LatestPostsWidget: Widget {
let kind: String = "LatestPostsWidget"

var body: some WidgetConfiguration {
AppIntentConfiguration(kind: kind,
intent: LatestPostsWidgetConfiguration.self,
provider: LatestPostsWidgetProvider()) { entry in
provider: LatestPostsWidgetProvider())
{ entry in
PostsWidgetView(entry: entry)
.containerBackground(Color("WidgetBackground").gradient, for: .widget)
}
Expand All @@ -82,11 +83,10 @@ struct LatestPostsWidget: Widget {
}
}


#Preview(as: .systemMedium) {
LatestPostsWidget()
} timeline: {
PostsWidgetEntry(date: .now,
PostsWidgetEntry(date: .now,
title: "Mastodon",
statuses: [.placeholder(), .placeholder(), .placeholder(), .placeholder()],
images: [:])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import WidgetKit
import AppIntents
import WidgetKit

struct LatestPostsWidgetConfiguration: WidgetConfigurationIntent {
static let title: LocalizedStringResource = "Configuration"
static let description = IntentDescription("Choose the account and timeline for this widget")

@Parameter(title: "Account")
var account: AppAccountEntity

@Parameter(title: "Timeline")
var timeline: TimelineFilterEntity
}
Expand Down
42 changes: 21 additions & 21 deletions IceCubesAppWidgetsExtension/MentionWidget/MentionWidget.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import WidgetKit
import SwiftUI
import Network
import DesignSystem
import Models
import Network
import SwiftUI
import Timeline
import WidgetKit

struct MentionsWidgetProvider: AppIntentTimelineProvider {
func placeholder(in context: Context) -> PostsWidgetEntry {
func placeholder(in _: Context) -> PostsWidgetEntry {
.init(date: Date(),
title: "Mentions",
statuses: [.placeholder()],
images: [:])
}

func snapshot(for configuration: MentionsWidgetConfiguration, in context: Context) async -> PostsWidgetEntry {
if let entry = await timeline(for: configuration, context: context).entries.first {
return entry
Expand All @@ -22,45 +22,46 @@ struct MentionsWidgetProvider: AppIntentTimelineProvider {
statuses: [],
images: [:])
}

func timeline(for configuration: MentionsWidgetConfiguration, in context: Context) async -> Timeline<PostsWidgetEntry> {
await timeline(for: configuration, context: context)
}
private func timeline(for configuration: MentionsWidgetConfiguration, context: Context) async -> Timeline<PostsWidgetEntry> {

private func timeline(for configuration: MentionsWidgetConfiguration, context _: Context) async -> Timeline<PostsWidgetEntry> {
do {
let client = Client(server: configuration.account.account.server,
oauthToken: configuration.account.account.oauthToken)
var excludedTypes = Models.Notification.NotificationType.allCases
excludedTypes.removeAll(where: { $0 == .mention })
var notifications: [Models.Notification] =
try await client.get(endpoint: Notifications.notifications(minId: nil,
maxId: nil,
types: excludedTypes.map(\.rawValue),
limit: 5))
let statuses = notifications.compactMap{ $0.status }
let images = try await loadImages(urls: statuses.map{ $0.account.avatar } )
try await client.get(endpoint: Notifications.notifications(minId: nil,
maxId: nil,
types: excludedTypes.map(\.rawValue),
limit: 5))
let statuses = notifications.compactMap { $0.status }
let images = try await loadImages(urls: statuses.map { $0.account.avatar })
return Timeline(entries: [.init(date: Date(),
title: "Mentions",
statuses: statuses,
images: images)], policy: .atEnd)
title: "Mentions",
statuses: statuses,
images: images)], policy: .atEnd)
} catch {
return Timeline(entries: [.init(date: Date(),
title: "Mentions",
statuses: [],
images: [:])],
policy: .atEnd)
policy: .atEnd)
}
}
}

struct MentionsWidget: Widget {
let kind: String = "MentionsWidget"

var body: some WidgetConfiguration {
AppIntentConfiguration(kind: kind,
intent: MentionsWidgetConfiguration.self,
provider: MentionsWidgetProvider()) { entry in
provider: MentionsWidgetProvider())
{ entry in
PostsWidgetView(entry: entry)
.containerBackground(Color("WidgetBackground").gradient, for: .widget)
}
Expand All @@ -70,7 +71,6 @@ struct MentionsWidget: Widget {
}
}


#Preview(as: .systemMedium) {
MentionsWidget()
} timeline: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import WidgetKit
import AppIntents
import WidgetKit

struct MentionsWidgetConfiguration: WidgetConfigurationIntent {
static let title: LocalizedStringResource = "Configuration"
static let description = IntentDescription("Choose the account for this widget")

@Parameter(title: "Account")
var account: AppAccountEntity
}
Expand Down
Loading

0 comments on commit a37316c

Please sign in to comment.