diff --git a/WhatsAppContactPhotoProvider.m b/WhatsAppContactPhotoProvider.m index b4f33ed..8af489e 100755 --- a/WhatsAppContactPhotoProvider.m +++ b/WhatsAppContactPhotoProvider.m @@ -1,32 +1,43 @@ +#import "FolderFinder.h" #import "WhatsAppContactPhotoProvider.h" @interface NCNotificationRequest -(NSString *)threadIdentifier; @end -@interface FBApplicationInfo - -(NSURL *)dataContainerURL; -@end - -@interface LSApplicationProxy - +(id)applicationProxyForIdentifier:(id)arg1; -@end - @implementation WhatsAppContactPhotoProvider - (DDNotificationContactPhotoPromiseOffer *)contactPhotoPromiseOfferForNotification:(DDUserNotification *)notification { - FBApplicationInfo *appinfo = [LSApplicationProxy applicationProxyForIdentifier:@"net.whatsapp.WhatsApp"]; NCNotificationRequest *request = [notification request]; NSString *threadId = [request threadIdentifier]; - NSString *phoneNumber = [threadId componentsSeparatedByString:@"@"][0]; - NSMutableString *imageURL = [NSMutableString new]; - NSString *containerURL = [[appinfo dataContainerURL] absoluteString]; + NSString *chatId = [threadId componentsSeparatedByString:@"@"][0]; + NSString* containerURL = [FolderFinder findSharedFolder:@"group.net.whatsapp.WhatsApp.shared"]; + containerURL = [NSString stringWithFormat:@"%@/Media/Profile", containerURL]; + + NSFileManager *fileManager = [[NSFileManager alloc] init]; + NSDirectoryEnumerator *files = [fileManager enumeratorAtPath:containerURL]; + + NSString *file; + NSString *profilePicture; + + while ((file = [files nextObject])) { + NSArray *parts = [file componentsSeparatedByString:@"-"]; + + // DMs + if ([parts count] == 2){ + if ([chatId isEqualToString:parts[0]]){ + profilePicture = file; + } + } - [imageURL appendString:containerURL]; - [imageURL appendString:@"/Library/Caches/spotlight-profile-v2/"]; - [imageURL appendString:phoneNumber]; - [imageURL appendString:@"@s-whatsapp-net.png"]; - [imageURL setString:[imageURL stringByReplacingOccurrencesOfString:@"file://" withString:@""]]; + // Groups + if ([parts count] == 3){ + if ([chatId isEqualToString:[NSString stringWithFormat:@"%@-%@", parts[0], parts[1]]]){ + profilePicture = file; + } + } + } + NSString *imageURL = [NSString stringWithFormat:@"%@/%@", containerURL, profilePicture]; UIImage *image = [UIImage imageWithContentsOfFile:imageURL]; return [NSClassFromString(@"DDNotificationContactPhotoPromiseOffer") offerInstantlyResolvingPromiseWithPhotoIdentifier:imageURL image:image];