Skip to content

Commit

Permalink
Convert unowned to weak in ReaderCommentsFollowPresenter (#22712)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdchr authored Feb 28, 2024
2 parents aab11ac + a8f85c9 commit 87a3999
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ReaderCommentsFollowPresenter: NSObject {

private let post: ReaderPost
private weak var delegate: ReaderCommentsFollowPresenterDelegate?
private unowned let presentingViewController: UIViewController
private weak var presentingViewController: UIViewController?
private let followCommentsService: FollowCommentsService?

// MARK: - Initialization
Expand Down Expand Up @@ -50,7 +50,7 @@ class ReaderCommentsFollowPresenter: NSObject {
DispatchQueue.main.async {
generator.notificationOccurred(.error)
let noticeTitle = newIsSubscribed ? Messages.followFail : Messages.unfollowFail
self?.presentingViewController.displayNotice(title: noticeTitle)
self?.presentingViewController?.displayNotice(title: noticeTitle)
self?.informDelegateFollowComplete(success: false)
}
return
Expand All @@ -62,7 +62,7 @@ class ReaderCommentsFollowPresenter: NSObject {

guard newIsSubscribed else {
let noticeTitle = newIsSubscribed ? Messages.followSuccess : Messages.unfollowSuccess
self?.presentingViewController.displayNotice(title: noticeTitle)
self?.presentingViewController?.displayNotice(title: noticeTitle)
return
}

Expand All @@ -78,7 +78,7 @@ class ReaderCommentsFollowPresenter: NSObject {
DispatchQueue.main.async {
generator.notificationOccurred(.error)
let noticeTitle = newIsSubscribed ? Messages.subscribeFail : Messages.unsubscribeFail
self?.presentingViewController.displayNotice(title: noticeTitle)
self?.presentingViewController?.displayNotice(title: noticeTitle)
self?.informDelegateFollowComplete(success: false)
}
}
Expand Down Expand Up @@ -130,11 +130,11 @@ private extension ReaderCommentsFollowPresenter {

guard canUndo else {
let title = ReaderHelpers.noticeTitle(forAction: action, success: true)
self.presentingViewController.displayNotice(title: title)
self.presentingViewController?.displayNotice(title: title)
return
}

self.presentingViewController.displayActionableNotice(
self.presentingViewController?.displayActionableNotice(
title: Messages.promptTitle,
message: Messages.promptMessage,
actionTitle: Messages.undoActionTitle,
Expand All @@ -144,13 +144,16 @@ private extension ReaderCommentsFollowPresenter {
}, failure: { [weak self] error in
DDLogError("Reader Comments: error toggling notification status: \(String(describing: error)))")
let title = ReaderHelpers.noticeTitle(forAction: action, success: false)
self?.presentingViewController.displayNotice(title: title)
self?.presentingViewController?.displayNotice(title: title)
completion?(false)
self?.informDelegateNotificationComplete(success: false)
})
}

func showBottomSheet(sourceView: UIView? = nil, sourceBarButtonItem: UIBarButtonItem? = nil) {
guard let presentingViewController else {
return
}
let sheetViewController = ReaderCommentsNotificationSheetViewController(isNotificationEnabled: post.receivesCommentNotifications, delegate: self)
let bottomSheet = BottomSheetViewController(childViewController: sheetViewController)
bottomSheet.show(from: presentingViewController, sourceView: sourceView, sourceBarButtonItem: sourceBarButtonItem)
Expand Down Expand Up @@ -201,6 +204,10 @@ private extension ReaderCommentsFollowPresenter {
}

func sourceForTracks() -> String {
guard let presentingViewController else {
return AnalyticsSource.unknown.description()
}

if presentingViewController is ReaderCommentsViewController {
return AnalyticsSource.comments.description()
}
Expand Down

0 comments on commit 87a3999

Please sign in to comment.