mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-01-31 09:35:13 +01:00
Remove remaining Tag-stuff (IOS-186) (#1205)
This commit is contained in:
parent
120b9e18b1
commit
7ab194b15d
@ -28,30 +28,4 @@ extension DataSourceFacade {
|
||||
transition: .show
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
static func coordinateToHashtagScene(
|
||||
provider: DataSourceProvider & AuthContextProvider,
|
||||
tag: ManagedObjectRecord<Tag>
|
||||
) async {
|
||||
let managedObjectContext = provider.context.managedObjectContext
|
||||
let _name: String? = try? await managedObjectContext.perform {
|
||||
guard let tag = tag.object(in: managedObjectContext) else { return nil }
|
||||
return tag.name
|
||||
}
|
||||
|
||||
guard let name = _name else { return }
|
||||
|
||||
let hashtagTimelineViewModel = HashtagTimelineViewModel(
|
||||
context: provider.context,
|
||||
authContext: provider.authContext,
|
||||
hashtag: name
|
||||
)
|
||||
|
||||
_ = provider.coordinator.present(
|
||||
scene: .hashtagTimeline(viewModel: hashtagTimelineViewModel),
|
||||
from: provider,
|
||||
transition: .show
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -38,20 +38,6 @@ final class HashtagTimelineHeaderView: UIView {
|
||||
postsTodayCount: Int(entity.history?.first?.uses ?? "0") ?? 0
|
||||
)
|
||||
}
|
||||
|
||||
static func from(_ entity: Tag) -> Self {
|
||||
Data(
|
||||
name: entity.name,
|
||||
following: entity.following,
|
||||
postCount: entity.histories.reduce(0) { res, acc in
|
||||
res + (Int(acc.uses) ?? 0)
|
||||
},
|
||||
participantsCount: entity.histories.reduce(0) { res, acc in
|
||||
res + (Int(acc.accounts) ?? 0)
|
||||
},
|
||||
postsTodayCount: Int(entity.histories.first?.uses ?? "0") ?? 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
let titleLabel = UILabel()
|
||||
|
@ -61,18 +61,7 @@ final class HashtagTimelineViewModel {
|
||||
}
|
||||
|
||||
func viewWillAppear() {
|
||||
let predicate = Tag.predicate(
|
||||
domain: authContext.mastodonAuthenticationBox.domain,
|
||||
name: hashtag
|
||||
)
|
||||
|
||||
guard
|
||||
let object = Tag.findOrFetch(in: context.managedObjectContext, matching: predicate)
|
||||
else {
|
||||
return hashtagDetails.send(hashtagDetails.value?.copy(following: false))
|
||||
}
|
||||
|
||||
hashtagDetails.send(hashtagDetails.value?.copy(following: object.following))
|
||||
hashtagDetails.send(hashtagDetails.value?.copy(following: hashtagEntity.value?.following ?? false))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="23B74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22522" systemVersion="23C71" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<entity name="Application" representedClassName="CoreDataStack.Application" syncable="YES">
|
||||
<attribute name="identifier" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="name" attributeType="String"/>
|
||||
@ -111,7 +111,6 @@
|
||||
<relationship name="endorsed" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="endorsedBy" inverseEntity="MastodonUser"/>
|
||||
<relationship name="endorsedBy" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="endorsed" inverseEntity="MastodonUser"/>
|
||||
<relationship name="favourite" toMany="YES" deletionRule="Nullify" destinationEntity="Status" inverseName="favouritedBy" inverseEntity="Status"/>
|
||||
<relationship name="followedTags" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Tag" inverseName="followedBy" inverseEntity="Tag"/>
|
||||
<relationship name="following" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="followingBy" inverseEntity="MastodonUser"/>
|
||||
<relationship name="followingBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="following" inverseEntity="MastodonUser"/>
|
||||
<relationship name="followRequested" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="followRequestedBy" inverseEntity="MastodonUser"/>
|
||||
@ -249,15 +248,4 @@
|
||||
<attribute name="updatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<relationship name="subscription" maxCount="1" deletionRule="Nullify" destinationEntity="Subscription" inverseName="alert" inverseEntity="Subscription"/>
|
||||
</entity>
|
||||
<entity name="Tag" representedClassName="CoreDataStack.Tag" syncable="YES">
|
||||
<attribute name="createAt" attributeType="Date" defaultDateTimeInterval="631123200" usesScalarValueType="NO"/>
|
||||
<attribute name="domain" attributeType="String" defaultValueString=""/>
|
||||
<attribute name="following" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="histories" optional="YES" attributeType="Binary"/>
|
||||
<attribute name="identifier" attributeType="UUID" usesScalarValueType="NO"/>
|
||||
<attribute name="name" attributeType="String"/>
|
||||
<attribute name="updatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="url" attributeType="String"/>
|
||||
<relationship name="followedBy" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="followedTags" inverseEntity="MastodonUser"/>
|
||||
</entity>
|
||||
</model>
|
@ -1,81 +0,0 @@
|
||||
//
|
||||
// History.swift
|
||||
// CoreDataStack
|
||||
//
|
||||
// Created by sxiaojian on 2021/2/1.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
import Foundation
|
||||
|
||||
public final class History: NSManagedObject {
|
||||
public typealias ID = UUID
|
||||
@NSManaged public private(set) var identifier: ID
|
||||
@NSManaged public private(set) var createAt: Date
|
||||
|
||||
@NSManaged public private(set) var day: Date
|
||||
@NSManaged public private(set) var uses: String
|
||||
@NSManaged public private(set) var accounts: String
|
||||
|
||||
// many-to-one relationship
|
||||
@NSManaged public private(set) var tag: Tag
|
||||
}
|
||||
|
||||
public extension History {
|
||||
override func awakeFromInsert() {
|
||||
super.awakeFromInsert()
|
||||
setPrimitiveValue(UUID(), forKey: #keyPath(History.identifier))
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
static func insert(
|
||||
into context: NSManagedObjectContext,
|
||||
property: Property
|
||||
) -> History {
|
||||
let history: History = context.insertObject()
|
||||
history.day = property.day
|
||||
history.uses = property.uses
|
||||
history.accounts = property.accounts
|
||||
return history
|
||||
}
|
||||
}
|
||||
|
||||
public extension History {
|
||||
func update(day: Date) {
|
||||
if self.day != day {
|
||||
self.day = day
|
||||
}
|
||||
}
|
||||
|
||||
func update(uses: String) {
|
||||
if self.uses != uses {
|
||||
self.uses = uses
|
||||
}
|
||||
}
|
||||
|
||||
func update(accounts: String) {
|
||||
if self.accounts != accounts {
|
||||
self.accounts = accounts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension History {
|
||||
struct Property {
|
||||
public let day: Date
|
||||
public let uses: String
|
||||
public let accounts: String
|
||||
|
||||
public init(day: Date, uses: String, accounts: String) {
|
||||
self.day = day
|
||||
self.uses = uses
|
||||
self.accounts = accounts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension History: Managed {
|
||||
public static var defaultSortDescriptors: [NSSortDescriptor] {
|
||||
return [NSSortDescriptor(keyPath: \History.createAt, ascending: false)]
|
||||
}
|
||||
}
|
@ -76,7 +76,6 @@ final public class MastodonUser: NSManagedObject {
|
||||
@NSManaged public private(set) var votePollOptions: Set<PollOption>
|
||||
@NSManaged public private(set) var votePolls: Set<Poll>
|
||||
// relationships
|
||||
@NSManaged public private(set) var followedTags: Set<Tag>
|
||||
@NSManaged public private(set) var following: Set<MastodonUser>
|
||||
@NSManaged public private(set) var followingBy: Set<MastodonUser>
|
||||
@NSManaged public private(set) var followRequested: Set<MastodonUser>
|
||||
|
@ -1,215 +0,0 @@
|
||||
//
|
||||
// Tag.swift
|
||||
// CoreDataStack
|
||||
//
|
||||
// Created by sxiaojian on 2021/2/1.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
import Foundation
|
||||
|
||||
public final class Tag: NSManagedObject {
|
||||
public typealias ID = UUID
|
||||
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var identifier: ID
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var domain: String
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var createAt: Date
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public private(set) var updatedAt: Date
|
||||
|
||||
// sourcery: autoGenerateProperty
|
||||
@NSManaged public private(set) var name: String
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public private(set) var url: String
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@NSManaged public private(set) var following: Bool
|
||||
|
||||
// one-to-one relationship
|
||||
|
||||
// many-to-many relationship
|
||||
@NSManaged public private(set) var followedBy: Set<MastodonUser>
|
||||
}
|
||||
|
||||
extension Tag {
|
||||
// sourcery: autoUpdatableObject, autoGenerateProperty
|
||||
@objc public var histories: [MastodonTagHistory] {
|
||||
get {
|
||||
let keyPath = #keyPath(Tag.histories)
|
||||
willAccessValue(forKey: keyPath)
|
||||
let _data = primitiveValue(forKey: keyPath) as? Data
|
||||
didAccessValue(forKey: keyPath)
|
||||
do {
|
||||
guard let data = _data else { return [] }
|
||||
let attachments = try JSONDecoder().decode([MastodonTagHistory].self, from: data)
|
||||
return attachments
|
||||
} catch {
|
||||
assertionFailure(error.localizedDescription)
|
||||
return []
|
||||
}
|
||||
}
|
||||
set {
|
||||
let keyPath = #keyPath(Tag.histories)
|
||||
let data = try? JSONEncoder().encode(newValue)
|
||||
willChangeValue(forKey: keyPath)
|
||||
setPrimitiveValue(data, forKey: keyPath)
|
||||
didChangeValue(forKey: keyPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Tag {
|
||||
@discardableResult
|
||||
public static func insert(
|
||||
into context: NSManagedObjectContext,
|
||||
property: Property
|
||||
) -> Tag {
|
||||
let object: Tag = context.insertObject()
|
||||
|
||||
object.configure(property: property)
|
||||
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Tag: Managed {
|
||||
public static var defaultSortDescriptors: [NSSortDescriptor] {
|
||||
[NSSortDescriptor(keyPath: \Tag.createAt, ascending: false)]
|
||||
}
|
||||
}
|
||||
|
||||
public extension Tag {
|
||||
|
||||
static func predicate(domain: String) -> NSPredicate {
|
||||
NSPredicate(format: "%K == %@", #keyPath(Tag.domain), domain)
|
||||
}
|
||||
|
||||
static func predicate(name: String) -> NSPredicate {
|
||||
// use case-insensitive query as tags #CaN #BE #speLLed #USiNG #arbITRARy #cASe
|
||||
NSPredicate(format: "%K MATCHES[c] %@", #keyPath(Tag.name), name)
|
||||
}
|
||||
|
||||
static func predicate(domain: String, following: Bool) -> NSPredicate {
|
||||
NSPredicate(format: "%K == %@ AND %K == %d", #keyPath(Tag.domain), domain, #keyPath(Tag.following), following)
|
||||
}
|
||||
|
||||
static func predicate(followedBy user: MastodonUser) -> NSPredicate {
|
||||
NSPredicate(format: "ANY %K.%K == %@", #keyPath(Tag.followedBy), #keyPath(MastodonUser.id), user.id)
|
||||
}
|
||||
|
||||
static func predicate(domain: String, name: String) -> NSPredicate {
|
||||
NSCompoundPredicate(andPredicateWithSubpredicates: [
|
||||
predicate(domain: domain),
|
||||
predicate(name: name),
|
||||
])
|
||||
}
|
||||
|
||||
static func predicate(domain: String, following: Bool, by user: MastodonUser) -> NSPredicate {
|
||||
NSCompoundPredicate(andPredicateWithSubpredicates: [
|
||||
predicate(domain: domain, following: following),
|
||||
predicate(followedBy: user)
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AutoGenerateProperty
|
||||
extension Tag: AutoGenerateProperty {
|
||||
// sourcery:inline:Tag.AutoGenerateProperty
|
||||
|
||||
// Generated using Sourcery
|
||||
// DO NOT EDIT
|
||||
public struct Property {
|
||||
public let identifier: ID
|
||||
public let domain: String
|
||||
public let createAt: Date
|
||||
public let updatedAt: Date
|
||||
public let name: String
|
||||
public let url: String
|
||||
public let following: Bool
|
||||
public let histories: [MastodonTagHistory]
|
||||
|
||||
public init(
|
||||
identifier: ID,
|
||||
domain: String,
|
||||
createAt: Date,
|
||||
updatedAt: Date,
|
||||
name: String,
|
||||
url: String,
|
||||
following: Bool,
|
||||
histories: [MastodonTagHistory]
|
||||
) {
|
||||
self.identifier = identifier
|
||||
self.domain = domain
|
||||
self.createAt = createAt
|
||||
self.updatedAt = updatedAt
|
||||
self.name = name
|
||||
self.url = url
|
||||
self.following = following
|
||||
self.histories = histories
|
||||
}
|
||||
}
|
||||
|
||||
public func configure(property: Property) {
|
||||
self.identifier = property.identifier
|
||||
self.domain = property.domain
|
||||
self.createAt = property.createAt
|
||||
self.updatedAt = property.updatedAt
|
||||
self.name = property.name
|
||||
self.url = property.url
|
||||
self.following = property.following
|
||||
self.histories = property.histories
|
||||
}
|
||||
|
||||
public func update(property: Property) {
|
||||
update(updatedAt: property.updatedAt)
|
||||
update(url: property.url)
|
||||
update(following: property.following)
|
||||
update(histories: property.histories)
|
||||
}
|
||||
// sourcery:end
|
||||
}
|
||||
|
||||
// MARK: - AutoUpdatableObject
|
||||
extension Tag: AutoUpdatableObject {
|
||||
// sourcery:inline:Tag.AutoUpdatableObject
|
||||
|
||||
// Generated using Sourcery
|
||||
// DO NOT EDIT
|
||||
public func update(updatedAt: Date) {
|
||||
if self.updatedAt != updatedAt {
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
}
|
||||
public func update(url: String) {
|
||||
if self.url != url {
|
||||
self.url = url
|
||||
}
|
||||
}
|
||||
public func update(following: Bool) {
|
||||
if self.following != following {
|
||||
self.following = following
|
||||
}
|
||||
}
|
||||
public func update(histories: [MastodonTagHistory]) {
|
||||
if self.histories != histories {
|
||||
self.histories = histories
|
||||
}
|
||||
}
|
||||
// sourcery:end
|
||||
|
||||
public func update(followed: Bool, by mastodonUser: MastodonUser) {
|
||||
if following {
|
||||
if !self.followedBy.contains(mastodonUser) {
|
||||
self.mutableSetValue(forKey: #keyPath(Tag.followedBy)).add(mastodonUser)
|
||||
}
|
||||
} else {
|
||||
if self.followedBy.contains(mastodonUser) {
|
||||
self.mutableSetValue(forKey: #keyPath(Tag.followedBy)).remove(mastodonUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
//
|
||||
// Tag+Property.swift
|
||||
// Mastodon
|
||||
//
|
||||
// Created by MainasuK on 2022-1-20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreDataStack
|
||||
import MastodonSDK
|
||||
|
||||
extension Tag.Property {
|
||||
public init(
|
||||
entity: Mastodon.Entity.Tag,
|
||||
domain: String,
|
||||
networkDate: Date
|
||||
) {
|
||||
self.init(
|
||||
identifier: UUID(),
|
||||
domain: domain,
|
||||
createAt: networkDate,
|
||||
updatedAt: networkDate,
|
||||
name: entity.name,
|
||||
url: entity.url,
|
||||
following: entity.following ?? false,
|
||||
histories: {
|
||||
guard let histories = entity.history else { return [] }
|
||||
let result: [MastodonTagHistory] = histories.map { history in
|
||||
return MastodonTagHistory(entity: history)
|
||||
}
|
||||
return result
|
||||
}()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension MastodonTagHistory {
|
||||
public convenience init(entity: Mastodon.Entity.History) {
|
||||
self.init(
|
||||
day: entity.day,
|
||||
uses: entity.uses,
|
||||
accounts: entity.accounts
|
||||
)
|
||||
}
|
||||
}
|
@ -211,7 +211,7 @@ extension Mastodon.API {
|
||||
return try Mastodon.API.decoder.decode(type, from: data)
|
||||
} catch let decodeError {
|
||||
#if DEBUG
|
||||
debugPrint(decodeError)
|
||||
debugPrint("\(response.url), Data: \(String(data: data, encoding: .utf8)), \(decodeError)")
|
||||
#endif
|
||||
|
||||
guard let httpURLResponse = response as? HTTPURLResponse else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user