summaryrefslogtreecommitdiffstats
path: root/src/notifications/MacNotificationDelegate.mm
blob: 9047efe3fe1462cbf97e6a2e7ee047ed44a3602e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

#import "notifications/MacNotificationDelegate.h"

#include <QString.h>

#include "ChatPage.h"

@implementation MacNotificationDelegate

- (id)initWithProxy: (std::unique_ptr<NotificationManagerProxy>&&)proxy
{
    if(self = [super init]) {
        mProxy = std::move(proxy);
    }

    return self;
}

- (void)userNotificationCenter:(UNUserNotificationCenter*)center
    didReceiveNotificationResponse:(UNNotificationResponse*)response
             withCompletionHandler:(void (^)())completionHandler
{
    if ([response.actionIdentifier isEqualToString:@"ReplyAction"]) {
        if ([response respondsToSelector:@selector(userText)]) {
            UNTextInputNotificationResponse* textResponse = (UNTextInputNotificationResponse*)response;
            NSString* textValue = [textResponse userText];
            NSString* eventId = [[[textResponse notification] request] identifier];
            NSString* roomId = [[[[textResponse notification] request] content] threadIdentifier];
            mProxy->notificationReplied(QString::fromNSString(roomId), QString::fromNSString(eventId), QString::fromNSString(textValue));
        }
    }
    completionHandler();
}

- (void)userNotificationCenter:(UNUserNotificationCenter*)center
       willPresentNotification:(UNNotification*)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{

    completionHandler(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound);
}

@end