forked from shadowfacts/Tusker
Fix potential data races
This commit is contained in:
parent
b95819cada
commit
0a16a2e261
|
@ -91,8 +91,8 @@ class ProfileViewController: UIPageViewController {
|
||||||
addKeyCommand(MenuController.nextSubTabCommand)
|
addKeyCommand(MenuController.nextSubTabCommand)
|
||||||
|
|
||||||
accountUpdater = mastodonController.persistentContainer.accountSubject
|
accountUpdater = mastodonController.persistentContainer.accountSubject
|
||||||
.filter { [weak self] in $0 == self?.accountID }
|
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
.filter { [weak self] in $0 == self?.accountID }
|
||||||
.sink { [weak self] (_) in self?.updateAccountUI() }
|
.sink { [weak self] (_) in self?.updateAccountUI() }
|
||||||
|
|
||||||
loadAccount()
|
loadAccount()
|
||||||
|
|
|
@ -164,7 +164,9 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
||||||
let attachmentURL = attachment.url
|
let attachmentURL = attachment.url
|
||||||
attachmentRequest = ImageCache.attachments.get(attachmentURL) { [weak self] (data, _) in
|
attachmentRequest = ImageCache.attachments.get(attachmentURL) { [weak self] (data, _) in
|
||||||
guard let self = self, let data = data else { return }
|
guard let self = self, let data = data else { return }
|
||||||
|
DispatchQueue.main.async {
|
||||||
self.attachmentRequest = nil
|
self.attachmentRequest = nil
|
||||||
|
}
|
||||||
if self.attachment.url.pathExtension == "gif" {
|
if self.attachment.url.pathExtension == "gif" {
|
||||||
self.source = .gifData(attachmentURL, data)
|
self.source = .gifData(attachmentURL, data)
|
||||||
if self.autoplayGifs {
|
if self.autoplayGifs {
|
||||||
|
|
|
@ -80,14 +80,14 @@ class ProfileHeaderView: UIView {
|
||||||
cancellables = []
|
cancellables = []
|
||||||
|
|
||||||
mastodonController.persistentContainer.accountSubject
|
mastodonController.persistentContainer.accountSubject
|
||||||
.filter { [weak self] in $0 == self?.accountID }
|
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
.filter { [weak self] in $0 == self?.accountID }
|
||||||
.sink { [weak self] in self?.updateUI(for: $0) }
|
.sink { [weak self] in self?.updateUI(for: $0) }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
mastodonController.persistentContainer.relationshipSubject
|
mastodonController.persistentContainer.relationshipSubject
|
||||||
.filter { [weak self] in $0 == self?.accountID }
|
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
.filter { [weak self] in $0 == self?.accountID }
|
||||||
.sink { [weak self] (_) in self?.updateRelationship() }
|
.sink { [weak self] (_) in self?.updateRelationship() }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
@ -203,11 +203,14 @@ class ProfileHeaderView: UIView {
|
||||||
let image = image,
|
let image = image,
|
||||||
self.accountID == accountID,
|
self.accountID == accountID,
|
||||||
let transformedImage = ImageGrayscalifier.convertIfNecessary(url: avatarURL, image: image) else {
|
let transformedImage = ImageGrayscalifier.convertIfNecessary(url: avatarURL, image: image) else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.avatarRequest = nil
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.avatarRequest = nil
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
self.avatarRequest = nil
|
||||||
self.avatarImageView.image = transformedImage
|
self.avatarImageView.image = transformedImage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,11 +220,14 @@ class ProfileHeaderView: UIView {
|
||||||
let image = image,
|
let image = image,
|
||||||
self.accountID == accountID,
|
self.accountID == accountID,
|
||||||
let transformedImage = ImageGrayscalifier.convertIfNecessary(url: header, image: image) else {
|
let transformedImage = ImageGrayscalifier.convertIfNecessary(url: header, image: image) else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self?.headerRequest = nil
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.headerRequest = nil
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
self.headerRequest = nil
|
||||||
self.headerImageView.image = transformedImage
|
self.headerImageView.image = transformedImage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,8 +106,8 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider {
|
||||||
open func createObserversIfNecessary() {
|
open func createObserversIfNecessary() {
|
||||||
if statusUpdater == nil {
|
if statusUpdater == nil {
|
||||||
statusUpdater = mastodonController.persistentContainer.statusSubject
|
statusUpdater = mastodonController.persistentContainer.statusSubject
|
||||||
.filter { [unowned self] in $0 == self.statusID }
|
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
.filter { [unowned self] in $0 == self.statusID }
|
||||||
.sink { [unowned self] in
|
.sink { [unowned self] in
|
||||||
if let mastodonController = mastodonController,
|
if let mastodonController = mastodonController,
|
||||||
let status = mastodonController.persistentContainer.status(for: $0) {
|
let status = mastodonController.persistentContainer.status(for: $0) {
|
||||||
|
@ -118,8 +118,8 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider {
|
||||||
|
|
||||||
if accountUpdater == nil {
|
if accountUpdater == nil {
|
||||||
accountUpdater = mastodonController.persistentContainer.accountSubject
|
accountUpdater = mastodonController.persistentContainer.accountSubject
|
||||||
.filter { [unowned self] in $0 == self.accountID }
|
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
.filter { [unowned self] in $0 == self.accountID }
|
||||||
.sink { [unowned self] in
|
.sink { [unowned self] in
|
||||||
if let mastodonController = mastodonController,
|
if let mastodonController = mastodonController,
|
||||||
let account = mastodonController.persistentContainer.account(for: $0) {
|
let account = mastodonController.persistentContainer.account(for: $0) {
|
||||||
|
|
|
@ -59,8 +59,8 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
||||||
|
|
||||||
if rebloggerAccountUpdater == nil {
|
if rebloggerAccountUpdater == nil {
|
||||||
rebloggerAccountUpdater = mastodonController.persistentContainer.accountSubject
|
rebloggerAccountUpdater = mastodonController.persistentContainer.accountSubject
|
||||||
.filter { [unowned self] in $0 == self.rebloggerID }
|
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
.filter { [unowned self] in $0 == self.rebloggerID }
|
||||||
.sink { [unowned self] in
|
.sink { [unowned self] in
|
||||||
if let mastodonController = self.mastodonController,
|
if let mastodonController = self.mastodonController,
|
||||||
let reblogger = mastodonController.persistentContainer.account(for: $0) {
|
let reblogger = mastodonController.persistentContainer.account(for: $0) {
|
||||||
|
|
Loading…
Reference in New Issue