Fix bugs with reblogged statuses

Including: Attachments not showing up, 3d touch peek/pop not working,
favorite/reblog not working
This commit is contained in:
Shadowfacts 2018-10-30 22:07:54 -04:00
parent 7eb377ec6b
commit aaddae1ecb
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 13 additions and 10 deletions

View File

@ -27,6 +27,7 @@ class MastodonCache {
statuses[id] = status statuses[id] = status
add(account: status.account) add(account: status.account)
if let reblog = status.reblog { if let reblog = status.reblog {
add(status: reblog)
add(account: reblog.account) add(account: reblog.account)
} }
} }

View File

@ -32,6 +32,7 @@ class StatusTableViewCell: UITableViewCell, PreferencesAdaptive {
var statusID: String! var statusID: String!
var accountID: String! var accountID: String!
var reblogStatusID: String?
var rebloggerID: String? var rebloggerID: String?
var favorited: Bool = false { var favorited: Bool = false {
@ -74,21 +75,22 @@ class StatusTableViewCell: UITableViewCell, PreferencesAdaptive {
} }
func updateUI(for statusID: String) { func updateUI(for statusID: String) {
self.statusID = statusID guard var status = MastodonCache.status(for: statusID) else { fatalError("Missing cached status \(statusID)") }
guard let status = MastodonCache.status(for: statusID) else { fatalError("Missing cached status \(statusID)") }
let account: Account if let reblogID = status.reblog?.id,
if let reblog = status.reblog { let reblog = MastodonCache.status(for: reblogID) {
account = reblog.account reblogStatusID = statusID
rebloggerID = status.account.id rebloggerID = status.account.id
status = reblog
reblogLabel.isHidden = false reblogLabel.isHidden = false
} else { } else {
account = status.account reblogStatusID = nil
reblogLabel.isHidden = true
rebloggerID = nil rebloggerID = nil
reblogLabel.isHidden = true
} }
let account = status.account
self.accountID = account.id self.accountID = account.id
self.statusID = status.id
updateUIForPreferences() updateUIForPreferences()
@ -292,7 +294,7 @@ extension StatusTableViewCell: TableViewSwipeActionProvider {
} }
completion(true) completion(true)
MastodonCache.add(status: status) MastodonCache.add(status: status)
self.updateUI(for: self.statusID) self.updateUI(for: self.reblogStatusID ?? self.statusID)
} }
}) })
} }
@ -320,7 +322,7 @@ extension StatusTableViewCell: TableViewSwipeActionProvider {
} }
completion(true) completion(true)
MastodonCache.add(status: status) MastodonCache.add(status: status)
self.updateUI(for: self.statusID) self.updateUI(for: self.reblogStatusID ?? self.statusID)
} }
}) })
} }