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

Sync polls rules (PSG-77, PSG-1097) #1702

Merged
merged 5 commits into from
Jan 31, 2023
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
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.