Skip to content

Commit

Permalink
Don't deliver local notifications when user status is DND
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Oct 31, 2022
1 parent 541be93 commit 22431b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion NextcloudTalk/NCAPIController.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ typedef void (^SetUserStatusCompletionBlock)(NSError *error);

typedef void (^GetServerCapabilitiesCompletionBlock)(NSDictionary *serverCapabilities, NSError *error);
typedef void (^GetServerNotificationCompletionBlock)(NSDictionary *notification, NSError *error, NSInteger statusCode);
typedef void (^GetServerNotificationsCompletionBlock)(NSArray *notifications, NSString *ETag, NSError *error);
typedef void (^GetServerNotificationsCompletionBlock)(NSArray *notifications, NSString *ETag, NSString *userStatus, NSError *error);

typedef void (^SubscribeToNextcloudServerCompletionBlock)(NSDictionary *responseDict, NSError *error);
typedef void (^UnsubscribeToNextcloudServerCompletionBlock)(NSError *error);
Expand Down
4 changes: 2 additions & 2 deletions NextcloudTalk/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2417,11 +2417,11 @@ - (NSURLSessionDataTask *)getServerNotificationsForAccount:(TalkAccount *)accoun
NSDictionary *headers = [self getResponseHeaders:response];

if (block) {
block(notifications, [headers objectForKey:@"ETag"], nil);
block(notifications, [headers objectForKey:@"ETag"], [headers objectForKey:@"x-nextcloud-user-status"], nil);
}
} else {
if (block) {
block(nil, nil, error);
block(nil, nil, nil, error);
}
}
}];
Expand Down
12 changes: 10 additions & 2 deletions NextcloudTalk/NCNotificationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import "NCRoomsManager.h"
#import "NCSettingsController.h"
#import "NCUserInterfaceController.h"
#import "NCUserStatus.h"

NSString * const NCNotificationControllerWillPresentNotification = @"NCNotificationControllerWillPresentNotification";
NSString * const NCLocalNotificationJoinChatNotification = @"NCLocalNotificationJoinChatNotification";
Expand Down Expand Up @@ -295,12 +296,15 @@ - (void)checkForNewNotificationsWithCompletionBlock:(CheckForNewNotificationsCom

dispatch_group_enter(notificationsGroup);

[[NCAPIController sharedInstance] getServerNotificationsForAccount:account withLastETag:account.lastNotificationETag withCompletionBlock:^(NSArray *notifications, NSString* ETag, NSError *error) {
[[NCAPIController sharedInstance] getServerNotificationsForAccount:account withLastETag:account.lastNotificationETag withCompletionBlock:^(NSArray *notifications, NSString* ETag, NSString *userStatus, NSError *error) {
if (error) {
dispatch_group_leave(notificationsGroup);
return;
}

// Don't show notifications if the user has status "do not disturb"
BOOL suppressNotifications = (serverCapabilities.userStatus && [userStatus isEqualToString:kUserStatusDND]);

NSInteger lastNotificationId = 0;
NSMutableArray *activeServerNotificationsIds = [NSMutableArray new];

Expand All @@ -318,7 +322,11 @@ - (void)checkForNewNotificationsWithCompletionBlock:(CheckForNewNotificationsCom
lastNotificationId = serverNotification.notificationId;
}

if (account.lastNotificationId != 0 && serverNotification.notificationId > account.lastNotificationId && serverNotification.notificationType != kNCNotificationTypeChat) {
if (suppressNotifications || serverNotification.notificationType != kNCNotificationTypeChat) {
continue;
}

if (account.lastNotificationId != 0 && serverNotification.notificationId > account.lastNotificationId) {
// Don't show notifications if this is the first time we retrieve notifications for this account
// Otherwise after adding a new account all unread notifications from the server would be shown

Expand Down

0 comments on commit 22431b4

Please sign in to comment.