-
Notifications
You must be signed in to change notification settings - Fork 497
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
Add support for in-app notifications. #6341
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,8 +195,6 @@ @interface LegacyAppDelegate () <GDPRConsentViewControllerDelegate, KeyVerificat | |
UIView *launchAnimationContainerView; | ||
} | ||
|
||
@property (strong, nonatomic) UIAlertController *mxInAppNotification; | ||
|
||
@property (strong, nonatomic) UIAlertController *logoutConfirmation; | ||
|
||
@property (weak, nonatomic) UIAlertController *gdprConsentNotGivenAlertController; | ||
|
@@ -587,13 +585,6 @@ - (void)applicationDidEnterBackground:(UIApplication *)application | |
// Remove expired URL previews from the cache | ||
[URLPreviewService.shared removeExpiredCacheData]; | ||
|
||
// Hide potential notification | ||
if (self.mxInAppNotification) | ||
{ | ||
[self.mxInAppNotification dismissViewControllerAnimated:NO completion:nil]; | ||
self.mxInAppNotification = nil; | ||
} | ||
|
||
// Discard any process on pending universal link | ||
[self resetPendingUniversalLink]; | ||
|
||
|
@@ -1820,18 +1811,6 @@ - (void)initMatrixSessions | |
// start the call service | ||
[self.callPresenter start]; | ||
|
||
// Look for the account related to this session. | ||
NSArray *mxAccounts = [MXKAccountManager sharedManager].activeAccounts; | ||
for (MXKAccount *account in mxAccounts) | ||
{ | ||
if (account.mxSession == mxSession) | ||
{ | ||
// Enable inApp notifications (if they are allowed for this account). | ||
[self enableInAppNotificationsForAccount:account]; | ||
break; | ||
} | ||
} | ||
|
||
[self.configuration setupSettingsWhenLoadedFor:mxSession]; | ||
|
||
// Register to user new device sign in notification | ||
|
@@ -1888,9 +1867,6 @@ - (void)initMatrixSessions | |
// Set up push notifications | ||
[self.pushNotificationService registerUserNotificationSettings]; | ||
} | ||
|
||
// Observe inApp notifications toggle change | ||
[account addObserver:self forKeyPath:@"enableInAppNotifications" options:0 context:nil]; | ||
} | ||
|
||
[self.delegate legacyAppDelegate:self didAddAccount:account]; | ||
|
@@ -1901,10 +1877,6 @@ - (void)initMatrixSessions | |
|
||
// Remove inApp notifications toggle change | ||
MXKAccount *account = notif.object; | ||
if (!account.isSoftLogout) | ||
{ | ||
[account removeObserver:self forKeyPath:@"enableInAppNotifications"]; | ||
} | ||
|
||
// Clear Modular data | ||
[[WidgetManager sharedManager] deleteDataForUser:account.mxCredentials.userId]; | ||
|
@@ -1984,12 +1956,6 @@ - (void)initMatrixSessions | |
|
||
// Set up push notifications | ||
[self.pushNotificationService registerUserNotificationSettings]; | ||
|
||
// Observe inApp notifications toggle change for each account | ||
for (MXKAccount *account in mxAccounts) | ||
{ | ||
[account addObserver:self forKeyPath:@"enableInAppNotifications" options:0 context:nil]; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -2256,10 +2222,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N | |
// Flush and restore Matrix data | ||
[self reloadMatrixSessions:NO]; | ||
} | ||
else if ([@"enableInAppNotifications" isEqualToString:keyPath] && [object isKindOfClass:[MXKAccount class]]) | ||
{ | ||
[self enableInAppNotificationsForAccount:(MXKAccount*)object]; | ||
} | ||
else if (object == [MXKAppSettings standardAppSettings] && [keyPath isEqualToString:@"enableCallKit"]) | ||
{ | ||
BOOL isCallKitEnabled = [MXKAppSettings standardAppSettings].isCallKitEnabled; | ||
|
@@ -2656,100 +2618,6 @@ - (UIViewController*)presentedViewController | |
|
||
#pragma mark - Matrix Accounts handling | ||
|
||
- (void)enableInAppNotificationsForAccount:(MXKAccount*)account | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice chunk of code gone 🎉 |
||
{ | ||
if (account.mxSession) | ||
{ | ||
if (account.enableInAppNotifications) | ||
{ | ||
// Build MXEvent -> NSString formatter | ||
EventFormatter *eventFormatter = [[EventFormatter alloc] initWithMatrixSession:account.mxSession]; | ||
eventFormatter.isForSubtitle = YES; | ||
|
||
[account listenToNotifications:^(MXEvent *event, MXRoomState *roomState, MXPushRule *rule) { | ||
|
||
// Check conditions to display this notification | ||
if (![self.visibleRoomId isEqualToString:event.roomId] | ||
&& !self.window.rootViewController.presentedViewController) | ||
{ | ||
MXKEventFormatterError error; | ||
NSString* messageText = [eventFormatter stringFromEvent:event | ||
withRoomState:roomState | ||
andLatestRoomState:nil | ||
error:&error]; | ||
if (messageText.length && (error == MXKEventFormatterErrorNone)) | ||
{ | ||
// Removing existing notification (if any) | ||
if (self.mxInAppNotification) | ||
{ | ||
[self.mxInAppNotification dismissViewControllerAnimated:NO completion:nil]; | ||
} | ||
|
||
// Check whether tweak is required | ||
for (MXPushRuleAction *ruleAction in rule.actions) | ||
{ | ||
if (ruleAction.actionType == MXPushRuleActionTypeSetTweak) | ||
{ | ||
if ([[ruleAction.parameters valueForKey:@"set_tweak"] isEqualToString:@"sound"]) | ||
{ | ||
// Play message sound | ||
AudioServicesPlaySystemSound(self->_messageSound); | ||
} | ||
} | ||
} | ||
|
||
MXRoomSummary *roomSummary = [account.mxSession roomSummaryWithRoomId:event.roomId]; | ||
|
||
__weak typeof(self) weakSelf = self; | ||
self.mxInAppNotification = [UIAlertController alertControllerWithTitle:roomSummary.displayname | ||
message:messageText | ||
preferredStyle:UIAlertControllerStyleAlert]; | ||
|
||
[self.mxInAppNotification addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] | ||
style:UIAlertActionStyleCancel | ||
handler:^(UIAlertAction * action) { | ||
|
||
if (weakSelf) | ||
{ | ||
typeof(self) self = weakSelf; | ||
self.mxInAppNotification = nil; | ||
[account updateNotificationListenerForRoomId:event.roomId ignore:YES]; | ||
} | ||
|
||
}]]; | ||
|
||
[self.mxInAppNotification addAction:[UIAlertAction actionWithTitle:[VectorL10n view] | ||
style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction * action) { | ||
|
||
if (weakSelf) | ||
{ | ||
typeof(self) self = weakSelf; | ||
self.mxInAppNotification = nil; | ||
// Show the room | ||
[self showRoom:event.roomId andEventId:nil withMatrixSession:account.mxSession]; | ||
} | ||
|
||
}]]; | ||
|
||
[self.window.rootViewController presentViewController:self.mxInAppNotification animated:YES completion:nil]; | ||
} | ||
} | ||
}]; | ||
} | ||
else | ||
{ | ||
[account removeNotificationListener]; | ||
} | ||
} | ||
|
||
if (self.mxInAppNotification) | ||
{ | ||
[self.mxInAppNotification dismissViewControllerAnimated:NO completion:nil]; | ||
self.mxInAppNotification = nil; | ||
} | ||
} | ||
|
||
- (void)selectMatrixAccount:(void (^)(MXKAccount *selectedAccount))onSelection | ||
{ | ||
NSArray *mxAccounts = [MXKAccountManager sharedManager].activeAccounts; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Notifications: Add a setting for in-app notifications and use the value with existing functionality in PushNotificationService. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Alert option was deprecated in iOS 14. I'm not sure what this means for the
Constants.userInfoKeyPresentNotificationOnForeground
check: one change could be to include it in notification centre too if that is set, but that didn't seem worthwhile to me.