forked from mastodon/mastodon-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adapt the app to async & await. Update timeline UI
- Loading branch information
Showing
754 changed files
with
29,643 additions
and
25,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sources: | ||
- . | ||
templates: | ||
- ./Template | ||
output: | ||
Generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
CoreDataStack/CoreData.xcdatamodeld/CoreData 2.xcdatamodel/contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
283 changes: 283 additions & 0 deletions
283
CoreDataStack/CoreData.xcdatamodeld/CoreData 3.xcdatamodel/contents
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
// | ||
// Feed.swift | ||
// CoreDataStack | ||
// | ||
// Created by MainasuK on 2022-1-11. | ||
// | ||
|
||
import Foundation | ||
import CoreData | ||
|
||
final public class Feed: NSManagedObject { | ||
|
||
@NSManaged public private(set) var acctRaw: String | ||
// sourcery: autoGenerateProperty | ||
public var acct: Acct { | ||
get { | ||
Acct(rawValue: acctRaw) ?? .none | ||
} | ||
set { | ||
acctRaw = newValue.rawValue | ||
} | ||
} | ||
|
||
@NSManaged public private(set) var kindRaw: String | ||
// sourcery: autoGenerateProperty | ||
public var kind: Kind { | ||
get { | ||
Kind(rawValue: kindRaw) ?? .none | ||
} | ||
set { | ||
kindRaw = newValue.rawValue | ||
} | ||
} | ||
|
||
// sourcery: autoUpdatableObject, autoGenerateProperty | ||
@NSManaged public private(set) var hasMore: Bool | ||
// sourcery: autoUpdatableObject | ||
@NSManaged public private(set) var isLoadingMore: Bool | ||
|
||
// sourcery: autoUpdatableObject, autoGenerateProperty | ||
@NSManaged public private(set) var createdAt: Date | ||
// sourcery: autoUpdatableObject, autoGenerateProperty | ||
@NSManaged public private(set) var updatedAt: Date | ||
|
||
// one-to-one relationship | ||
@NSManaged public private(set) var status: Status? | ||
@NSManaged public private(set) var notification: Notification? | ||
|
||
} | ||
|
||
extension Feed { | ||
|
||
@discardableResult | ||
public static func insert( | ||
into context: NSManagedObjectContext, | ||
property: Property | ||
) -> Feed { | ||
let object: Feed = context.insertObject() | ||
object.configure(property: property) | ||
return object | ||
} | ||
|
||
} | ||
|
||
extension Feed: Managed { | ||
public static var defaultSortDescriptors: [NSSortDescriptor] { | ||
return [NSSortDescriptor(keyPath: \Feed.createdAt, ascending: false)] | ||
} | ||
} | ||
|
||
extension Feed { | ||
|
||
static func predicate(kind: Kind) -> NSPredicate { | ||
return NSPredicate(format: "%K == %@", #keyPath(Feed.kindRaw), kind.rawValue) | ||
} | ||
|
||
static func predicate(acct: Acct) -> NSPredicate { | ||
return NSPredicate(format: "%K == %@", #keyPath(Feed.acctRaw), acct.rawValue) | ||
} | ||
|
||
public static func predicate(kind: Kind, acct: Acct) -> NSPredicate { | ||
return NSCompoundPredicate(andPredicateWithSubpredicates: [ | ||
Feed.predicate(kind: kind), | ||
Feed.predicate(acct: acct) | ||
]) | ||
} | ||
|
||
public static func nonePredicate() -> NSPredicate { | ||
return predicate(kind: .none, acct: .none) | ||
} | ||
|
||
public static func hasMorePredicate() -> NSPredicate { | ||
return NSPredicate(format: "%K == YES", #keyPath(Feed.hasMore)) | ||
} | ||
|
||
public static func hasNotificationPredicate() -> NSPredicate { | ||
return NSPredicate(format: "%K != nil", #keyPath(Feed.notification)) | ||
} | ||
|
||
public static func notificationTypePredicate(types: [MastodonNotificationType]) -> NSPredicate { | ||
return NSCompoundPredicate(andPredicateWithSubpredicates: [ | ||
hasNotificationPredicate(), | ||
NSPredicate( | ||
format: "%K.%K IN %@", | ||
#keyPath(Feed.notification), | ||
#keyPath(Notification.typeRaw), | ||
types.map { $0.rawValue } | ||
) | ||
]) | ||
} | ||
|
||
} | ||
|
||
// MARK: - AutoGenerateProperty | ||
extension Feed: AutoGenerateProperty { | ||
// sourcery:inline:Feed.AutoGenerateProperty | ||
|
||
// Generated using Sourcery | ||
// DO NOT EDIT | ||
public struct Property { | ||
public let acct: Acct | ||
public let kind: Kind | ||
public let hasMore: Bool | ||
public let createdAt: Date | ||
public let updatedAt: Date | ||
|
||
public init( | ||
acct: Acct, | ||
kind: Kind, | ||
hasMore: Bool, | ||
createdAt: Date, | ||
updatedAt: Date | ||
) { | ||
self.acct = acct | ||
self.kind = kind | ||
self.hasMore = hasMore | ||
self.createdAt = createdAt | ||
self.updatedAt = updatedAt | ||
} | ||
} | ||
|
||
public func configure(property: Property) { | ||
self.acct = property.acct | ||
self.kind = property.kind | ||
self.hasMore = property.hasMore | ||
self.createdAt = property.createdAt | ||
self.updatedAt = property.updatedAt | ||
} | ||
|
||
public func update(property: Property) { | ||
update(hasMore: property.hasMore) | ||
update(createdAt: property.createdAt) | ||
update(updatedAt: property.updatedAt) | ||
} | ||
// sourcery:end | ||
} | ||
|
||
// MARK: - AutoUpdatableObject | ||
extension Feed: AutoUpdatableObject { | ||
// sourcery:inline:Feed.AutoUpdatableObject | ||
|
||
// Generated using Sourcery | ||
// DO NOT EDIT | ||
public func update(hasMore: Bool) { | ||
if self.hasMore != hasMore { | ||
self.hasMore = hasMore | ||
} | ||
} | ||
public func update(isLoadingMore: Bool) { | ||
if self.isLoadingMore != isLoadingMore { | ||
self.isLoadingMore = isLoadingMore | ||
} | ||
} | ||
public func update(createdAt: Date) { | ||
if self.createdAt != createdAt { | ||
self.createdAt = createdAt | ||
} | ||
} | ||
public func update(updatedAt: Date) { | ||
if self.updatedAt != updatedAt { | ||
self.updatedAt = updatedAt | ||
} | ||
} | ||
// sourcery:end | ||
} | ||
|
||
public protocol FeedIndexable { | ||
var feeds: Set<Feed> { get } | ||
func feed(kind: Feed.Kind, acct: Feed.Acct) -> Feed? | ||
} | ||
|
||
extension FeedIndexable { | ||
public func feed(kind: Feed.Kind, acct: Feed.Acct) -> Feed? { | ||
return feeds.first(where: { feed in | ||
feed.kind == kind && feed.acct == acct | ||
}) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.