Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader Comments: Follow conversation via notifications #17363

Merged
merged 6 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}
}