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

Don't deliver local notifications when user status is DND #966

Merged
merged 1 commit into from
Nov 2, 2022
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
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