| 1 |
// SPDX-FileCopyrightText: 2021 Nheko Contributors |
| 2 |
// SPDX-FileCopyrightText: 2022 Nheko Contributors |
| 3 |
// |
| 4 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
#import "notifications/MacNotificationDelegate.h" |
| 7 |
|
| 8 |
#include <QString> |
| 9 |
|
| 10 |
#include "ChatPage.h" |
| 11 |
|
| 12 |
@implementation MacNotificationDelegate |
| 13 |
|
| 14 |
- (id)initWithProxy: (std::unique_ptr<NotificationManagerProxy>&&)proxy |
| 15 |
{ |
| 16 |
if(self = [super init]) { |
| 17 |
mProxy = std::move(proxy); |
| 18 |
} |
| 19 |
|
| 20 |
return self; |
| 21 |
} |
| 22 |
|
| 23 |
- (void)userNotificationCenter:(UNUserNotificationCenter*)center |
| 24 |
didReceiveNotificationResponse:(UNNotificationResponse*)response |
| 25 |
withCompletionHandler:(void (^)())completionHandler |
| 26 |
{ |
| 27 |
if ([response.actionIdentifier isEqualToString:@"ReplyAction"]) { |
| 28 |
if ([response respondsToSelector:@selector(userText)]) { |
| 29 |
UNTextInputNotificationResponse* textResponse = (UNTextInputNotificationResponse*)response; |
| 30 |
NSString* textValue = [textResponse userText]; |
| 31 |
NSString* eventId = [[[textResponse notification] request] identifier]; |
| 32 |
NSString* roomId = [[[[textResponse notification] request] content] threadIdentifier]; |
| 33 |
mProxy->notificationReplied(QString::fromNSString(roomId), QString::fromNSString(eventId), QString::fromNSString(textValue)); |
| 34 |
} |
| 35 |
} |
| 36 |
completionHandler(); |
| 37 |
} |
| 38 |
|
| 39 |
- (void)userNotificationCenter:(UNUserNotificationCenter*)center |
| 40 |
willPresentNotification:(UNNotification*)notification |
| 41 |
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler |
| 42 |
{ |
| 43 |
|
| 44 |
completionHandler(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound); |
| 45 |
} |
| 46 |
|
| 47 |
@end |