Skip to content

Commit b08f57b

Browse files
committed
Post notification when view is being dismissed instead of immediately.
1 parent 54ebfd8 commit b08f57b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ typedef NS_ENUM(NSUInteger, ReaderCommentsSource) {
3131
/// Navigates to the specified comment when the view appears
3232
@property (nonatomic, strong) NSNumber *navigateToCommentID;
3333

34+
35+
// Comment moderation support.
36+
@property (nonatomic, assign, readwrite) BOOL commentModified;
3437
@end

WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ - (void)viewDidLoad
144144
{
145145
[super viewDidLoad];
146146
self.view.backgroundColor = [UIColor murielBasicBackground];
147+
self.commentModified = NO;
147148

148149
[self checkIfLoggedIn];
149150

@@ -195,6 +196,11 @@ - (void)viewWillDisappear:(BOOL)animated
195196
{
196197
[super viewWillDisappear:animated];
197198
[self dismissNotice];
199+
200+
if (self.commentModified) {
201+
// Don't post the notification until the view is being dismissed to avoid purging cached comments prematurely.
202+
[self postCommentModifiedNotification];
203+
}
198204

199205
#pragma clang diagnostic push
200206
#pragma clang diagnostic ignored "-Wunused-result"

WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ extension NSNotification.Name {
142142
WPAnalytics.trackReader(.readerArticleCommentsOpened, properties: properties)
143143
}
144144

145+
// MARK: - Notification
146+
147+
@objc func postCommentModifiedNotification() {
148+
NotificationCenter.default.post(name: .ReaderCommentModifiedNotification, object: nil)
149+
}
150+
145151
}
146152

147153
// MARK: - Popover Presentation Delegate
@@ -223,7 +229,7 @@ private extension ReaderCommentsViewController {
223229
CommentAnalytics.trackCommentEdited(comment: comment)
224230

225231
self?.commentService.uploadComment(comment, success: {
226-
NotificationCenter.default.post(name: .ReaderCommentModifiedNotification, object: nil)
232+
self?.commentModified = true
227233

228234
// update the thread again in case the approval status changed.
229235
tableView.reloadRows(at: [indexPath], with: .automatic)
@@ -239,7 +245,7 @@ private extension ReaderCommentsViewController {
239245

240246
func moderateComment(_ comment: Comment, status: CommentStatusType, handler: WPTableViewHandler) {
241247
let successBlock: (String) -> Void = { [weak self] noticeText in
242-
NotificationCenter.default.post(name: .ReaderCommentModifiedNotification, object: nil)
248+
self?.commentModified = true
243249

244250
// Adjust the ReaderPost's comment count.
245251
if let post = self?.post, let commentCount = post.commentCount?.intValue {

0 commit comments

Comments
 (0)