Skip to content

Commit

Permalink
change profile picture source and add group chat support
Browse files Browse the repository at this point in the history
Co-Authored-By: Gil Shahar <[email protected]>
  • Loading branch information
marcoroth and gilshahar7 committed Jul 20, 2018
1 parent 4b23ed8 commit b4b53f4
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions WhatsAppContactPhotoProvider.m
Original file line number Diff line number Diff line change
@@ -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];
Expand Down

0 comments on commit b4b53f4

Please sign in to comment.