Repository navigation
Expand file tree
/
Copy pathPusher.m
More file actions
50 lines (45 loc) · 2.13 KB
/
Copy pathPusher.m
File metadata and controls
50 lines (45 loc) · 2.13 KB
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
48
49
50
//
// Pusher.m
// Keybase
//
// Created by Michael Maxim on 5/7/18.
// Copyright © 2018 Keybase. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Pusher.h"
@import UserNotifications;
@implementation PushNotifier {
}
- (void)localNotification:(NSString*)ident msg:(NSString*)msg badgeCount:(long)badgeCount soundName:(NSString*)soundName convID:(NSString*)convID typ:(NSString*)typ {
UNMutableNotificationContent *localNotification = [UNMutableNotificationContent new];
localNotification.sound = [UNNotificationSound soundNamed:soundName];
NSNumber* badge = NULL;
if (badgeCount >= 0) {
badge = [NSNumber numberWithLong:badgeCount];
}
localNotification.badge = badge;
localNotification.body = msg;
localNotification.userInfo = @{ @"convID" : convID, @"type" : typ};
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:ident content:localNotification trigger:nil];
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"local notification failed: %@",error);
}
}];
}
- (void)displayChatNotification:(KeybaseChatNotification *)notification {
NSString* ident = [NSString stringWithFormat:@"%@:%ld", notification.convID, notification.message.id_];
NSString* msg;
if (notification.isPlaintext && [notification.message.plaintext length] != 0) {
if([ notification.message.from.keybaseUsername isEqualToString: notification.conversationName ] || [notification.conversationName length] == 0) {
msg = [NSString stringWithFormat:@"%@: %@", notification.message.from.keybaseUsername, notification.message.plaintext];
} else {
msg = [NSString stringWithFormat:@"%@ (%@): %@", notification.message.from.keybaseUsername, notification.conversationName, notification.message.plaintext];
}
} else {
msg = notification.message.serverMessage;
}
[self localNotification:ident msg:msg badgeCount:notification.badgeCount soundName:notification.soundName convID:notification.convID typ:@"chat.newmessage"];
}
@end