Add reply policy and exclusive fields to lists
This commit is contained in:
parent
eb496243c7
commit
a46eaafbcf
|
@ -11,14 +11,18 @@ import Foundation
|
||||||
public struct List: ListProtocol, Decodable, Equatable, Hashable, Sendable {
|
public struct List: ListProtocol, Decodable, Equatable, Hashable, Sendable {
|
||||||
public let id: String
|
public let id: String
|
||||||
public let title: String
|
public let title: String
|
||||||
|
public let replyPolicy: ReplyPolicy?
|
||||||
|
public let exclusive: Bool?
|
||||||
|
|
||||||
public var timeline: Timeline {
|
public var timeline: Timeline {
|
||||||
return .list(id: id)
|
return .list(id: id)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(id: String, title: String) {
|
public init(id: String, title: String, replyPolicy: ReplyPolicy?, exclusive: Bool?) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.title = title
|
self.title = title
|
||||||
|
self.replyPolicy = replyPolicy
|
||||||
|
self.exclusive = exclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func ==(lhs: List, rhs: List) -> Bool {
|
public static func ==(lhs: List, rhs: List) -> Bool {
|
||||||
|
@ -36,8 +40,15 @@ public struct List: ListProtocol, Decodable, Equatable, Hashable, Sendable {
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func update(_ listID: String, title: String) -> Request<List> {
|
public static func update(_ listID: String, title: String, replyPolicy: ReplyPolicy?, exclusive: Bool?) -> Request<List> {
|
||||||
return Request<List>(method: .put, path: "/api/v1/lists/\(listID)", body: ParametersBody(["title" => title]))
|
var params = ["title" => title]
|
||||||
|
if let replyPolicy {
|
||||||
|
params.append("replies_policy" => replyPolicy.rawValue)
|
||||||
|
}
|
||||||
|
if let exclusive {
|
||||||
|
params.append("exclusive" => exclusive)
|
||||||
|
}
|
||||||
|
return Request<List>(method: .put, path: "/api/v1/lists/\(listID)", body: ParametersBody(params))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func delete(_ listID: String) -> Request<Empty> {
|
public static func delete(_ listID: String) -> Request<Empty> {
|
||||||
|
@ -59,5 +70,13 @@ public struct List: ListProtocol, Decodable, Equatable, Hashable, Sendable {
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case id
|
case id
|
||||||
case title
|
case title
|
||||||
|
case replyPolicy = "replies_policy"
|
||||||
|
case exclusive
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension List {
|
||||||
|
public enum ReplyPolicy: String, Codable, Hashable, CaseIterable, Sendable {
|
||||||
|
case followed, list, none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,6 @@ import Foundation
|
||||||
public protocol ListProtocol {
|
public protocol ListProtocol {
|
||||||
var id: String { get }
|
var id: String { get }
|
||||||
var title: String { get }
|
var title: String { get }
|
||||||
|
var replyPolicy: List.ReplyPolicy? { get }
|
||||||
|
var exclusive: Bool? { get }
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,16 +449,12 @@ class MastodonController: ObservableObject {
|
||||||
guard let lists = try? persistentContainer.viewContext.fetch(req) else {
|
guard let lists = try? persistentContainer.viewContext.fetch(req) else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
return lists.map {
|
return lists.map(\.apiList).sorted(using: SemiCaseSensitiveComparator.keyPath(\.title))
|
||||||
List(id: $0.id, title: $0.title)
|
|
||||||
}.sorted(using: SemiCaseSensitiveComparator.keyPath(\.title))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCachedList(id: String) -> List? {
|
func getCachedList(id: String) -> List? {
|
||||||
let req = ListMO.fetchRequest(id: id)
|
let req = ListMO.fetchRequest(id: id)
|
||||||
return (try? persistentContainer.viewContext.fetch(req).first).flatMap {
|
return (try? persistentContainer.viewContext.fetch(req).first).map(\.apiList)
|
||||||
List(id: $0.id, title: $0.title)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
@ -47,7 +47,7 @@ class RenameListService {
|
||||||
|
|
||||||
private func updateList(with title: String) async {
|
private func updateList(with title: String) async {
|
||||||
do {
|
do {
|
||||||
let req = List.update(list.id, title: title)
|
let req = List.update(list.id, title: title, replyPolicy: nil, exclusive: nil)
|
||||||
let (list, _) = try await mastodonController.run(req)
|
let (list, _) = try await mastodonController.run(req)
|
||||||
mastodonController.renamedList(list)
|
mastodonController.renamedList(list)
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -25,6 +25,22 @@ public final class ListMO: NSManagedObject, ListProtocol {
|
||||||
|
|
||||||
@NSManaged public var id: String
|
@NSManaged public var id: String
|
||||||
@NSManaged public var title: String
|
@NSManaged public var title: String
|
||||||
|
@NSManaged private var replyPolicyString: String?
|
||||||
|
@NSManaged private var exclusiveInternal: Bool
|
||||||
|
|
||||||
|
public var replyPolicy: List.ReplyPolicy? {
|
||||||
|
get {
|
||||||
|
replyPolicyString.flatMap(List.ReplyPolicy.init(rawValue:))
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
replyPolicyString = newValue?.rawValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var exclusive: Bool? {
|
||||||
|
get { exclusiveInternal }
|
||||||
|
set { exclusiveInternal = newValue ?? false }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,5 +53,16 @@ extension ListMO {
|
||||||
func updateFrom(apiList list: List) {
|
func updateFrom(apiList list: List) {
|
||||||
self.id = list.id
|
self.id = list.id
|
||||||
self.title = list.title
|
self.title = list.title
|
||||||
|
self.replyPolicy = list.replyPolicy
|
||||||
|
self.exclusive = list.exclusive
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiList: List {
|
||||||
|
List(
|
||||||
|
id: id,
|
||||||
|
title: title,
|
||||||
|
replyPolicy: replyPolicy,
|
||||||
|
exclusive: exclusive
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,9 @@
|
||||||
<attribute name="url" attributeType="URI"/>
|
<attribute name="url" attributeType="URI"/>
|
||||||
</entity>
|
</entity>
|
||||||
<entity name="List" representedClassName="ListMO" syncable="YES">
|
<entity name="List" representedClassName="ListMO" syncable="YES">
|
||||||
|
<attribute name="exclusiveInternal" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||||
<attribute name="id" optional="YES" attributeType="String"/>
|
<attribute name="id" optional="YES" attributeType="String"/>
|
||||||
|
<attribute name="replyPolicyString" optional="YES" attributeType="String"/>
|
||||||
<attribute name="title" optional="YES" attributeType="String"/>
|
<attribute name="title" optional="YES" attributeType="String"/>
|
||||||
<uniquenessConstraints>
|
<uniquenessConstraints>
|
||||||
<uniquenessConstraint>
|
<uniquenessConstraint>
|
||||||
|
|
|
@ -112,7 +112,7 @@ class AuxiliarySceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDel
|
||||||
case .list(id: let id):
|
case .list(id: let id):
|
||||||
let req = ListMO.fetchRequest(id: id)
|
let req = ListMO.fetchRequest(id: id)
|
||||||
if let list = try? mastodonController.persistentContainer.viewContext.fetch(req).first {
|
if let list = try? mastodonController.persistentContainer.viewContext.fetch(req).first {
|
||||||
return ListTimelineViewController(for: List(id: id, title: list.title), mastodonController: mastodonController)
|
return ListTimelineViewController(for: list.apiList, mastodonController: mastodonController)
|
||||||
} else {
|
} else {
|
||||||
return TimelineViewController(for: timeline, mastodonController: mastodonController)
|
return TimelineViewController(for: timeline, mastodonController: mastodonController)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue