Skip to content

Commit

Permalink
Merge pull request #17363 from wordpress-mobile/feature/enable-follow…
Browse files Browse the repository at this point in the history
…-conversation

Reader Comments: Follow conversation via notifications
  • Loading branch information
dvdchr authored Oct 27, 2021
2 parents 7d7c8b9 + 67e953e commit 42881bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
18.6
-----
* [**] Comments: Users can now follow conversation via notifications, in addition to emails. [#17363]
* [**] Block editor: Block inserter indicates newly available block types [https://github.com/wordpress-mobile/gutenberg-mobile/pull/4047]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum FeatureFlag: Int, CaseIterable, OverrideableFlag {
case .domains:
return BuildConfiguration.current == .localDeveloper
case .followConversationViaNotifications:
return false
return true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1401,34 +1401,31 @@ - (void)handleFollowConversationButtonTapped
- (void)handleNotificationsButtonTappedWithUndo:(BOOL)canUndo completion:(void (^ _Nullable)(BOOL))completion
{
BOOL desiredState = !self.post.receivesCommentNotifications;

NSString *successTitle = desiredState
? NSLocalizedString(@"In-app notifications enabled", @"The app successfully enabled notifications for the subscription")
: NSLocalizedString(@"In-app notifications disabled", @"The app successfully disabled notifications for the subscription");

NSString *failureTitle = desiredState
? NSLocalizedString(@"Could not enable notifications", @"The app failed to enable notifications for the subscription")
: NSLocalizedString(@"Could not disable notifications", @"The app failed to disable notifications for the subscription");
PostSubscriptionAction action = desiredState ? PostSubscriptionActionEnableNotification : PostSubscriptionActionDisableNotification;

__weak __typeof(self) weakSelf = self;
NSString* (^noticeTitle)(BOOL) = ^NSString* (BOOL success) {
return [weakSelf noticeTitleForAction:action success:success];
};

[self.followCommentsService toggleNotificationSettings:desiredState success:^{
if (completion) {
completion(YES);
}

if (!canUndo) {
[weakSelf displayNoticeWithTitle:successTitle message:nil];
[weakSelf displayNoticeWithTitle:noticeTitle(YES) message:nil];
return;
}

// show the undo notice with action button.
NSString *undoActionTitle = NSLocalizedString(@"Undo", @"Button title. Reverts the previous notification operation");
[weakSelf displayActionableNoticeWithTitle:successTitle message:nil actionTitle:undoActionTitle actionHandler:^(BOOL accepted) {
[weakSelf displayActionableNoticeWithTitle:noticeTitle(YES) message:nil actionTitle:undoActionTitle actionHandler:^(BOOL accepted) {
[weakSelf handleNotificationsButtonTappedWithUndo:NO completion:nil];
}];

} failure:^(NSError * _Nullable error) {
[weakSelf displayNoticeWithTitle:failureTitle message:nil];
[weakSelf displayNoticeWithTitle:noticeTitle(NO) message:nil];
if (completion) {
completion(NO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,26 @@ import Foundation
let bottomSheet = BottomSheetViewController(childViewController: sheetViewController)
bottomSheet.show(from: self, sourceBarButtonItem: sourceBarButtonItem)
}

// MARK: Post Subscriptions

/// Enumerates the kind of actions available in relation to post subscriptions.
/// TODO: Add `followConversation` and `unfollowConversation` once the "Follow Conversation" feature flag is removed.
@objc enum PostSubscriptionAction: Int {
case enableNotification
case disableNotification
}

func noticeTitle(forAction action: PostSubscriptionAction, success: Bool) -> String {
switch (action, success) {
case (.enableNotification, true):
return NSLocalizedString("In-app notifications enabled", comment: "The app successfully enabled notifications for the subscription")
case (.enableNotification, false):
return NSLocalizedString("Could not enable notifications", comment: "The app failed to enable notifications for the subscription")
case (.disableNotification, true):
return NSLocalizedString("In-app notifications disabled", comment: "The app successfully disabled notifications for the subscription")
case (.disableNotification, false):
return NSLocalizedString("Could not disable notifications", comment: "The app failed to disable notifications for the subscription")
}
}
}

0 comments on commit 42881bf

Please sign in to comment.