Announcements data
This commit is contained in:
parent
406ac2a270
commit
418d7f354a
|
@ -150,6 +150,21 @@ extension ContentDatabase {
|
|||
t.column("count", .integer).notNull()
|
||||
}
|
||||
|
||||
try db.create(table: "announcement") { t in
|
||||
t.column("id", .text).primaryKey(onConflict: .replace)
|
||||
t.column("content", .text).notNull()
|
||||
t.column("startsAt", .datetime)
|
||||
t.column("endsAt", .datetime)
|
||||
t.column("allDay", .boolean).notNull()
|
||||
t.column("publishedAt", .datetime).notNull()
|
||||
t.column("updatedAt", .datetime).notNull()
|
||||
t.column("read", .boolean).notNull()
|
||||
t.column("mentions", .blob).notNull()
|
||||
t.column("tags", .blob).notNull()
|
||||
t.column("emojis", .blob).notNull()
|
||||
t.column("reactions", .blob).notNull()
|
||||
}
|
||||
|
||||
try db.create(table: "conversationRecord") { t in
|
||||
t.column("id", .text).primaryKey(onConflict: .replace)
|
||||
t.column("unread", .boolean).notNull()
|
||||
|
|
|
@ -407,6 +407,18 @@ public extension ContentDatabase {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func update(announcements: [Announcement]) -> AnyPublisher<Never, Error> {
|
||||
databaseWriter.writePublisher {
|
||||
for announcement in announcements {
|
||||
try announcement.save($0)
|
||||
}
|
||||
|
||||
try Announcement.filter(!announcements.map(\.id).contains(Announcement.Columns.id)).deleteAll($0)
|
||||
}
|
||||
.ignoreOutput()
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func timelinePublisher(_ timeline: Timeline) -> AnyPublisher<[[CollectionItem]], Error> {
|
||||
ValueObservation.tracking(
|
||||
TimelineItemsInfo.request(TimelineRecord.filter(TimelineRecord.Columns.id == timeline.id)).fetchOne)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright © 2021 Metabolist. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import GRDB
|
||||
import Mastodon
|
||||
|
||||
extension Announcement: ContentDatabaseRecord {}
|
||||
|
||||
extension Announcement {
|
||||
enum Columns: String, ColumnExpression {
|
||||
case id
|
||||
case content
|
||||
case startsAt
|
||||
case endsAt
|
||||
case allDay
|
||||
case publishedAt
|
||||
case updatedAt
|
||||
case read
|
||||
case mentions
|
||||
case tags
|
||||
case emojis
|
||||
case reactions
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright © 2021 Metabolist. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct Announcement: Codable, Hashable {
|
||||
public let id: String
|
||||
public let content: HTML
|
||||
public let startsAt: Date?
|
||||
public let endsAt: Date?
|
||||
public let allDay: Bool
|
||||
public let publishedAt: Date
|
||||
public let updatedAt: Date
|
||||
public let read: Bool
|
||||
public let mentions: [Mention]
|
||||
public let tags: [Tag]
|
||||
public let emojis: [Emoji]
|
||||
public let reactions: [AnnouncementReaction]
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright © 2021 Metabolist. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct AnnouncementReaction: Codable, Hashable {
|
||||
public let name: String
|
||||
public let count: Int
|
||||
public let me: Bool
|
||||
public let url: URL?
|
||||
public let staticUrl: URL?
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright © 2021 Metabolist. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import HTTP
|
||||
import Mastodon
|
||||
|
||||
public enum AnnouncementsEndpoint {
|
||||
case announcements
|
||||
}
|
||||
|
||||
extension AnnouncementsEndpoint: Endpoint {
|
||||
public typealias ResultType = [Announcement]
|
||||
|
||||
public var pathComponentsInContext: [String] {
|
||||
["announcements"]
|
||||
}
|
||||
|
||||
public var method: HTTPMethod {
|
||||
.get
|
||||
}
|
||||
}
|
|
@ -68,6 +68,13 @@ public extension IdentityService {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func refreshAnnouncements() -> AnyPublisher<Never, Error> {
|
||||
mastodonAPIClient.request(AnnouncementsEndpoint.announcements)
|
||||
.flatMap(contentDatabase.update(announcements:))
|
||||
.print()
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func confirmIdentity() -> AnyPublisher<Never, Error> {
|
||||
identityDatabase.confirmIdentity(id: id)
|
||||
}
|
||||
|
|
|
@ -123,6 +123,9 @@ public extension NavigationViewModel {
|
|||
identification.service.refreshEmojis()
|
||||
.sink { _ in } receiveValue: { _ in }
|
||||
.store(in: &cancellables)
|
||||
identification.service.refreshAnnouncements()
|
||||
.sink { _ in } receiveValue: { _ in }
|
||||
.store(in: &cancellables)
|
||||
|
||||
if identification.identity.preferences.useServerPostingReadingPreferences {
|
||||
identification.service.refreshServerPreferences()
|
||||
|
|
Loading…
Reference in New Issue