mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Refactoring
This commit is contained in:
parent
e0d63700bc
commit
a26acd0af1
2 changed files with 18 additions and 13 deletions
|
@ -70,11 +70,20 @@ extension AccountRecord {
|
||||||
StatusRecord.self,
|
StatusRecord.self,
|
||||||
through: pinnedStatusJoins,
|
through: pinnedStatusJoins,
|
||||||
using: AccountPinnedStatusJoin.status)
|
using: AccountPinnedStatusJoin.status)
|
||||||
|
static let statusJoins = hasMany(AccountStatusJoin.self)
|
||||||
|
|
||||||
var pinnedStatuses: QueryInterfaceRequest<StatusInfo> {
|
var pinnedStatuses: QueryInterfaceRequest<StatusInfo> {
|
||||||
StatusInfo.request(request(for: Self.pinnedStatuses))
|
StatusInfo.request(request(for: Self.pinnedStatuses))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func statuses(collection: ProfileCollection) -> QueryInterfaceRequest<StatusInfo> {
|
||||||
|
StatusInfo.request(
|
||||||
|
request(for: Self.hasMany(
|
||||||
|
StatusRecord.self,
|
||||||
|
through: Self.statusJoins.filter(AccountStatusJoin.Columns.collection == collection.rawValue),
|
||||||
|
using: AccountStatusJoin.status)))
|
||||||
|
}
|
||||||
|
|
||||||
init(account: Account) {
|
init(account: Account) {
|
||||||
id = account.id
|
id = account.id
|
||||||
username = account.username
|
username = account.username
|
||||||
|
|
|
@ -192,7 +192,7 @@ public extension ContentDatabase {
|
||||||
ValueObservation.tracking { db -> [[StatusInfo]] in
|
ValueObservation.tracking { db -> [[StatusInfo]] in
|
||||||
guard let parent = try StatusInfo.request(StatusRecord.filter(StatusRecord.Columns.id == parentID))
|
guard let parent = try StatusInfo.request(StatusRecord.filter(StatusRecord.Columns.id == parentID))
|
||||||
.fetchOne(db) else {
|
.fetchOne(db) else {
|
||||||
return [[]]
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
let ancestors = try parent.record.ancestors.fetchAll(db)
|
let ancestors = try parent.record.ancestors.fetchAll(db)
|
||||||
|
@ -210,20 +210,16 @@ public extension ContentDatabase {
|
||||||
accountID: String,
|
accountID: String,
|
||||||
collection: ProfileCollection) -> AnyPublisher<[[Status]], Error> {
|
collection: ProfileCollection) -> AnyPublisher<[[Status]], Error> {
|
||||||
ValueObservation.tracking { db -> [[StatusInfo]] in
|
ValueObservation.tracking { db -> [[StatusInfo]] in
|
||||||
let statuses = try StatusInfo.request(StatusRecord.filter(
|
guard let accountRecord = try AccountRecord
|
||||||
AccountStatusJoin
|
.filter(AccountRecord.Columns.id == accountID)
|
||||||
.select(AccountStatusJoin.Columns.statusId, as: String.self)
|
.fetchOne(db) else {
|
||||||
.filter(sql: "accountId = ? AND collection = ?", arguments: [accountID, collection.rawValue])
|
return []
|
||||||
.contains(StatusRecord.Columns.id))
|
}
|
||||||
.order(StatusRecord.Columns.createdAt.desc))
|
|
||||||
.fetchAll(db)
|
|
||||||
|
|
||||||
if
|
let statuses = try accountRecord.statuses(collection: collection).fetchAll(db)
|
||||||
case .statuses = collection,
|
|
||||||
let accountRecord = try AccountRecord.filter(AccountRecord.Columns.id == accountID).fetchOne(db) {
|
|
||||||
let pinnedStatuses = try accountRecord.pinnedStatuses.fetchAll(db)
|
|
||||||
|
|
||||||
return [pinnedStatuses, statuses]
|
if case .statuses = collection {
|
||||||
|
return [try accountRecord.pinnedStatuses.fetchAll(db), statuses]
|
||||||
} else {
|
} else {
|
||||||
return [statuses]
|
return [statuses]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue