-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTweak.xm
177 lines (152 loc) · 6.05 KB
/
Tweak.xm
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#import "Tweak.h"
dispatch_queue_t highProtityQueue() {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
return queue;
}
%group Tweak
%hook SBDashBoardNotificationDispatcher
- (void)postNotificationRequest:(NCNotificationRequest *)request forCoalescedNotification:(id)arg2 {
if ([[request.content.header lowercaseString] containsString:@"whatsapp"]) {
NSString *__block contactImagePath;
UIImage *__block contactImage;
dispatch_async(dispatch_get_main_queue(),^{
dispatch_sync(highProtityQueue(),^{
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];
NSEnumerator *files = [[fileManager contentsOfDirectoryAtPath:picturesPath error:nil] reverseObjectEnumerator];
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) {
contactImagePath = [NSString stringWithFormat:@"%@/%@", picturesPath, profilePicture];
contactImage = [UIImage imageWithContentsOfFile:contactImagePath];
// here it is
contactImage = [self imageWithImage:contactImage convertToSize:CGSizeMake(25, 25)];
NSArray *newIconsArray = [NSArray arrayWithObject:contactImage];
MSHookIvar<NSArray *>(request.content, "_icons") = newIconsArray;
break;
}
}
}
});
%orig;
});
} else {
%orig;
}
}
%new
- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
UIImage *imageRender = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
// creating a cicrle path
UIBezierPath *bPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.height, size.width)];
[bPath addClip];
// loading the image in the given size within the circle path
[image drawInRect:CGRectMake(0, 0, size.height, size.width)];
}];
renderer = nil;
return imageRender;
}
%end
%hook CSNotificationDispatcher
- (void)postNotificationRequest:(NCNotificationRequest *)request {
if ([[request.content.header lowercaseString] containsString:@"whatsapp"]) {
NSString *__block contactImagePath;
UIImage *__block contactImage;
dispatch_async(dispatch_get_main_queue(),^{
dispatch_sync(highProtityQueue(),^{
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];
NSEnumerator *files = [[fileManager contentsOfDirectoryAtPath:picturesPath error:nil] reverseObjectEnumerator];
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) {
contactImagePath = [NSString stringWithFormat:@"%@/%@", picturesPath, profilePicture];
contactImage = [UIImage imageWithContentsOfFile:contactImagePath];
// here it is
contactImage = [self imageWithImage:contactImage convertToSize:CGSizeMake(25, 25)];
NSArray *newIconsArray = [NSArray arrayWithObject:contactImage];
MSHookIvar<NSArray *>(request.content, "_icons") = newIconsArray;
break;
}
}
}
});
%orig;
});
} else {
%orig;
}
}
%new
- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
UIImage *imageRender = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
// creating a cicrle path
UIBezierPath *bPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.height, size.width)];
[bPath addClip];
// loading the image in the given size within the circle path
[image drawInRect:CGRectMake(0, 0, size.height, size.width)];
}];
renderer = nil;
return imageRender;
}
%end
// SnowBoard compatibility fix
%hook NCNotificationContent
-(void)setIcons:(NSArray *)arg1 {
self.icons = arg1;
}
-(NSArray *)icons {
return MSHookIvar<NSArray *>(self, "_icons");
}
%end
%end
static void loadPrefs() {
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.miwix.seeyaprefs.plist"];
if ( [prefs objectForKey:@"TweakisEnabled"] ? [[prefs objectForKey:@"TweakisEnabled"] boolValue] : YES ) {
%init(Tweak);
}
}
%ctor {
loadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("com.miwix.seeyaprefs/settingschanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}