mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 01:31:02 +00:00
Refactoring
This commit is contained in:
parent
992cbd475f
commit
e0d63700bc
7 changed files with 39 additions and 42 deletions
|
@ -4,12 +4,16 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
|
|
||||||
struct AccountInfo: Codable, Hashable, FetchableRecord {
|
struct AccountInfo: Codable, Hashable, FetchableRecord {
|
||||||
let account: AccountRecord
|
let record: AccountRecord
|
||||||
let moved: AccountRecord?
|
let movedRecord: AccountRecord?
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AccountInfo {
|
extension AccountInfo {
|
||||||
|
static func addingIncludes<T: DerivableRequest>(_ request: T) -> T where T.RowDecoder == AccountRecord {
|
||||||
|
request.including(optional: AccountRecord.moved.forKey(CodingKeys.movedRecord))
|
||||||
|
}
|
||||||
|
|
||||||
static func request(_ request: QueryInterfaceRequest<AccountRecord>) -> QueryInterfaceRequest<Self> {
|
static func request(_ request: QueryInterfaceRequest<AccountRecord>) -> QueryInterfaceRequest<Self> {
|
||||||
request.including(optional: AccountRecord.moved.forKey(CodingKeys.moved)).asRequest(of: self)
|
addingIncludes(request).asRequest(of: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,8 +195,8 @@ public extension ContentDatabase {
|
||||||
return [[]]
|
return [[]]
|
||||||
}
|
}
|
||||||
|
|
||||||
let ancestors = try parent.status.ancestors.fetchAll(db)
|
let ancestors = try parent.record.ancestors.fetchAll(db)
|
||||||
let descendants = try parent.status.descendants.fetchAll(db)
|
let descendants = try parent.record.descendants.fetchAll(db)
|
||||||
|
|
||||||
return [ancestors, [parent], descendants]
|
return [ancestors, [parent], descendants]
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,31 +4,21 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
|
|
||||||
struct StatusInfo: Codable, Hashable, FetchableRecord {
|
struct StatusInfo: Codable, Hashable, FetchableRecord {
|
||||||
let account: AccountRecord
|
let record: StatusRecord
|
||||||
let accountMoved: AccountRecord?
|
let accountInfo: AccountInfo
|
||||||
let status: StatusRecord
|
let reblogAccountInfo: AccountInfo?
|
||||||
let reblogAccount: AccountRecord?
|
let reblogRecord: StatusRecord?
|
||||||
let reblogAccountMoved: AccountRecord?
|
|
||||||
let reblog: StatusRecord?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension StatusInfo {
|
extension StatusInfo {
|
||||||
|
static func addingIncludes<T: DerivableRequest>(_ request: T) -> T where T.RowDecoder == StatusRecord {
|
||||||
|
request.including(required: AccountInfo.addingIncludes(StatusRecord.account).forKey(CodingKeys.accountInfo))
|
||||||
|
.including(optional: AccountInfo.addingIncludes(StatusRecord.reblogAccount)
|
||||||
|
.forKey(CodingKeys.reblogAccountInfo))
|
||||||
|
.including(optional: StatusRecord.reblog.forKey(CodingKeys.reblogRecord))
|
||||||
|
}
|
||||||
|
|
||||||
static func request(_ request: QueryInterfaceRequest<StatusRecord>) -> QueryInterfaceRequest<Self> {
|
static func request(_ request: QueryInterfaceRequest<StatusRecord>) -> QueryInterfaceRequest<Self> {
|
||||||
request.including(required: StatusRecord.account.forKey(CodingKeys.account))
|
addingIncludes(request).asRequest(of: self)
|
||||||
.including(optional: StatusRecord.accountMoved.forKey(CodingKeys.accountMoved))
|
|
||||||
.including(optional: StatusRecord.reblogAccount.forKey(CodingKeys.reblogAccount))
|
|
||||||
.including(optional: StatusRecord.reblogAccountMoved.forKey(CodingKeys.reblogAccountMoved))
|
|
||||||
.including(optional: StatusRecord.reblog.forKey(CodingKeys.reblog))
|
|
||||||
.asRequest(of: self)
|
|
||||||
}
|
|
||||||
|
|
||||||
var accountInfo: AccountInfo {
|
|
||||||
AccountInfo(account: account, moved: accountMoved)
|
|
||||||
}
|
|
||||||
|
|
||||||
var reblogAccountInfo: AccountInfo? {
|
|
||||||
guard let reblogAccount = reblogAccount else { return nil }
|
|
||||||
|
|
||||||
return AccountInfo(account: reblogAccount, moved: reblogAccountMoved)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ extension Account {
|
||||||
convenience init(info: AccountInfo) {
|
convenience init(info: AccountInfo) {
|
||||||
var moved: Account?
|
var moved: Account?
|
||||||
|
|
||||||
if let movedRecord = info.moved {
|
if let movedRecord = info.movedRecord {
|
||||||
moved = Self(record: movedRecord, moved: nil)
|
moved = Self(record: movedRecord, moved: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.init(record: info.account, moved: moved)
|
self.init(record: info.record, moved: moved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,16 @@ import GRDB
|
||||||
extension Identity {
|
extension Identity {
|
||||||
init(info: IdentityInfo) {
|
init(info: IdentityInfo) {
|
||||||
self.init(
|
self.init(
|
||||||
id: info.identity.id,
|
id: info.record.id,
|
||||||
url: info.identity.url,
|
url: info.record.url,
|
||||||
authenticated: info.identity.authenticated,
|
authenticated: info.record.authenticated,
|
||||||
pending: info.identity.pending,
|
pending: info.record.pending,
|
||||||
lastUsedAt: info.identity.lastUsedAt,
|
lastUsedAt: info.record.lastUsedAt,
|
||||||
preferences: info.identity.preferences,
|
preferences: info.record.preferences,
|
||||||
instance: info.instance,
|
instance: info.instance,
|
||||||
account: info.account,
|
account: info.account,
|
||||||
lastRegisteredDeviceToken: info.identity.lastRegisteredDeviceToken,
|
lastRegisteredDeviceToken: info.record.lastRegisteredDeviceToken,
|
||||||
pushSubscriptionAlerts: info.identity.pushSubscriptionAlerts)
|
pushSubscriptionAlerts: info.record.pushSubscriptionAlerts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ extension Status {
|
||||||
convenience init(info: StatusInfo) {
|
convenience init(info: StatusInfo) {
|
||||||
var reblog: Status?
|
var reblog: Status?
|
||||||
|
|
||||||
if let reblogRecord = info.reblog, let reblogAccountInfo = info.reblogAccountInfo {
|
if let reblogRecord = info.reblogRecord, let reblogAccountInfo = info.reblogAccountInfo {
|
||||||
reblog = Status(record: reblogRecord, account: Account(info: reblogAccountInfo), reblog: nil)
|
reblog = Status(record: reblogRecord, account: Account(info: reblogAccountInfo), reblog: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.init(record: info.status,
|
self.init(record: info.record,
|
||||||
account: Account(info: info.accountInfo),
|
account: Account(info: info.accountInfo),
|
||||||
reblog: reblog)
|
reblog: reblog)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,18 @@ import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct IdentityInfo: Codable, Hashable, FetchableRecord {
|
struct IdentityInfo: Codable, Hashable, FetchableRecord {
|
||||||
let identity: IdentityRecord
|
let record: IdentityRecord
|
||||||
let instance: Identity.Instance?
|
let instance: Identity.Instance?
|
||||||
let account: Identity.Account?
|
let account: Identity.Account?
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IdentityInfo {
|
extension IdentityInfo {
|
||||||
static func request(_ request: QueryInterfaceRequest<IdentityRecord>) -> QueryInterfaceRequest<Self> {
|
static func addingIncludes<T: DerivableRequest>(_ request: T) -> T where T.RowDecoder == IdentityRecord {
|
||||||
request.including(optional: IdentityRecord.instance.forKey(CodingKeys.instance))
|
request.including(optional: IdentityRecord.instance.forKey(CodingKeys.instance))
|
||||||
.including(optional: IdentityRecord.account.forKey(CodingKeys.account))
|
.including(optional: IdentityRecord.account.forKey(CodingKeys.account))
|
||||||
.asRequest(of: self)
|
}
|
||||||
|
|
||||||
|
static func request(_ request: QueryInterfaceRequest<IdentityRecord>) -> QueryInterfaceRequest<Self> {
|
||||||
|
addingIncludes(request).asRequest(of: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue