diff --git a/MatrixSDK/NotificationCenter/MXNotificationCenter.h b/MatrixSDK/NotificationCenter/MXNotificationCenter.h index 151808f462..d740d78735 100644 --- a/MatrixSDK/NotificationCenter/MXNotificationCenter.h +++ b/MatrixSDK/NotificationCenter/MXNotificationCenter.h @@ -21,9 +21,10 @@ #import "MXPushRuleConditionChecker.h" #import "MXHTTPOperation.h" - @class MXSession; +MX_ASSUME_MISSING_NULLABILITY_BEGIN + /** Posted when an existing push rule will be modified (pause, resume, delete) or when a new rule will be added. The notification object is the MXNotificationCenter instance. @@ -197,8 +198,9 @@ extern NSString *const kMXNotificationCenterAllOtherRoomMessagesRuleID; @param pushRule the push rule to update @param enable YES to enable. + @param completion an optional completion block for the operation. */ -- (void)enableRule:(MXPushRule*)pushRule isEnabled:(BOOL)enable; +- (void)enableRule:(MXPushRule*)pushRule isEnabled:(BOOL)enable completion:(nullable void (^)(NSError * _Nullable error))completion; /** Update the actions for an existing push rule. @@ -208,12 +210,14 @@ extern NSString *const kMXNotificationCenterAllOtherRoomMessagesRuleID; @param notify enable/disable notification. @param soundName the name of the sound to apply (`ring`, `default`, etc). @param highlight enable/disable highlight option. + @param completion an optional completion block for the operation. */ - (void)updatePushRuleActions:(NSString*)ruleId kind:(MXPushRuleKind)kind notify:(BOOL)notify soundName:(NSString*)soundName - highlight:(BOOL)highlight; + highlight:(BOOL)highlight + completion:(nullable void (^)(NSError * _Nullable error))completion; /** Create a content push rule, see MXNotificationCenter notifications for operation result. diff --git a/MatrixSDK/NotificationCenter/MXNotificationCenter.m b/MatrixSDK/NotificationCenter/MXNotificationCenter.m index db6119bbe1..1e80429ea7 100644 --- a/MatrixSDK/NotificationCenter/MXNotificationCenter.m +++ b/MatrixSDK/NotificationCenter/MXNotificationCenter.m @@ -397,7 +397,7 @@ - (void)removeRule:(MXPushRule*)pushRule } } -- (void)enableRule:(MXPushRule*)pushRule isEnabled:(BOOL)enable +- (void)enableRule:(MXPushRule*)pushRule isEnabled:(BOOL)enable completion:(nullable void (^)(NSError * _Nullable error))completion; { if (pushRule) { @@ -426,10 +426,15 @@ - (void)enableRule:(MXPushRule*)pushRule isEnabled:(BOOL)enable [[NSNotificationCenter defaultCenter] postNotificationName:kMXNotificationCenterDidUpdateRules object:self userInfo:nil]; + if (completion) { + completion(nil); + } } failure:^(NSError *error) { - [[NSNotificationCenter defaultCenter] postNotificationName:kMXNotificationCenterDidFailRulesUpdate object:self userInfo:@{kMXNotificationCenterErrorKey:error}]; + if (completion) { + completion(error); + } }]; } } @@ -439,6 +444,7 @@ - (void)updatePushRuleActions:(NSString*)ruleId notify:(BOOL)notify soundName:(NSString*)soundName highlight:(BOOL)highlight + completion:(nullable void (^)(NSError * _Nullable error))completion { NSArray *actions = [self encodeActionsWithNotify:notify soundName:soundName highlight:highlight]; @@ -450,12 +456,20 @@ - (void)updatePushRuleActions:(NSString*)ruleId // Refresh locally rules [self refreshRules:^{ [[NSNotificationCenter defaultCenter] postNotificationName:kMXNotificationCenterDidUpdateRules object:self userInfo:nil]; + if (completion) { + completion(nil); + } } failure:^(NSError *error) { [[NSNotificationCenter defaultCenter] postNotificationName:kMXNotificationCenterDidFailRulesUpdate object:self userInfo:@{kMXNotificationCenterErrorKey:error}]; + if (completion) { + completion(nil); + } }]; - } - failure:^(NSError *error) { + } failure:^(NSError *error) { [[NSNotificationCenter defaultCenter] postNotificationName:kMXNotificationCenterDidFailRulesUpdate object:self userInfo:@{kMXNotificationCenterErrorKey:error}]; + if (completion) { + completion(error); + } }]; } diff --git a/changelog.d/pr-1702.change b/changelog.d/pr-1702.change new file mode 100644 index 0000000000..3c30aefc4c --- /dev/null +++ b/changelog.d/pr-1702.change @@ -0,0 +1 @@ +Notifications: add completion blocks in the API.