Skip to content

Commit

Permalink
Merge pull request #1702 from matrix-org/alfogrillo/sync_polls_rules
Browse files Browse the repository at this point in the history
Sync polls rules (PSG-77, PSG-1097)
  • Loading branch information
alfogrillo authored Jan 31, 2023
2 parents d772603 + 0fe0d74 commit 9e36625
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
10 changes: 7 additions & 3 deletions MatrixSDK/NotificationCenter/MXNotificationCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
22 changes: 18 additions & 4 deletions MatrixSDK/NotificationCenter/MXNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}];
}
}
Expand All @@ -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];
Expand All @@ -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);
}
}];
}

Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-1702.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Notifications: add completion blocks in the API.

0 comments on commit 9e36625

Please sign in to comment.