mirror of
https://github.com/metabolist/metatext.git
synced 2025-01-03 10:38:41 +00:00
Announcements data
This commit is contained in:
parent
406ac2a270
commit
418d7f354a
8 changed files with 111 additions and 0 deletions
|
@ -150,6 +150,21 @@ extension ContentDatabase {
|
||||||
t.column("count", .integer).notNull()
|
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
|
try db.create(table: "conversationRecord") { t in
|
||||||
t.column("id", .text).primaryKey(onConflict: .replace)
|
t.column("id", .text).primaryKey(onConflict: .replace)
|
||||||
t.column("unread", .boolean).notNull()
|
t.column("unread", .boolean).notNull()
|
||||||
|
|
|
@ -407,6 +407,18 @@ public extension ContentDatabase {
|
||||||
.eraseToAnyPublisher()
|
.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> {
|
func timelinePublisher(_ timeline: Timeline) -> AnyPublisher<[[CollectionItem]], Error> {
|
||||||
ValueObservation.tracking(
|
ValueObservation.tracking(
|
||||||
TimelineItemsInfo.request(TimelineRecord.filter(TimelineRecord.Columns.id == timeline.id)).fetchOne)
|
TimelineItemsInfo.request(TimelineRecord.filter(TimelineRecord.Columns.id == timeline.id)).fetchOne)
|
||||||
|
|
24
DB/Sources/DB/Extensions/Announcement+Extensions.swift
Normal file
24
DB/Sources/DB/Extensions/Announcement+Extensions.swift
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
18
Mastodon/Sources/Mastodon/Entities/Announcement.swift
Normal file
18
Mastodon/Sources/Mastodon/Entities/Announcement.swift
Normal file
|
@ -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()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshAnnouncements() -> AnyPublisher<Never, Error> {
|
||||||
|
mastodonAPIClient.request(AnnouncementsEndpoint.announcements)
|
||||||
|
.flatMap(contentDatabase.update(announcements:))
|
||||||
|
.print()
|
||||||
|
.eraseToAnyPublisher()
|
||||||
|
}
|
||||||
|
|
||||||
func confirmIdentity() -> AnyPublisher<Never, Error> {
|
func confirmIdentity() -> AnyPublisher<Never, Error> {
|
||||||
identityDatabase.confirmIdentity(id: id)
|
identityDatabase.confirmIdentity(id: id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,9 @@ public extension NavigationViewModel {
|
||||||
identification.service.refreshEmojis()
|
identification.service.refreshEmojis()
|
||||||
.sink { _ in } receiveValue: { _ in }
|
.sink { _ in } receiveValue: { _ in }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
identification.service.refreshAnnouncements()
|
||||||
|
.sink { _ in } receiveValue: { _ in }
|
||||||
|
.store(in: &cancellables)
|
||||||
|
|
||||||
if identification.identity.preferences.useServerPostingReadingPreferences {
|
if identification.identity.preferences.useServerPostingReadingPreferences {
|
||||||
identification.service.refreshServerPreferences()
|
identification.service.refreshServerPreferences()
|
||||||
|
|
Loading…
Reference in a new issue