Skip to content

Commit

Permalink
Missing Push Notifications (#1696): Show a notification even if the a…
Browse files Browse the repository at this point in the history
…pp fails to sync with its hs to get all data.

Renaming
  • Loading branch information
manuroe committed Dec 29, 2017
1 parent 536c8cc commit 9e612dd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Riot/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1469,13 +1469,15 @@ - (nullable NSString *)notificationBodyForEvent:(MXEvent *)event pushRule:(MXPus
}

/**
Display limited notifications for events the app was not able to get data
Display "limited" notifications for events the app was not able to get data
(because of /sync failure).
In this situation, we are only able to display "You received a message in %@".
@param mxSession the matrix session where the /sync failed.
@param events the list of events id we did not get data.
*/
- (void)handleLocalNotificationsForFailedSync:(MXSession*)mxSession events:(NSArray<NSString *> *)events
- (void)handleLimitedLocalNotifications:(MXSession*)mxSession events:(NSArray<NSString *> *)events
{
NSString *userId = mxSession.matrixRestClient.credentials.userId;

Expand Down Expand Up @@ -1518,7 +1520,7 @@ - (void)handleLocalNotificationsForFailedSync:(MXSession*)mxSession events:(NSAr

UILocalNotification *localNotificationForFailedSync = [[UILocalNotification alloc] init];
localNotificationForFailedSync.userInfo = userInfo;
localNotificationForFailedSync.alertBody = [self notificationBodyForFailedSyncEvent:eventId inMatrixSession:mxSession];
localNotificationForFailedSync.alertBody = [self limitedNotificationBodyForEvent:eventId inMatrixSession:mxSession];

NSLog(@"[AppDelegate][Push] handleLocalNotificationsForFailedSync: Display notification for event %@", eventId);
[[UIApplication sharedApplication] scheduleLocalNotification:localNotificationForFailedSync];
Expand All @@ -1532,8 +1534,7 @@ - (void)handleLocalNotificationsForFailedSync:(MXSession*)mxSession events:(NSAr
@param mxSession the matrix session where the /sync failed.
@return the string to display in the local notification.
*/
- (nullable NSString *)limited otificationBodyForEvent:(MXEvent *)event pushRule:(MXPushRule*)rule inAccount:(MXKAccount*)account
- (nullable NSString *)notificationBodyForFailedSyncEvent:(NSString *)eventId inMatrixSession:(MXSession*)mxSession
- (nullable NSString *)limitedNotificationBodyForEvent:(NSString *)eventId inMatrixSession:(MXSession*)mxSession
{
NSString *notificationBody;

Expand Down Expand Up @@ -2139,7 +2140,7 @@ - (void)initMatrixSessions
NSLog(@"[AppDelegate][Push] initial sync failed with %tu pending incoming pushes", self.incomingPushEventIds[@(mxSession.hash)].count);

// Trigger local notifications when the sync with HS fails
[self handleLocalNotificationsForFailedSync:mxSession events:self.incomingPushEventIds[@(mxSession.hash)]];
[self handleLimitedLocalNotifications:mxSession events:self.incomingPushEventIds[@(mxSession.hash)]];

// Update app icon badge number
[self refreshApplicationIconBadgeNumber];
Expand Down

0 comments on commit 9e612dd

Please sign in to comment.