mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-23 06:18:08 +00:00
Swiftformat
This commit is contained in:
parent
06629cc397
commit
83e4e74329
22 changed files with 171 additions and 169 deletions
|
@ -5,9 +5,9 @@ import Env
|
|||
import Foundation
|
||||
import Models
|
||||
import Network
|
||||
import Nuke
|
||||
import SwiftUI
|
||||
import Timeline
|
||||
import Nuke
|
||||
|
||||
struct SettingsTabs: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
|
|
@ -61,10 +61,10 @@ public struct AccountsListRow: View {
|
|||
let relationShip = viewModel.relationShip
|
||||
{
|
||||
VStack(alignment: .center) {
|
||||
FollowButton(viewModel: .init(accountId: viewModel.account.id,
|
||||
relationship: relationShip,
|
||||
shouldDisplayNotify: false,
|
||||
relationshipUpdated: { _ in }))
|
||||
FollowButton(viewModel: .init(accountId: viewModel.account.id,
|
||||
relationship: relationShip,
|
||||
shouldDisplayNotify: false,
|
||||
relationshipUpdated: { _ in }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import SwiftUI
|
|||
|
||||
@MainActor
|
||||
class EditAccountViewModel: ObservableObject {
|
||||
|
||||
class FieldEditViewModel: ObservableObject, Identifiable {
|
||||
let id = UUID().uuidString
|
||||
@Published var name: String = ""
|
||||
|
@ -44,7 +43,7 @@ class EditAccountViewModel: ObservableObject {
|
|||
isBot = account.bot
|
||||
isLocked = account.locked
|
||||
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 {
|
||||
isLoading = false
|
||||
}
|
||||
|
@ -60,7 +59,7 @@ class EditAccountViewModel: ObservableObject {
|
|||
bot: isBot,
|
||||
locked: isLocked,
|
||||
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))
|
||||
if response?.statusCode != 200 {
|
||||
saveError = true
|
||||
|
|
|
@ -16,10 +16,10 @@ public struct AppAccountsSelectorView: View {
|
|||
|
||||
var showNotificationBadge: Bool {
|
||||
accountsViewModel
|
||||
.filter { $0.account?.id != currentAccount.account?.id }
|
||||
.compactMap{ $0.appAccount.oauthToken }
|
||||
.map{ preferences.getNotificationsCount(for: $0) }
|
||||
.reduce(0, +) > 0
|
||||
.filter { $0.account?.id != currentAccount.account?.id }
|
||||
.compactMap { $0.appAccount.oauthToken }
|
||||
.map { preferences.getNotificationsCount(for: $0) }
|
||||
.reduce(0, +) > 0
|
||||
}
|
||||
|
||||
public init(routerPath: RouterPath,
|
||||
|
|
|
@ -117,22 +117,22 @@ struct ConversationMessageView: View {
|
|||
Label(isLiked ? "status.action.unfavorite" : "status.action.favorite",
|
||||
systemImage: isLiked ? "star.fill" : "star")
|
||||
}
|
||||
Button { Task {
|
||||
do {
|
||||
let status: Status
|
||||
if isBookmarked {
|
||||
status = try await client.post(endpoint: Statuses.unbookmark(id: message.id))
|
||||
} else {
|
||||
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")
|
||||
Button { Task {
|
||||
do {
|
||||
let status: Status
|
||||
if isBookmarked {
|
||||
status = try await client.post(endpoint: Statuses.unbookmark(id: message.id))
|
||||
} else {
|
||||
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")
|
||||
}
|
||||
Divider()
|
||||
if message.account.id == currentAccount.account?.id {
|
||||
Button("status.action.delete", role: .destructive) {
|
||||
|
@ -141,13 +141,13 @@ struct ConversationMessageView: View {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
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(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)
|
||||
|
|
|
@ -92,33 +92,33 @@ struct ConversationsListRow: View {
|
|||
Label("conversations.action.mark-read", systemImage: "eye")
|
||||
}
|
||||
|
||||
if let message = conversation.lastStatus {
|
||||
Section("conversations.latest.message") {
|
||||
Button {
|
||||
UIPasteboard.general.string = message.content.asRawText
|
||||
} label: {
|
||||
Label("status.action.copy-text", systemImage: "doc.on.doc")
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
if let message = conversation.lastStatus {
|
||||
Section("conversations.latest.message") {
|
||||
Button {
|
||||
UIPasteboard.general.string = message.content.asRawText
|
||||
} label: {
|
||||
Label("status.action.copy-text", systemImage: "doc.on.doc")
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button(role: .destructive) {
|
||||
Task {
|
||||
|
@ -132,20 +132,20 @@ struct ConversationsListRow: View {
|
|||
@ViewBuilder
|
||||
private var likeAndBookmark: some View {
|
||||
Button {
|
||||
Task {
|
||||
await viewModel.favorite(conversation: conversation)
|
||||
}
|
||||
Task {
|
||||
await viewModel.favorite(conversation: conversation)
|
||||
}
|
||||
} label: {
|
||||
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 {
|
||||
Task {
|
||||
await viewModel.bookmark(conversation: conversation)
|
||||
}
|
||||
Task {
|
||||
await viewModel.bookmark(conversation: conversation)
|
||||
}
|
||||
} label: {
|
||||
Label(conversation.lastStatus?.bookmarked ?? false ? "status.action.unbookmark" : "status.action.bookmark",
|
||||
systemImage: conversation.lastStatus?.bookmarked ?? false ? "bookmark.fill" : "bookmark")
|
||||
Label(conversation.lastStatus?.bookmarked ?? false ? "status.action.unbookmark" : "status.action.bookmark",
|
||||
systemImage: conversation.lastStatus?.bookmarked ?? false ? "bookmark.fill" : "bookmark")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,30 +16,30 @@ public struct ConversationsListView: View {
|
|||
|
||||
public init() {}
|
||||
|
||||
private var conversations: Binding<[Conversation]> {
|
||||
if viewModel.isLoadingFirstPage {
|
||||
return Binding.constant(Conversation.placeholders())
|
||||
} else {
|
||||
return $viewModel.conversations
|
||||
}
|
||||
private var conversations: Binding<[Conversation]> {
|
||||
if viewModel.isLoadingFirstPage {
|
||||
return Binding.constant(Conversation.placeholders())
|
||||
} else {
|
||||
return $viewModel.conversations
|
||||
}
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
ScrollView {
|
||||
LazyVStack {
|
||||
Group {
|
||||
if !conversations.isEmpty || viewModel.isLoadingFirstPage {
|
||||
ForEach(conversations) { $conversation in
|
||||
if viewModel.isLoadingFirstPage {
|
||||
ConversationsListRow(conversation: $conversation, viewModel: viewModel)
|
||||
.padding(.horizontal, .layoutPadding)
|
||||
.redacted(reason: .placeholder)
|
||||
} else {
|
||||
ConversationsListRow(conversation: $conversation, viewModel: viewModel)
|
||||
.padding(.horizontal, .layoutPadding)
|
||||
}
|
||||
Divider()
|
||||
}
|
||||
ForEach(conversations) { $conversation in
|
||||
if viewModel.isLoadingFirstPage {
|
||||
ConversationsListRow(conversation: $conversation, viewModel: viewModel)
|
||||
.padding(.horizontal, .layoutPadding)
|
||||
.redacted(reason: .placeholder)
|
||||
} else {
|
||||
ConversationsListRow(conversation: $conversation, viewModel: viewModel)
|
||||
.padding(.horizontal, .layoutPadding)
|
||||
}
|
||||
Divider()
|
||||
}
|
||||
} else if conversations.isEmpty && !viewModel.isLoadingFirstPage && !viewModel.isError {
|
||||
EmptyView(iconName: "tray",
|
||||
title: "conversations.empty.title",
|
||||
|
|
|
@ -86,22 +86,22 @@ class ConversationsListViewModel: ObservableObject {
|
|||
} catch {}
|
||||
}
|
||||
|
||||
private func updateConversationWithNewLastStatus(conversation: Conversation, newLastStatus: Status) {
|
||||
let newConversation = Conversation(id: conversation.id, unread: conversation.unread, lastStatus: newLastStatus, accounts: conversation.accounts)
|
||||
updateConversations(conversation: newConversation)
|
||||
}
|
||||
private func updateConversationWithNewLastStatus(conversation: Conversation, newLastStatus: Status) {
|
||||
let newConversation = Conversation(id: conversation.id, unread: conversation.unread, lastStatus: newLastStatus, accounts: conversation.accounts)
|
||||
updateConversations(conversation: newConversation)
|
||||
}
|
||||
|
||||
private func updateConversations(conversation: Conversation) {
|
||||
if let index = conversations.firstIndex(where: { $0.id == conversation.id }) {
|
||||
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) })
|
||||
private func updateConversations(conversation: Conversation) {
|
||||
if let index = conversations.firstIndex(where: { $0.id == conversation.id }) {
|
||||
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) })
|
||||
}
|
||||
|
||||
func handleEvent(event: any StreamEvent) {
|
||||
if let event = event as? StreamEventConversation {
|
||||
updateConversations(conversation: event.conversation)
|
||||
updateConversations(conversation: event.conversation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ public class QuickLook: ObservableObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Published public private(set) var urls: [URL] = []
|
||||
@Published public private(set) var isPreparing: Bool = false
|
||||
@Published public private(set) var latestError: Error?
|
||||
|
@ -73,7 +74,7 @@ public class QuickLook: ObservableObject {
|
|||
return path
|
||||
}
|
||||
|
||||
private func cleanup(urls: [URL]) {
|
||||
private func cleanup(urls _: [URL]) {
|
||||
try? FileManager.default.removeItem(at: quickLookDir)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,12 @@ public struct Conversation: Identifiable, Decodable, Hashable, Equatable {
|
|||
public let lastStatus: Status?
|
||||
public let accounts: [Account]
|
||||
|
||||
public init(id: String, unread: Bool, lastStatus: Status? = nil, accounts: [Account]) {
|
||||
self.id = id
|
||||
self.unread = unread
|
||||
self.lastStatus = lastStatus
|
||||
self.accounts = accounts
|
||||
}
|
||||
public init(id: String, unread: Bool, lastStatus: Status? = nil, accounts: [Account]) {
|
||||
self.id = id
|
||||
self.unread = unread
|
||||
self.lastStatus = lastStatus
|
||||
self.accounts = accounts
|
||||
}
|
||||
|
||||
public static func placeholder() -> Conversation {
|
||||
.init(id: UUID().uuidString, unread: false, lastStatus: .placeholder(), accounts: [.placeholder()])
|
||||
|
|
|
@ -190,7 +190,8 @@ public struct UpdateCredentialsData: Encodable, Sendable {
|
|||
bot: Bool,
|
||||
locked: Bool,
|
||||
discoverable: Bool,
|
||||
fieldsAttributes: [FieldData]) {
|
||||
fieldsAttributes: [FieldData])
|
||||
{
|
||||
self.displayName = displayName
|
||||
self.note = note
|
||||
self.source = source
|
||||
|
@ -204,5 +205,4 @@ public struct UpdateCredentialsData: Encodable, Sendable {
|
|||
}
|
||||
self.fieldsAttributes = fieldAttributes
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -197,7 +197,6 @@ public extension URL {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extension UIImage {
|
||||
func resized(to size: CGSize) -> UIImage {
|
||||
UIGraphicsImageRenderer(size: size).image { _ in
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
import SwiftUI
|
||||
import Models
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
class StatusEmbedCache {
|
||||
|
@ -8,7 +8,7 @@ class StatusEmbedCache {
|
|||
|
||||
private var cache: [URL: Status] = [:]
|
||||
|
||||
private init() { }
|
||||
private init() {}
|
||||
|
||||
func set(url: URL, status: Status) {
|
||||
cache[url] = status
|
||||
|
|
|
@ -45,7 +45,7 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
|
|||
routerPath: routerPath,
|
||||
isRemote: isRemote)
|
||||
|
||||
})
|
||||
})
|
||||
.id(status.id)
|
||||
.onAppear {
|
||||
fetcher.statusDidAppear(status: status)
|
||||
|
|
|
@ -47,7 +47,7 @@ public class StatusRowViewModel: ObservableObject {
|
|||
|
||||
var isThread: Bool {
|
||||
status.reblog?.inReplyToId != nil || status.reblog?.inReplyToAccountId != nil ||
|
||||
status.inReplyToId != nil || status.inReplyToAccountId != nil
|
||||
status.inReplyToId != nil || status.inReplyToAccountId != nil
|
||||
}
|
||||
|
||||
var highlightRowColor: Color {
|
||||
|
@ -99,7 +99,8 @@ public class StatusRowViewModel: ObservableObject {
|
|||
isFiltered = filter != nil
|
||||
|
||||
if let url = embededStatusURL(),
|
||||
let embed = StatusEmbedCache.shared.get(url: url) {
|
||||
let embed = StatusEmbedCache.shared.get(url: url)
|
||||
{
|
||||
isEmbedLoading = false
|
||||
embeddedStatus = embed
|
||||
}
|
||||
|
@ -159,7 +160,8 @@ public class StatusRowViewModel: ObservableObject {
|
|||
let content = status.reblog?.content ?? status.content
|
||||
if !content.statusesURLs.isEmpty,
|
||||
let url = content.statusesURLs.first,
|
||||
client.hasConnection(with: url) {
|
||||
client.hasConnection(with: url)
|
||||
{
|
||||
return url
|
||||
}
|
||||
return nil
|
||||
|
@ -167,7 +169,8 @@ public class StatusRowViewModel: ObservableObject {
|
|||
|
||||
func loadEmbeddedStatus() async {
|
||||
guard embeddedStatus == nil,
|
||||
let url = embededStatusURL() else {
|
||||
let url = embededStatusURL()
|
||||
else {
|
||||
if isEmbedLoading {
|
||||
isEmbedLoading = false
|
||||
}
|
||||
|
|
|
@ -85,8 +85,8 @@ struct StatusRowHeaderView: View {
|
|||
|
||||
private var dateView: Text {
|
||||
Text(status.createdAt.relativeFormatted) +
|
||||
Text(" ⸱ ") +
|
||||
Text(Image(systemName: viewModel.status.visibility.iconName))
|
||||
Text(" ⸱ ") +
|
||||
Text(Image(systemName: viewModel.status.visibility.iconName))
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
|
Loading…
Reference in a new issue