-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSNMessenger.xm
679 lines (512 loc) · 25.7 KB
/
SNMessenger.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
#import "Settings/SNSettingsViewController.h"
#import "SNMessenger.h"
#pragma mark - Global variables & functions
static BOOL noAds;
static BOOL showTheEyeButton;
static BOOL alwaysSendHdPhotos;
static BOOL callConfirmation;
static BOOL disableLongPressToChangeChatTheme;
static BOOL disableReadReceipts;
static NSString *disableTypingIndicator;
static BOOL hideNotifBadgesInChat;
static NSString *keyboardStateAfterEnterChat;
static BOOL canSaveFriendsStories;
static BOOL disableStoriesPreview;
static BOOL disableStorySeenReceipts;
static BOOL extendStoryVideoUploadLength;
static BOOL hideStatusBarWhenViewingStory;
static BOOL neverReplayStoryAfterReacting;
static BOOL hidePeopleTab;
static BOOL hideStoriesTab;
static BOOL hideNotesRow;
static BOOL hideSearchBar;
static BOOL hideSuggestedContactsInSearch;
static NSMutableDictionary *settings;
BOOL isDarkMode = NO;
NSBundle *tweakBundle = nil;
static NSBundle *SNMessengerBundle() {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *tweakBundlePath = [[NSBundle mainBundle] pathForResource:@"SNMessenger" ofType:@"bundle"];
if (tweakBundlePath)
bundle = [NSBundle bundleWithPath:tweakBundlePath];
else
bundle = [NSBundle bundleWithPath:ROOT_PATH_NS(@"/Library/Application Support/SNMessenger.bundle")];
});
return bundle;
}
static void reloadPrefs() {
settings = getCurrentSettings();
noAds = [[settings objectForKey:@"noAds"] ?: @(YES) boolValue];
showTheEyeButton = [[settings objectForKey:@"showTheEyeButton"] ?: @(YES) boolValue];
alwaysSendHdPhotos = [[settings objectForKey:@"alwaysSendHdPhotos"] ?: @(YES) boolValue];
callConfirmation = [[settings objectForKey:@"callConfirmation"] ?: @(YES) boolValue];
disableReadReceipts = [[settings objectForKey:@"disableReadReceipts"] ?: @(YES) boolValue];
disableLongPressToChangeChatTheme = [[settings objectForKey:@"disableLongPressToChangeTheme"] ?: @(NO) boolValue];
disableTypingIndicator = [settings objectForKey:@"disableTypingIndicator"] ?: @"NOWHERE";
hideNotifBadgesInChat = [[settings objectForKey:@"hideNotifBadgesInChat"] ?: @(NO) boolValue];
keyboardStateAfterEnterChat = [settings objectForKey:@"keyboardStateAfterEnterChat"] ?: @"ADAPTIVE";
canSaveFriendsStories = [[settings objectForKey:@"canSaveFriendsStories"] ?: @(YES) boolValue];
disableStoriesPreview = [[settings objectForKey:@"disableStoriesPreview"] ?: @(NO) boolValue];
disableStorySeenReceipts = [[settings objectForKey:@"disableStorySeenReceipts"] ?: @(YES) boolValue];
extendStoryVideoUploadLength = [[settings objectForKey:@"extendStoryVideoUploadLength"] ?: @(YES) boolValue];
hideStatusBarWhenViewingStory = [[settings objectForKey:@"hideStatusBarWhenViewingStory"] ?: @(YES) boolValue];
neverReplayStoryAfterReacting = [[settings objectForKey:@"neverReplayStoryAfterReacting"] ?: @(NO) boolValue];
hidePeopleTab = [[settings objectForKey:@"hidePeopleTab"] ?: @(NO) boolValue];
hideStoriesTab = [[settings objectForKey:@"hideStoriesTab"] ?: @(NO) boolValue];
hideNotesRow = [[settings objectForKey:@"hideNotesRow"] ?: @(NO) boolValue];
hideSearchBar = [[settings objectForKey:@"hideSearchBar"] ?: @(NO) boolValue];
hideSuggestedContactsInSearch = [[settings objectForKey:@"hideSuggestedContactsInSearch"] ?: @(NO) boolValue];
}
#pragma mark - Settings page | Quick toggle to disable/enable read receipts
%hook MDSNavigationController
%property (nonatomic, retain) UIBarButtonItem *eyeItem;
%property (nonatomic, retain) UIBarButtonItem *settingsItem;
- (void)viewWillAppear:(BOOL)arg1 {
if (!self.settingsItem && [[self childViewControllerForUserInterfaceStyle] isKindOfClass:%c(MSGSettingsViewController)]) {
UIButton *settingsButton = [[UIButton alloc] init];
UIImage *settingsIcon = getTemplateImage(@"Gear@3x");
[settingsButton setImage:settingsIcon forState:UIControlStateNormal];
[settingsButton addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
self.settingsItem = [[UIBarButtonItem alloc] initWithCustomView:settingsButton];
self.settingsItem.style = UIBarButtonItemStyleDone;
@try {
self.navigationBar.topItem.leftBarButtonItems = @[self.navigationBar.topItem.leftBarButtonItem, self.settingsItem];
} @catch (id ex) {
self.navigationBar.topItem.leftBarButtonItem = self.settingsItem;
}
}
if (showTheEyeButton && !self.eyeItem && [[self childViewControllerForUserInterfaceStyle] isKindOfClass:%c(MSGInboxViewController)]) {
UIButton *eyeButton = [[UIButton alloc] init];
UIImage *eyeIcon = getTemplateImage(disableReadReceipts ? @"No-Receipt@3x" : @"Receipt@3x");
[eyeButton setImage:eyeIcon forState:UIControlStateNormal];
[eyeButton addTarget:self action:@selector(handleEyeTap:) forControlEvents:UIControlEventTouchUpInside];
self.eyeItem = [[UIBarButtonItem alloc] initWithCustomView:eyeButton];
self.eyeItem.style = UIBarButtonItemStyleDone;
self.navigationBar.topItem.rightBarButtonItems = @[self.navigationBar.topItem.rightBarButtonItem, self.eyeItem];
}
%orig;
}
%new(v@:)
- (void)openSettings {
isDarkMode = MSHookIvar<NSInteger>(self, "_statusBarStyleFromTheme") == 1;
SNSettingsViewController *settingsController = [[SNSettingsViewController alloc] init];
[self pushViewController:settingsController animated:YES];
}
%new(v@:@)
- (void)handleEyeTap:(UIButton *)eyeButton {
UIImage *eyeIcon = getTemplateImage(!disableReadReceipts ? @"No-Receipt@3x" : @"Receipt@3x");
[eyeButton setImage:eyeIcon forState:UIControlStateNormal];
[settings setObject:[NSNumber numberWithBool:!disableReadReceipts] forKey:@"disableReadReceipts"];
[settings writeToFile:getSettingsPlistPath() atomically:YES];
notify_post(PREF_CHANGED_NOTIF);
}
%end
#pragma mark - Necessary hooks
Class actionStandardClass;
MSGModelInfo actionStandardInfo;
MSGModelADTInfo actionStandardADTInfo = { "MSGStoryOverlayProfileViewAction", 0 };
Class actionTypeSaveClass;
MSGModelInfo actionTypeSaveInfo = { "MSGStoryViewerOverflowMenuActionTypeSave", 0, nil, nil, YES, nil};
MSGModelADTInfo actionTypeSaveADTInfo = { "MSGStoryViewerOverflowMenuActionType", 2 };
Class (* MSGModelDefineClass)(MSGModelInfo *);
%hookf(Class, MSGModelDefineClass, MSGModelInfo *info) {
Class modelClass = %orig;
SwitchStr (info->name) {
CaseEqual ("MSGStoryOverlayProfileViewActionStandard") {
actionStandardClass = modelClass;
actionStandardInfo = *info;
break;
}
CaseEqual ("MSGStoryViewerOverflowMenuActionTypeSave") {
return objc_lookUpClass("MSGStoryViewerOverflowMenuActionTypeSave") ?: modelClass;
}
Default {
break;
}
}
return modelClass;
}
%hook MSGModel
%new(v@:@)
- (void)setValueForField:(NSString *)name, /* value: */ ... {
MSGModelInfo *info = MSHookIvar<MSGModelInfo *>(self, "_modelInfo");
NSInteger index = 0, type = -1, offset = 0x0;
const char *encoding = "";
while (index < info->numberOfFields) {
if ([name isEqual:*(&info->fieldInfo->field_0 + offset)]) {
encoding = *(&info->fieldInfo->encoding_0 + offset);
type = *(&info->fieldInfo->type_0 + offset) % 256;
break;
}
offset += 0x4;
index++;
};
va_list args;
va_start(args, name);
switch (type) {
case 0: {
[self setBoolValue:(BOOL)va_arg(args, int) forFieldIndex:index];
break;
}
case 2: {
[self setInt64Value:va_arg(args, NSInteger) forFieldIndex:index];
break;
}
case 5 ... 6: {
switch (type - (MessengerVersion() <= 458.0)) {
case 5: [self setObjectValue:va_arg(args, id) forFieldIndex:index];
default: break;
}
break;
}
default: {
RLog(@"model: %@ | field: %@ | type: %lu | encoding: %s", self, name, type, encoding);
break;
}
}
va_end(args);
}
%new(@@:Q)
- (id)valueAtFieldIndex:(NSUInteger)index {
MSGModelInfo *modelInfo = MSHookIvar<MSGModelInfo *>(self, "_modelInfo");
NSUInteger type = *(&modelInfo->fieldInfo->type_0 + 0x4 * index) % 256;
MSGModelTypes values = MSHookIvar<MSGModelTypes>(self, "_fieldValues");
if (index >= modelInfo->numberOfFields) return @"Out of fields.";
switch (type) {
case 0: return @(get<bool>(values[index]));
case 1: return @(get<int>(values[index]));
case 2: return @(get<long long>(values[index]));
case 3: return @(get<double>(values[index]));
case 4: return @(get<float>(values[index]));
case 5 ... 8: {
switch (type - (MessengerVersion() <= 458.0)) {
case 4: return [NSValue valueWithPointer:get<void *>(values[index])]; // Struct in v458.0.0
case 5: return get<id>(values[index]);
case 6: return [get<MSGModelWeakObjectContainer *>(values[index]) value];
case 7: return (__bridge id)get<void *>(values[index]);
case 8: return NSStringFromSelector(*get<SEL *>(values[index]));
default: break;
}
}
case 9 ... 13: return get<id>(values[index]);
default: break;
}
return nil;
}
%new(@@:)
- (NSMutableDictionary *)debugMSGModel {
MSGModelInfo *modelInfo = MSHookIvar<MSGModelInfo *>(self, "_modelInfo");
NSMutableDictionary *debugInfo = [@{} mutableCopy];
NSInteger index = 0, offset = 0x0;
while (index < modelInfo->numberOfFields) {
NSString *name = *(&modelInfo->fieldInfo->field_0 + offset);
NSUInteger size = *(&modelInfo->fieldInfo->sizeof_0 + offset);
NSUInteger type = *(&modelInfo->fieldInfo->type_0 + offset) % 256;
const char *encoding = *(&modelInfo->fieldInfo->encoding_0 + offset);
NSDictionary *info = @{
@"index": @(index),
@"name" : name,
@"size" : @(size),
@"type" : [NSString stringWithFormat:@"type: %lu - %@ (%s)", type, typeLookup(encoding, type), encoding],
@"value": [self valueAtFieldIndex:index] ?: [NSNull null]
};
[debugInfo setValue:info forKey:[NSString stringWithFormat:@"%lu - %@", index, name]];
offset += 0x4;
index++;
};
return debugInfo;
}
%end
#pragma mark - Always send HD photos
%hook LSMediaPickerViewController
- (BOOL)collectionView:(id)arg1 shouldSelectItemAtIndexPath:(id)arg2 {
UIButton *hdToggleButton = MSHookIvar<UIButton *>(self, "_hdToggleButton");
if (alwaysSendHdPhotos && [hdToggleButton state] == 0) {
[self _stopHDAnimationAndToggleHD];
}
return %orig;
}
%end
#pragma mark - Audio / Video call confirmation
%hook MSGNavigationCoordinator_LSNavigationCoordinatorProxy
%new(v@:@?)
- (void)presentAlertWithCompletion:(void (^)(BOOL confirmed))completion {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:localizedStringForKey(@"CALL_CONFIRMATION_TITLE") message:localizedStringForKey(@"CALL_CONFIRMATION_MESSAGE") preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:localizedStringForKey(@"CONFIRM") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
completion(YES);
}]];
[alert addAction:[UIAlertAction actionWithTitle:localizedStringForKey(@"CANCEL") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
completion(NO);
}]];
[self presentViewController:alert presentationStyle:UIModalPresentationNone animated:YES completion:nil];
}
%end
id (* LSRTCValidateCallIntentForKey)(NSString *, id, LSRTCCallIntentValidatorParams *);
%hookf(id, LSRTCValidateCallIntentForKey, NSString *key, id context, LSRTCCallIntentValidatorParams *params) {
MSGNavigationCoordinator_LSNavigationCoordinatorProxy *navigationCoordinator = [[params callIntent] navigationCoordinator];
if (!callConfirmation || ![key isEqual:@"rtc_integrity_joiner_transparency"]) return %orig;
[navigationCoordinator presentAlertWithCompletion:^(BOOL confirmed) {
if (confirmed) %orig;
}];
return nil;
}
#pragma mark - Disable read receipts
%group MCINotificationCenterPostNotification
void *(* MCINotificationCenterPostNotification)(id, NSString *, NSString *, NSMutableDictionary *);
%hookf(void *, MCINotificationCenterPostNotification, id notifCenter, NSString *event, NSString *taskID, NSMutableDictionary *content) {
if (disableReadReceipts && [[content valueForKey:@"MCDNotificationTaskLabelsListKey"] isEqual:@[@"tam_thread_mark_read"]]) {
return nil;
}
return %orig;
}
%end
// v458.0.0
%group MCINotificationCenterPostStrictNotification
void *(* MCINotificationCenterPostStrictNotification)(NSUInteger, id, NSString *, NSString *, NSMutableDictionary *);
%hookf(void *, MCINotificationCenterPostStrictNotification, NSUInteger type, id notifCenter, NSString *event, NSString *taskID, NSMutableDictionary *content) {
if (disableReadReceipts && [[content valueForKey:@"MCDNotificationTaskLabelsListKey"] isEqual:@[@"tam_thread_mark_read"]]) {
return nil;
}
return %orig;
}
%end
#pragma mark - Disable stories preview
%hook MSGCQLResultSetList
+ (instancetype)newWithIdentifier:(NSString *)identifier context:(MSGStoryCardToolbox *)context resultSet:(id)arg3 resultSetCount:(NSInteger)arg4 options:(void *)arg5 actionHandlers:(void *)arg6 impressionTrackingContext:(id)arg7 {
if ([identifier isEqual:@"stories"]) {
[context setValueForField:@"isVideoAutoplayEnabled", !disableStoriesPreview];
}
return %orig;
}
%end
#pragma mark - Disable story seen receipt | Disable story replay after reacting
%hook LSStoryBucketViewController
%property (nonatomic, assign) BOOL isSelfStory;
%property (nonatomic, assign) CGFloat duration;
- (void)startTimer {
self.isSelfStory = [self.ownerId isEqual:[[%c(FBAnalytics) sharedAnalytics] userFBID]];
if (!disableStorySeenReceipts || self.isSelfStory) {
return %orig;
}
LSVideoPlayerView *playerView = MSHookIvar<LSVideoPlayerView *>(self, "_videoPlayerView");
self.duration = [self getDurationFromPlayerView:playerView];
[MSHookIvar<NSTimer *>(self, "_storyTimer") invalidate]; // Stop last timer
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(_updateProgressIndicator) userInfo:nil repeats:YES];
[self setValue:timer forKey:@"_storyTimer"]; // Set new timer
}
- (CGFloat)storyDuration {
return disableStorySeenReceipts && !self.isSelfStory ? self.duration : %orig;
}
%new(d@:@)
- (CGFloat)getDurationFromPlayerView:(LSVideoPlayerView *)playerView {
if (playerView) {
CMTime timeStruct = [playerView duration];
return (CGFloat)timeStruct.value / (CGFloat)timeStruct.timescale;
}
return 5.0f; // Default value for non-video stories
}
- (void)replyBarWillPlayStoryFromBeginning:(id)arg1 {
if (!neverReplayStoryAfterReacting) {
%orig;
}
}
%end
#pragma mark - Disable typing indicator
%hook MSGThreadRowCell
- (BOOL)_isTypingWithModel:(id)arg1 {
return [@[@"CHAT_SECTIONS_ONLY", @"BOTH"] containsObject:disableTypingIndicator] ? NO : %orig;
}
// v458.0.0
- (BOOL)_isTypingWithModel:(id)arg1 mailbox:(id)arg2 {
return [@[@"CHAT_SECTIONS_ONLY", @"BOTH"] containsObject:disableTypingIndicator] ? NO : %orig;
}
%end
%hook MSGMessageListViewModelGenerator
- (void)didLoadThreadModel:(id)arg1 threadViewModelMap:(id)arg2 threadSessionIdentifier:(id)arg3 messageModels:(NSMutableArray <MSGTempMessageListItemModel *> *)models componentStateMap:(id)arg5 threadParticipants:(id)arg6 attributionIDV2:(id)arg7 loadMoreStateOlder:(int)arg8 loadMoreStateNewer:(int)arg9 didLoadNewIsland:(BOOL)arg10 modelFetchedTimeInSeconds:(CGFloat)arg11 completion:(id)arg12 {
if ([@[@"INBOX_ONLY", @"BOTH"] containsObject:disableTypingIndicator] && [[[models lastObject] messageId] isEqual:@"typing_indicator"]) {
[models removeLastObject];
}
%orig;
}
// v458.0.0
- (void)didLoadThreadModel:(id)arg1 threadViewModelMap:(id)arg2 threadSessionIdentifier:(id)arg3 messageModels:(NSMutableArray <MSGTempMessageListItemModel *> *)models threadParticipants:(id)arg5 attributionIDV2:(id)arg6 loadMoreStateOlder:(int)arg7 loadMoreStateNewer:(int)arg8 didLoadNewIsland:(BOOL)arg9 completion:(id)arg10 {
if ([@[@"INBOX_ONLY", @"BOTH"] containsObject:disableTypingIndicator] && [[[models lastObject] messageId] isEqual:@"typing_indicator"]) {
[models removeLastObject];
}
%orig;
}
%end
#pragma mark - Extend story video upload duration
%group MSGAVFoundationEstimateMaxVideoDurationInputCreate
id (* MSGAVFoundationEstimateMaxVideoDurationInputCreate)(MSGMediaVideoPhasset *, NSUInteger, NSInteger, id, id);
%hookf(id, MSGAVFoundationEstimateMaxVideoDurationInputCreate, MSGMediaVideoPhasset *videoAsset, NSUInteger maxVideoResolution, NSInteger maxFileSizeInBytes, id roundingFactorInSeconds, id completion) {
MSHookIvar<CGFloat>([videoAsset asset], "_duration") = 1.0f; // max ≈ 13 mins
return %orig;
}
%end
// v458.0.0
%group MSGCSessionedMobileConfig
BOOL (* MSGCSessionedMobileConfigGetBoolean)(id, MSGCSessionedMobileConfig *, BOOL, BOOL);
%hookf(BOOL, MSGCSessionedMobileConfigGetBoolean, id context, MSGCSessionedMobileConfig *config, BOOL arg3, BOOL arg4) {
if (strcmp(config->subKey, "replace_system_trimmer") == 0) {
return YES;
}
return %orig;
}
CGFloat (* MSGCSessionedMobileConfigGetDouble)(id, MSGCSessionedMobileConfig *, BOOL, BOOL);
%hookf(CGFloat, MSGCSessionedMobileConfigGetDouble, id context, MSGCSessionedMobileConfig *config, BOOL arg3, BOOL arg4) {
if (strcmp(config->subKey, "max_story_duration") == 0) {
return 600.0f; // 10 mins
}
return %orig;
}
%end
#pragma mark - Hide notification badges in chat top bar | Keyboard state after entering chat | Disable long press to change theme
%hook MSGThreadViewController
- (instancetype)initWithMailbox:(id)arg1 threadQueryKey:(id)arg2 threadSessionLifecycle:(id)arg3 threadNavigationData:(id)arg4 navigationEntryPoint:(int)arg5 options:(MSGThreadViewControllerOptions *)options metricContextsContainer:(id)arg7 datasource:(id)arg8 {
MSGThreadViewOptions *viewOptions = [options viewOptions];
[viewOptions setValueForField:@"shouldHideBadgeInBackButton", hideNotifBadgesInChat];
if (![keyboardStateAfterEnterChat isEqual:@"ADAPTIVE"]) {
[viewOptions setValueForField:@"onOpenKeyboardState", [keyboardStateAfterEnterChat isEqual:@"ALWAYS_EXPANDED"] ? 2 : 1];
}
return %orig;
}
- (void)messageListViewControllerDidLongPressBackground:(id)arg1 {
if (!disableLongPressToChangeChatTheme) %orig;
}
%end
#pragma mark - Hide search bar
%hook MSGInboxViewController
- (void)viewDidLoad {
%orig;
if (hideSearchBar) {
self.navigationItem.searchController = nil;
}
}
%end
#pragma mark - Hide status bar when viewing story (iOS 12 devices only)
%hook LSMediaViewerViewController
- (BOOL)prefersStatusBarHidden {
BOOL isCorrectController = [MSHookIvar<id>(self, "_contentController") isKindOfClass:%c(LSStoryViewerContentController)];
return hideStatusBarWhenViewingStory && isCorrectController ? YES : %orig;
}
%end
#pragma mark - Hide suggested contacts in search
%hook LSContactListViewController
- (void)didLoadContactList:(NSArray *)list contactExtrasById:(NSDictionary *)extras {
if (hideSuggestedContactsInSearch) {
NSString *featureIdentifier = MSHookIvar<NSString *>(self, "_featureIdentifier");
if ([featureIdentifier isEqual:@"universal_search_null_state"]) {
return %orig(nil, nil);
}
}
%orig;
}
%end
#pragma mark - Hide tabs in tab bar
static BOOL hideTabBar = NO;
%hook LSTabBarDataSource
- (instancetype)initWithDependencies:(id)dependencies inboxLoadedCompletion:(id)completion {
LSTabBarDataSource *data = %orig;
NSMutableArray *items = [MSHookIvar<NSArray *>(data, "_tabBarItems") mutableCopy];
NSMutableArray *itemsInfo = [MSHookIvar<NSArray <MSGTabBarItemInfo *> *>(data, "_tabBarItemInfos") mutableCopy];
NSArray *removedItems = @[hidePeopleTab ? @"tabbar-people" : @"", hideStoriesTab ? @"tabbar-stories" : @""];
for (MSGTabBarItemInfo *info in [itemsInfo reverseObjectEnumerator]) {
if ([removedItems containsObject:[[info props] accessibilityIdentifierText]]) {
if ([itemsInfo count] > 2) {
[itemsInfo removeObject:info];
[items removeObject:info];
} else {
hideTabBar = YES;
break;
}
}
}
[data setValue:itemsInfo forKey:@"_tabBarItemInfos"];
[data setValue:items forKey:@"_tabBarItems"];
return data;
}
%end
%hook MDSTabBarController
- (void)_prepareTabBar {
if (!hideTabBar) %orig;
}
%end
#pragma mark - Remove ads | Hide notes row
%hook MSGThreadListDataSource
- (NSArray *)inboxRows {
NSMutableArray *currentRows = [%orig mutableCopy];
if ([self isInitializationComplete] && (noAds || hideNotesRow) && [currentRows count] > 0) {
MSGThreadListUnitsSate *unitsState = MSHookIvar<MSGThreadListUnitsSate *>(self, "_unitsState");
NSMutableDictionary *units = [unitsState unitKeyToUnit];
MSGInboxUnit *adUnit = [units objectForKey:@"ads_renderer"];
NSUInteger adUnitIndex = [[adUnit positionInThreadList] belowThreadIndex] + 2;
BOOL isOffline = [units objectForKey:@"qp"];
if (noAds && adUnitIndex + isOffline < [currentRows count]) [currentRows removeObjectAtIndex:adUnitIndex + isOffline];
if (hideNotesRow) [currentRows removeObjectAtIndex:isOffline];
}
return currentRows;
}
%end
%hook LSStoryViewerContentController
- (void)_updateStoriesWithBucketStoryModels:(NSMutableArray *)models deletedIndexPaths:(id)arg2 addedIndexPaths:(NSArray *)addedIndexPaths newIndexPath:(id)arg4 {
// Bucket types: 0 = unread | 1 = advertisement | 2 = read
for (MSGStoryViewerBucketModel *model in [models reverseObjectEnumerator]) {
if ([model bucketType] == 1) {
[models removeObject:model];
addedIndexPaths = @[];
}
}
%orig;
}
%end
#pragma mark - Save friends' stories
%hook LSStoryOverlayProfileView
- (void)_handleOverflowMenuButton:(UIButton *)button {
NSMutableArray *actions = [MSHookIvar<NSArray *>(self, "_overflowActions") mutableCopy];
NSString *storyAuthorId = MSHookIvar<NSString *>(self, "_storyAuthorId");
if (canSaveFriendsStories && ![storyAuthorId isEqual:[[%c(FBAnalytics) sharedAnalytics] userFBID]] && [actions count] == 3) {
actionTypeSaveClass = MSGModelDefineClass(&actionTypeSaveInfo);
MSGStoryViewerOverflowMenuActionTypeSave *actionTypeSave = nil;
MSGStoryOverlayProfileViewActionStandard *actionStandard = nil;
if (MessengerVersion() > 458.0) {
actionTypeSave = [actionTypeSaveClass newADTModelWithInfo:&actionTypeSaveInfo adtInfo:&actionTypeSaveADTInfo];
actionStandard = [actionStandardClass newADTModelWithInfo:&actionStandardInfo adtInfo:&actionStandardADTInfo];
} else {
actionTypeSave = [actionTypeSaveClass newADTModelWithInfo:&actionTypeSaveInfo adtValueSubtype:actionTypeSaveADTInfo.subtype];
actionStandard = [actionStandardClass newADTModelWithInfo:&actionStandardInfo adtValueSubtype:actionStandardADTInfo.subtype];
}
[actionStandard setValueForField:@"type", actionTypeSave];
[actions insertObject:actionStandard atIndex:2];
[self setValue:actions forKey:@"_overflowActions"];
}
%orig;
}
%end
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)reloadPrefs, CFSTR(PREF_CHANGED_NOTIF), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
reloadPrefs();
// Get the tweak bundle
tweakBundle = SNMessengerBundle();
MSImageRef LSEngineRef = getImageRef(@"LightSpeedEngine.framework/LightSpeedEngine");
MSImageRef LSCoreRef = getImageRef(@"LightSpeedCore.framework/LightSpeedCore");
if (MessengerVersion() > 458.0) {
LSRTCValidateCallIntentForKey = (id (*)(NSString *, id, LSRTCCallIntentValidatorParams *))MSFindSymbol(LSCoreRef, "_LSRTCValidateCallIntentForKey");
MSGModelDefineClass = (Class (*)(MSGModelInfo *))MSFindSymbol(LSEngineRef, "_MSGModelDefineClass");
MCINotificationCenterPostNotification = (void *(*)(id, NSString *, NSString *, NSMutableDictionary *))MSFindSymbol(LSEngineRef, "_MCINotificationCenterPostNotification");
%init(MCINotificationCenterPostNotification);
MSGAVFoundationEstimateMaxVideoDurationInputCreate = (id (*)(MSGMediaVideoPhasset *, NSUInteger, NSInteger, id, id))MSFindSymbol(LSEngineRef, "_MSGAVFoundationEstimateMaxVideoDurationInputCreate");
%init(MSGAVFoundationEstimateMaxVideoDurationInputCreate);
} else {
LSRTCValidateCallIntentForKey = (id (*)(NSString *, id, LSRTCCallIntentValidatorParams *))MSFindSymbol(LSCoreRef, "_LSRTCValidateCallIntentForKey");
MSGModelDefineClass = (Class (*)(MSGModelInfo *))MSFindSymbol(LSCoreRef, "_MSGModelDefineClass");
MCINotificationCenterPostStrictNotification = (void *(*)(NSUInteger, id, NSString *, NSString *, NSMutableDictionary *))MSFindSymbol(LSCoreRef, "_MCINotificationCenterPostStrictNotification");
%init(MCINotificationCenterPostStrictNotification);
MSGCSessionedMobileConfigGetBoolean = (BOOL (*)(id, MSGCSessionedMobileConfig *, BOOL, BOOL))MSFindSymbol(LSCoreRef, "_MSGCSessionedMobileConfigGetBoolean");
MSGCSessionedMobileConfigGetDouble = (CGFloat (*)(id, MSGCSessionedMobileConfig *, BOOL, BOOL))MSFindSymbol(LSCoreRef, "_MSGCSessionedMobileConfigGetDouble");
%init(MSGCSessionedMobileConfig);
}
%init;
}