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.

Fix last Giom's remark: Make sure we do not display a "limited" notif for an event with already a "full" notif.
  • Loading branch information
manuroe committed Dec 29, 2017
1 parent 8676024 commit 0cdcff9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Riot/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,9 @@ - (void)handleLocalNotificationsForAccount:(MXKAccount*)account
MXEvent *event;

// Ignore event already notified to the user
if ([self displayedLimitedLocalNotificationForEvent:eventId andUser:account.mxCredentials.userId])
if ([self displayedLocalNotificationForEvent:eventId andUser:account.mxCredentials.userId type:nil])
{
NSLog(@"[AppDelegate][Push] handleLocalNotificationsForAccount: Skip event already displayed in a failed sync notif. Event id: %@", eventId);
NSLog(@"[AppDelegate][Push] handleLocalNotificationsForAccount: Skip event already displayed in a notification. Event id: %@", eventId);
continue;
}

Expand Down Expand Up @@ -1332,6 +1332,7 @@ - (void)handleLocalNotificationsForAccount:(MXKAccount*)account
UILocalNotification *eventNotification = [[UILocalNotification alloc] init];
eventNotification.alertBody = notificationBody;
eventNotification.userInfo = @{
@"type": @"full",
@"room_id": event.roomId,
@"event_id": event.eventId,
@"user_id": account.mxCredentials.userId
Expand Down Expand Up @@ -1501,15 +1502,16 @@ - (void)handleLimitedLocalNotifications:(MXSession*)mxSession events:(NSArray<NS

for (NSString *eventId in events)
{
if ([self displayedLimitedLocalNotificationForEvent:eventId andUser:userId])
// Ignore event already notified to the user
if ([self displayedLocalNotificationForEvent:eventId andUser:userId type:nil])
{
NSLog(@"[AppDelegate][Push] handleLocalNotificationsForFailedSync: Notification for event %@ already exists", eventId);
NSLog(@"[AppDelegate][Push] handleLocalNotificationsForAccount: Skip event already displayed in a notification. Event id: %@", eventId);
continue;
}

// Build notification user info
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"failed_sync",
@"type": @"limited",
@"event_id": eventId,
@"user_id": userId
}];
Expand Down Expand Up @@ -1572,20 +1574,21 @@ - (nullable NSString *)limitedNotificationBodyForEvent:(NSString *)eventId inMat
}

/**
Return the already displayed limited notification for an event.
Return the already displayed notification for an event.
@param eventId the id of the event attached to the notification to find.
@param userId the id of the user attached to the notification to find.
@param type the type of notification. @"full" or @"limited". nil for any type.
@return the local notification if any.
*/
- (UILocalNotification*)displayedLimitedLocalNotificationForEvent:(NSString*)eventId andUser:(NSString*)userId
- (UILocalNotification*)displayedLocalNotificationForEvent:(NSString*)eventId andUser:(NSString*)userId type:(NSString*)type
{
UILocalNotification *limitedLocalNotification;
for (UILocalNotification *localNotification in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
if ([localNotification.userInfo[@"type"] isEqualToString:@"failed_sync"]
&& [localNotification.userInfo[@"event_id"] isEqualToString:eventId]
&& [localNotification.userInfo[@"user_id"] isEqualToString:userId])
if ([localNotification.userInfo[@"event_id"] isEqualToString:eventId]
&& [localNotification.userInfo[@"user_id"] isEqualToString:userId]
&& (!type || [localNotification.userInfo[@"type"] isEqualToString:type]))
{
limitedLocalNotification = localNotification;
break;
Expand Down

0 comments on commit 0cdcff9

Please sign in to comment.