|
|
@ -69,7 +69,7 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle |
|
|
|
|
|
|
|
fetchTimeline { error in |
|
|
|
if error != nil { |
|
|
|
print("\(String(describing: error))") |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -133,7 +133,7 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle |
|
|
|
@objc func fetch() { |
|
|
|
fetchTimeline { error in |
|
|
|
if error != nil { |
|
|
|
print("\(String(describing: error))") |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -173,10 +173,16 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle |
|
|
|
} |
|
|
|
|
|
|
|
DispatchQueue.main.async { |
|
|
|
var newStatusCount = 0 |
|
|
|
|
|
|
|
for (index, status) in data.enumerated() { |
|
|
|
if let upsertResult = MastodonDataManager.upsertStatus(status) { |
|
|
|
let status = upsertResult.object |
|
|
|
|
|
|
|
if upsertResult.new { |
|
|
|
newStatusCount = newStatusCount + 1 |
|
|
|
} |
|
|
|
|
|
|
|
if let pagination = pagination { |
|
|
|
var markers: [PaginationMarker] = status.markers ?? [] |
|
|
|
markers = Array(markers.drop { $0.context == self.currentPaginationContext }) |
|
|
@ -204,6 +210,10 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if newStatusCount > 0 { |
|
|
|
AlertManager.shared.show(message: "\(newStatusCount) new toots", category: .newStatuses) |
|
|
|
} |
|
|
|
|
|
|
|
CoreDataManager.shared.saveContext() |
|
|
|
|
|
|
|
self.loading = false |
|
|
@ -396,15 +406,21 @@ extension TimelineTableViewController: StatusViewDelegate { |
|
|
|
func favoriteTapped(status: StatusMO) { |
|
|
|
if status.favorited { |
|
|
|
MastodonAPI.unfavorite(statusID: status.id!) { error in |
|
|
|
if error != nil { |
|
|
|
print("\(String(describing: error))") |
|
|
|
guard error == nil else { |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
AlertManager.shared.show(message: "Unfavorited", category: .favorited) |
|
|
|
} |
|
|
|
} else { |
|
|
|
MastodonAPI.favorite(statusID: status.id!) { error in |
|
|
|
if error != nil { |
|
|
|
print("\(String(describing: error))") |
|
|
|
guard error == nil else { |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
AlertManager.shared.show(message: "Favorited!", category: .favorited) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -412,15 +428,21 @@ extension TimelineTableViewController: StatusViewDelegate { |
|
|
|
func reblogTapped(status: StatusMO) { |
|
|
|
if status.reblogged { |
|
|
|
MastodonAPI.unreblog(statusID: status.id!) { error in |
|
|
|
if error != nil { |
|
|
|
print("\(String(describing: error))") |
|
|
|
guard error == nil else { |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
AlertManager.shared.show(message: "Unboosted", category: .boosted) |
|
|
|
} |
|
|
|
} else { |
|
|
|
MastodonAPI.reblog(statusID: status.id!) { error in |
|
|
|
if error != nil { |
|
|
|
print("\(String(describing: error))") |
|
|
|
guard error == nil else { |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
AlertManager.shared.show(message: "Boosted!", category: .boosted) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -431,7 +453,7 @@ extension TimelineTableViewController: StatusViewDelegate { |
|
|
|
if marker.context == self.currentPaginationContext && marker.item.direction == direction { |
|
|
|
fetchTimeline(withPagination: marker.item) { error in |
|
|
|
if error != nil { |
|
|
|
print("\(String(describing: error))") |
|
|
|
AlertManager.shared.show(message: error!.localizedDescription, category: .error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|