Swiftformat

This commit is contained in:
Thomas Ricouard 2023-02-26 06:45:57 +01:00
parent 06629cc397
commit 83e4e74329
22 changed files with 171 additions and 169 deletions

View file

@ -5,9 +5,9 @@ import Env
import Foundation import Foundation
import Models import Models
import Network import Network
import Nuke
import SwiftUI import SwiftUI
import Timeline import Timeline
import Nuke
struct SettingsTabs: View { struct SettingsTabs: View {
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss

View file

@ -61,10 +61,10 @@ public struct AccountsListRow: View {
let relationShip = viewModel.relationShip let relationShip = viewModel.relationShip
{ {
VStack(alignment: .center) { VStack(alignment: .center) {
FollowButton(viewModel: .init(accountId: viewModel.account.id, FollowButton(viewModel: .init(accountId: viewModel.account.id,
relationship: relationShip, relationship: relationShip,
shouldDisplayNotify: false, shouldDisplayNotify: false,
relationshipUpdated: { _ in })) relationshipUpdated: { _ in }))
} }
} }
} }

View file

@ -4,7 +4,6 @@ import SwiftUI
@MainActor @MainActor
class EditAccountViewModel: ObservableObject { class EditAccountViewModel: ObservableObject {
class FieldEditViewModel: ObservableObject, Identifiable { class FieldEditViewModel: ObservableObject, Identifiable {
let id = UUID().uuidString let id = UUID().uuidString
@Published var name: String = "" @Published var name: String = ""
@ -44,7 +43,7 @@ class EditAccountViewModel: ObservableObject {
isBot = account.bot isBot = account.bot
isLocked = account.locked isLocked = account.locked
isDiscoverable = account.discoverable ?? false isDiscoverable = account.discoverable ?? false
fields = account.source?.fields.map{ .init(name: $0.name, value: $0.value.asRawText) } ?? [] fields = account.source?.fields.map { .init(name: $0.name, value: $0.value.asRawText) } ?? []
withAnimation { withAnimation {
isLoading = false isLoading = false
} }
@ -60,7 +59,7 @@ class EditAccountViewModel: ObservableObject {
bot: isBot, bot: isBot,
locked: isLocked, locked: isLocked,
discoverable: isDiscoverable, discoverable: isDiscoverable,
fieldsAttributes: fields.map{ .init(name: $0.name, value: $0.value)}) fieldsAttributes: fields.map { .init(name: $0.name, value: $0.value) })
let response = try await client?.patch(endpoint: Accounts.updateCredentials(json: data)) let response = try await client?.patch(endpoint: Accounts.updateCredentials(json: data))
if response?.statusCode != 200 { if response?.statusCode != 200 {
saveError = true saveError = true

View file

@ -16,10 +16,10 @@ public struct AppAccountsSelectorView: View {
var showNotificationBadge: Bool { var showNotificationBadge: Bool {
accountsViewModel accountsViewModel
.filter { $0.account?.id != currentAccount.account?.id } .filter { $0.account?.id != currentAccount.account?.id }
.compactMap{ $0.appAccount.oauthToken } .compactMap { $0.appAccount.oauthToken }
.map{ preferences.getNotificationsCount(for: $0) } .map { preferences.getNotificationsCount(for: $0) }
.reduce(0, +) > 0 .reduce(0, +) > 0
} }
public init(routerPath: RouterPath, public init(routerPath: RouterPath,

View file

@ -117,22 +117,22 @@ struct ConversationMessageView: View {
Label(isLiked ? "status.action.unfavorite" : "status.action.favorite", Label(isLiked ? "status.action.unfavorite" : "status.action.favorite",
systemImage: isLiked ? "star.fill" : "star") systemImage: isLiked ? "star.fill" : "star")
} }
Button { Task { Button { Task {
do { do {
let status: Status let status: Status
if isBookmarked { if isBookmarked {
status = try await client.post(endpoint: Statuses.unbookmark(id: message.id)) status = try await client.post(endpoint: Statuses.unbookmark(id: message.id))
} else { } else {
status = try await client.post(endpoint: Statuses.bookmark(id: message.id)) status = try await client.post(endpoint: Statuses.bookmark(id: message.id))
}
withAnimation {
isBookmarked = status.bookmarked == true
}
} catch {}
} } label: {
Label(isBookmarked ? "status.action.unbookmark" : "status.action.bookmark",
systemImage: isBookmarked ? "bookmark.fill" : "bookmark")
} }
withAnimation {
isBookmarked = status.bookmarked == true
}
} catch {}
} } label: {
Label(isBookmarked ? "status.action.unbookmark" : "status.action.bookmark",
systemImage: isBookmarked ? "bookmark.fill" : "bookmark")
}
Divider() Divider()
if message.account.id == currentAccount.account?.id { if message.account.id == currentAccount.account?.id {
Button("status.action.delete", role: .destructive) { Button("status.action.delete", role: .destructive) {
@ -141,13 +141,13 @@ struct ConversationMessageView: View {
} }
} }
} else { } else {
Section(message.reblog?.account.acct ?? message.account.acct) { Section(message.reblog?.account.acct ?? message.account.acct) {
Button { Button {
routerPath.presentedSheet = .mentionStatusEditor(account: message.reblog?.account ?? message.account, visibility: .pub) routerPath.presentedSheet = .mentionStatusEditor(account: message.reblog?.account ?? message.account, visibility: .pub)
} label: { } label: {
Label("status.action.mention", systemImage: "at") Label("status.action.mention", systemImage: "at")
}
} }
}
Section { Section {
Button(role: .destructive) { Button(role: .destructive) {
routerPath.presentedSheet = .report(status: message.reblogAsAsStatus ?? message) routerPath.presentedSheet = .report(status: message.reblogAsAsStatus ?? message)

View file

@ -92,33 +92,33 @@ struct ConversationsListRow: View {
Label("conversations.action.mark-read", systemImage: "eye") Label("conversations.action.mark-read", systemImage: "eye")
} }
if let message = conversation.lastStatus { if let message = conversation.lastStatus {
Section("conversations.latest.message") { Section("conversations.latest.message") {
Button { Button {
UIPasteboard.general.string = message.content.asRawText UIPasteboard.general.string = message.content.asRawText
} label: { } label: {
Label("status.action.copy-text", systemImage: "doc.on.doc") Label("status.action.copy-text", systemImage: "doc.on.doc")
} }
likeAndBookmark likeAndBookmark
}
Divider()
if message.account.id != currentAccount.account?.id {
Section(message.reblog?.account.acct ?? message.account.acct) {
Button {
routerPath.presentedSheet = .mentionStatusEditor(account: message.reblog?.account ?? message.account, visibility: .pub)
} label: {
Label("status.action.mention", systemImage: "at")
}
}
Section {
Button(role: .destructive) {
routerPath.presentedSheet = .report(status: message.reblogAsAsStatus ?? message)
} label: {
Label("status.action.report", systemImage: "exclamationmark.bubble")
}
}
}
} }
Divider()
if message.account.id != currentAccount.account?.id {
Section(message.reblog?.account.acct ?? message.account.acct) {
Button {
routerPath.presentedSheet = .mentionStatusEditor(account: message.reblog?.account ?? message.account, visibility: .pub)
} label: {
Label("status.action.mention", systemImage: "at")
}
}
Section {
Button(role: .destructive) {
routerPath.presentedSheet = .report(status: message.reblogAsAsStatus ?? message)
} label: {
Label("status.action.report", systemImage: "exclamationmark.bubble")
}
}
}
}
Button(role: .destructive) { Button(role: .destructive) {
Task { Task {
@ -132,20 +132,20 @@ struct ConversationsListRow: View {
@ViewBuilder @ViewBuilder
private var likeAndBookmark: some View { private var likeAndBookmark: some View {
Button { Button {
Task { Task {
await viewModel.favorite(conversation: conversation) await viewModel.favorite(conversation: conversation)
} }
} label: { } label: {
Label(conversation.lastStatus?.favourited ?? false ? "status.action.unfavorite" : "status.action.favorite", Label(conversation.lastStatus?.favourited ?? false ? "status.action.unfavorite" : "status.action.favorite",
systemImage: conversation.lastStatus?.favourited ?? false ? "star.fill" : "star") systemImage: conversation.lastStatus?.favourited ?? false ? "star.fill" : "star")
} }
Button { Button {
Task { Task {
await viewModel.bookmark(conversation: conversation) await viewModel.bookmark(conversation: conversation)
} }
} label: { } label: {
Label(conversation.lastStatus?.bookmarked ?? false ? "status.action.unbookmark" : "status.action.bookmark", Label(conversation.lastStatus?.bookmarked ?? false ? "status.action.unbookmark" : "status.action.bookmark",
systemImage: conversation.lastStatus?.bookmarked ?? false ? "bookmark.fill" : "bookmark") systemImage: conversation.lastStatus?.bookmarked ?? false ? "bookmark.fill" : "bookmark")
} }
} }
} }

View file

@ -16,30 +16,30 @@ public struct ConversationsListView: View {
public init() {} public init() {}
private var conversations: Binding<[Conversation]> { private var conversations: Binding<[Conversation]> {
if viewModel.isLoadingFirstPage { if viewModel.isLoadingFirstPage {
return Binding.constant(Conversation.placeholders()) return Binding.constant(Conversation.placeholders())
} else { } else {
return $viewModel.conversations return $viewModel.conversations
}
} }
}
public var body: some View { public var body: some View {
ScrollView { ScrollView {
LazyVStack { LazyVStack {
Group { Group {
if !conversations.isEmpty || viewModel.isLoadingFirstPage { if !conversations.isEmpty || viewModel.isLoadingFirstPage {
ForEach(conversations) { $conversation in ForEach(conversations) { $conversation in
if viewModel.isLoadingFirstPage { if viewModel.isLoadingFirstPage {
ConversationsListRow(conversation: $conversation, viewModel: viewModel) ConversationsListRow(conversation: $conversation, viewModel: viewModel)
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
.redacted(reason: .placeholder) .redacted(reason: .placeholder)
} else { } else {
ConversationsListRow(conversation: $conversation, viewModel: viewModel) ConversationsListRow(conversation: $conversation, viewModel: viewModel)
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
} }
Divider() Divider()
} }
} else if conversations.isEmpty && !viewModel.isLoadingFirstPage && !viewModel.isError { } else if conversations.isEmpty && !viewModel.isLoadingFirstPage && !viewModel.isError {
EmptyView(iconName: "tray", EmptyView(iconName: "tray",
title: "conversations.empty.title", title: "conversations.empty.title",

View file

@ -86,22 +86,22 @@ class ConversationsListViewModel: ObservableObject {
} catch {} } catch {}
} }
private func updateConversationWithNewLastStatus(conversation: Conversation, newLastStatus: Status) { private func updateConversationWithNewLastStatus(conversation: Conversation, newLastStatus: Status) {
let newConversation = Conversation(id: conversation.id, unread: conversation.unread, lastStatus: newLastStatus, accounts: conversation.accounts) let newConversation = Conversation(id: conversation.id, unread: conversation.unread, lastStatus: newLastStatus, accounts: conversation.accounts)
updateConversations(conversation: newConversation) updateConversations(conversation: newConversation)
} }
private func updateConversations(conversation: Conversation) { private func updateConversations(conversation: Conversation) {
if let index = conversations.firstIndex(where: { $0.id == conversation.id }) { if let index = conversations.firstIndex(where: { $0.id == conversation.id }) {
conversations.remove(at: index) conversations.remove(at: index)
}
conversations.insert(conversation, at: 0)
conversations = conversations.sorted(by: { ($0.lastStatus?.createdAt.asDate ?? Date.now) > ($1.lastStatus?.createdAt.asDate ?? Date.now) })
} }
conversations.insert(conversation, at: 0)
conversations = conversations.sorted(by: { ($0.lastStatus?.createdAt.asDate ?? Date.now) > ($1.lastStatus?.createdAt.asDate ?? Date.now) })
}
func handleEvent(event: any StreamEvent) { func handleEvent(event: any StreamEvent) {
if let event = event as? StreamEventConversation { if let event = event as? StreamEventConversation {
updateConversations(conversation: event.conversation) updateConversations(conversation: event.conversation)
} }
} }
} }

View file

@ -10,6 +10,7 @@ public class QuickLook: ObservableObject {
} }
} }
} }
@Published public private(set) var urls: [URL] = [] @Published public private(set) var urls: [URL] = []
@Published public private(set) var isPreparing: Bool = false @Published public private(set) var isPreparing: Bool = false
@Published public private(set) var latestError: Error? @Published public private(set) var latestError: Error?
@ -73,7 +74,7 @@ public class QuickLook: ObservableObject {
return path return path
} }
private func cleanup(urls: [URL]) { private func cleanup(urls _: [URL]) {
try? FileManager.default.removeItem(at: quickLookDir) try? FileManager.default.removeItem(at: quickLookDir)
} }
} }

View file

@ -6,12 +6,12 @@ public struct Conversation: Identifiable, Decodable, Hashable, Equatable {
public let lastStatus: Status? public let lastStatus: Status?
public let accounts: [Account] public let accounts: [Account]
public init(id: String, unread: Bool, lastStatus: Status? = nil, accounts: [Account]) { public init(id: String, unread: Bool, lastStatus: Status? = nil, accounts: [Account]) {
self.id = id self.id = id
self.unread = unread self.unread = unread
self.lastStatus = lastStatus self.lastStatus = lastStatus
self.accounts = accounts self.accounts = accounts
} }
public static func placeholder() -> Conversation { public static func placeholder() -> Conversation {
.init(id: UUID().uuidString, unread: false, lastStatus: .placeholder(), accounts: [.placeholder()]) .init(id: UUID().uuidString, unread: false, lastStatus: .placeholder(), accounts: [.placeholder()])

View file

@ -190,7 +190,8 @@ public struct UpdateCredentialsData: Encodable, Sendable {
bot: Bool, bot: Bool,
locked: Bool, locked: Bool,
discoverable: Bool, discoverable: Bool,
fieldsAttributes: [FieldData]) { fieldsAttributes: [FieldData])
{
self.displayName = displayName self.displayName = displayName
self.note = note self.note = note
self.source = source self.source = source
@ -204,5 +205,4 @@ public struct UpdateCredentialsData: Encodable, Sendable {
} }
self.fieldsAttributes = fieldAttributes self.fieldsAttributes = fieldAttributes
} }
} }

View file

@ -197,7 +197,6 @@ public extension URL {
} }
} }
extension UIImage { extension UIImage {
func resized(to size: CGSize) -> UIImage { func resized(to size: CGSize) -> UIImage {
UIGraphicsImageRenderer(size: size).image { _ in UIGraphicsImageRenderer(size: size).image { _ in

View file

@ -1,6 +1,6 @@
import Foundation import Foundation
import SwiftUI
import Models import Models
import SwiftUI
@MainActor @MainActor
class StatusEmbedCache { class StatusEmbedCache {
@ -8,7 +8,7 @@ class StatusEmbedCache {
private var cache: [URL: Status] = [:] private var cache: [URL: Status] = [:]
private init() { } private init() {}
func set(url: URL, status: Status) { func set(url: URL, status: Status) {
cache[url] = status cache[url] = status

View file

@ -45,7 +45,7 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
routerPath: routerPath, routerPath: routerPath,
isRemote: isRemote) isRemote: isRemote)
}) })
.id(status.id) .id(status.id)
.onAppear { .onAppear {
fetcher.statusDidAppear(status: status) fetcher.statusDidAppear(status: status)

View file

@ -47,7 +47,7 @@ public class StatusRowViewModel: ObservableObject {
var isThread: Bool { var isThread: Bool {
status.reblog?.inReplyToId != nil || status.reblog?.inReplyToAccountId != nil || status.reblog?.inReplyToId != nil || status.reblog?.inReplyToAccountId != nil ||
status.inReplyToId != nil || status.inReplyToAccountId != nil status.inReplyToId != nil || status.inReplyToAccountId != nil
} }
var highlightRowColor: Color { var highlightRowColor: Color {
@ -99,7 +99,8 @@ public class StatusRowViewModel: ObservableObject {
isFiltered = filter != nil isFiltered = filter != nil
if let url = embededStatusURL(), if let url = embededStatusURL(),
let embed = StatusEmbedCache.shared.get(url: url) { let embed = StatusEmbedCache.shared.get(url: url)
{
isEmbedLoading = false isEmbedLoading = false
embeddedStatus = embed embeddedStatus = embed
} }
@ -159,7 +160,8 @@ public class StatusRowViewModel: ObservableObject {
let content = status.reblog?.content ?? status.content let content = status.reblog?.content ?? status.content
if !content.statusesURLs.isEmpty, if !content.statusesURLs.isEmpty,
let url = content.statusesURLs.first, let url = content.statusesURLs.first,
client.hasConnection(with: url) { client.hasConnection(with: url)
{
return url return url
} }
return nil return nil
@ -167,7 +169,8 @@ public class StatusRowViewModel: ObservableObject {
func loadEmbeddedStatus() async { func loadEmbeddedStatus() async {
guard embeddedStatus == nil, guard embeddedStatus == nil,
let url = embededStatusURL() else { let url = embededStatusURL()
else {
if isEmbedLoading { if isEmbedLoading {
isEmbedLoading = false isEmbedLoading = false
} }

View file

@ -85,8 +85,8 @@ struct StatusRowHeaderView: View {
private var dateView: Text { private var dateView: Text {
Text(status.createdAt.relativeFormatted) + Text(status.createdAt.relativeFormatted) +
Text("") + Text("") +
Text(Image(systemName: viewModel.status.visibility.iconName)) Text(Image(systemName: viewModel.status.visibility.iconName))
} }
@ViewBuilder @ViewBuilder