-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
WhatsAppContactPhotoProvider.m
executable file
·51 lines (42 loc) · 1.86 KB
/
WhatsAppContactPhotoProvider.m
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
51
#import "FolderFinder.h"
#import "WhatsAppContactPhotoProvider.h"
@interface NCNotificationRequest
-(NSString *)threadIdentifier;
@end
@implementation WhatsAppContactPhotoProvider
- (DDNotificationContactPhotoPromiseOffer *)contactPhotoPromiseOfferForNotification:(DDUserNotification *)notification {
NCNotificationRequest *request = [notification request];
NSString *threadId = [request threadIdentifier];
NSString *chatId = [threadId componentsSeparatedByString:@"@"][0];
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSArray *identifiers = @[@"group.net.whatsapp.WhatsApp.shared", @"group.net.whatsapp.WhatsAppSMB.shared"];
for (NSString *identifier in identifiers) {
NSString *file;
NSString *profilePicture;
NSString *containerPath = [FolderFinder findSharedFolder:identifier];
NSString *picturesPath = [NSString stringWithFormat:@"%@/Media/Profile", containerPath];
NSDirectoryEnumerator *files = [fileManager enumeratorAtPath:picturesPath];
while (file = [files nextObject]) {
NSArray *parts = [file componentsSeparatedByString:@"-"];
// DMs
if ([parts count] == 2) {
if ([chatId isEqualToString:parts[0]]){
profilePicture = file;
}
}
// Groups
if ([parts count] == 3) {
if ([chatId isEqualToString:[NSString stringWithFormat:@"%@-%@", parts[0], parts[1]]]){
profilePicture = file;
}
}
if (profilePicture) {
NSString *imagePath = [NSString stringWithFormat:@"%@/%@", picturesPath, profilePicture];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
return [NSClassFromString(@"DDNotificationContactPhotoPromiseOffer") offerInstantlyResolvingPromiseWithPhotoIdentifier:imagePath image:image];
}
}
}
return nil;
}
@end