Compare commits
4 Commits
0a7709526f
...
89a9bfba47
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 89a9bfba47 | |
Shadowfacts | 2798a199aa | |
Shadowfacts | 3d0402c1e0 | |
Shadowfacts | af0c9c92b6 |
|
@ -7,6 +7,8 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import WebURL
|
||||||
|
import WebURLFoundationExtras
|
||||||
|
|
||||||
public class Hashtag: Codable {
|
public class Hashtag: Codable {
|
||||||
public let name: String
|
public let name: String
|
||||||
|
@ -20,6 +22,18 @@ public class Hashtag: Codable {
|
||||||
self.history = nil
|
self.history = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public required init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.name = try container.decode(String.self, forKey: .name)
|
||||||
|
// pixelfed (possibly others) don't fully escape special characters in the hashtag url
|
||||||
|
if let url = URL(try container.decode(WebURL.self, forKey: .url)) {
|
||||||
|
self.url = url
|
||||||
|
} else {
|
||||||
|
throw DecodingError.dataCorruptedError(forKey: .url, in: container, debugDescription: "unable to convert WebURL to URL")
|
||||||
|
}
|
||||||
|
self.history = try container.decodeIfPresent([History].self, forKey: .history)
|
||||||
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case name
|
case name
|
||||||
case url
|
case url
|
||||||
|
|
|
@ -85,14 +85,16 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
self.older = pagination?.older
|
if !statuses.isEmpty {
|
||||||
self.newer = pagination?.newer
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
|
}
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
var snapshot = self.dataSource.snapshot()
|
var snapshot = self.dataSource.snapshot()
|
||||||
snapshot.appendItems(statuses.map { Item(id: $0.id, state: .unknown) }, toSection: .statuses)
|
snapshot.appendItems(statuses.map { Item(id: $0.id, state: .unknown, pinned: false) }, toSection: .statuses)
|
||||||
if self.kind == .statuses {
|
if self.kind == .statuses {
|
||||||
self.loadPinnedStatuses(snapshot: { snapshot }, completion: completion)
|
self.loadPinnedStatuses(snapshot: { snapshot }, completion: completion)
|
||||||
} else {
|
} else {
|
||||||
|
@ -120,7 +122,7 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
var snapshot = snapshot()
|
var snapshot = snapshot()
|
||||||
snapshot.deleteItems(snapshot.itemIdentifiers(inSection: .pinned))
|
snapshot.deleteItems(snapshot.itemIdentifiers(inSection: .pinned))
|
||||||
snapshot.appendItems(statuses.map { Item(id: $0.id, state: .unknown) }, toSection: .pinned)
|
snapshot.appendItems(statuses.map { Item(id: $0.id, state: .unknown, pinned: true) }, toSection: .pinned)
|
||||||
completion(.success(snapshot))
|
completion(.success(snapshot))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,19 +141,17 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
guard !statuses.isEmpty else {
|
guard !statuses.isEmpty else {
|
||||||
completion(.failure(.noOlder))
|
completion(.failure(.noOlder))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let older = pagination?.older {
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
self.older = older
|
|
||||||
}
|
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
snapshot.appendItems(statuses.map { Item(id: $0.id, state: .unknown) }, toSection: .statuses)
|
snapshot.appendItems(statuses.map { Item(id: $0.id, state: .unknown, pinned: false) }, toSection: .statuses)
|
||||||
completion(.success(snapshot))
|
completion(.success(snapshot))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,19 +170,17 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
guard !statuses.isEmpty else {
|
guard !statuses.isEmpty else {
|
||||||
completion(.failure(.noNewer))
|
completion(.failure(.allCaughtUp))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let newer = pagination?.newer {
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
self.newer = newer
|
|
||||||
}
|
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
let items = statuses.map { Item(id: $0.id, state: .unknown) }
|
let items = statuses.map { Item(id: $0.id, state: .unknown, pinned: false) }
|
||||||
if let first = snapshot.itemIdentifiers(inSection: .statuses).first {
|
if let first = snapshot.itemIdentifiers(inSection: .statuses).first {
|
||||||
snapshot.insertItems(items, beforeItem: first)
|
snapshot.insertItems(items, beforeItem: first)
|
||||||
} else {
|
} else {
|
||||||
|
@ -248,13 +246,15 @@ extension ProfileStatusesViewController {
|
||||||
struct Item: Hashable {
|
struct Item: Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let state: StatusState
|
let state: StatusState
|
||||||
|
let pinned: Bool
|
||||||
|
|
||||||
static func ==(lhs: Item, rhs: Item) -> Bool {
|
static func ==(lhs: Item, rhs: Item) -> Bool {
|
||||||
return lhs.id == rhs.id
|
return lhs.id == rhs.id && lhs.pinned == rhs.pinned
|
||||||
}
|
}
|
||||||
|
|
||||||
func hash(into hasher: inout Hasher) {
|
func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(id)
|
hasher.combine(id)
|
||||||
|
hasher.combine(pinned)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,9 +151,11 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
self.newer = pagination?.newer
|
if !statuses.isEmpty {
|
||||||
self.older = pagination?.older
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
|
}
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -183,7 +185,6 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
snapshot.appendItems([.confirmLoadMore], toSection: .footer)
|
snapshot.appendItems([.confirmLoadMore], toSection: .footer)
|
||||||
self.dataSource.apply(snapshot)
|
|
||||||
completion(.success(snapshot))
|
completion(.success(snapshot))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -195,8 +196,10 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
self.older = pagination?.older
|
if !statuses.isEmpty {
|
||||||
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
|
}
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
|
@ -220,17 +223,13 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
guard !statuses.isEmpty else {
|
guard !statuses.isEmpty else {
|
||||||
completion(.failure(.allCaughtUp))
|
completion(.failure(.allCaughtUp))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no new statuses, pagination is nil
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
// if we were to then overwrite self.newer, future refresh would fail
|
|
||||||
if let newer = pagination?.newer {
|
|
||||||
self.newer = newer
|
|
||||||
}
|
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
|
|
Loading…
Reference in New Issue