Skip to content

Commit

Permalink
feat: add the ability to hide meta ai
Browse files Browse the repository at this point in the history
  • Loading branch information
SoCuul committed May 12, 2024
1 parent 45e1daf commit fed0f7d
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/Controllers/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ - (NSArray *)specifiers {
_specifiers = [NSMutableArray arrayWithArray:@[
// Section 1: General
[self newSectionWithTitle:@"General" footer:nil],
[self newSwitchCellWithTitle:@"Hide Meta AI" detailTitle:@"Hides the meta ai buttons within the app" key:@"hide_meta_ai" defaultValue:false changeAction:nil],
[self newSwitchCellWithTitle:@"Copy description" detailTitle:@"Copy the post description with a long press" key:@"copy_description" defaultValue:true changeAction:nil],
[self newSwitchCellWithTitle:@"Hide reels tab" detailTitle:@"Hides the reels tab on the bottom navbar" key:@"hide_reels_tab" defaultValue:false changeAction:nil],
[self newSwitchCellWithTitle:@"Do not save recent searches" detailTitle:@"Search bars will no longer save your recent searches" key:@"no_recent_searches" defaultValue:false changeAction:nil],
Expand Down
290 changes: 290 additions & 0 deletions src/Features/General/HideMetaAI.xm
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
#import "../../InstagramHeaders.h"
#import "../../Manager.h"

// Direct

// Meta AI button functionality on direct search bar
%hook IGDirectInboxViewController
- (void)searchBarMetaAIButtonTappedOnSearchBar:(id)arg1 {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: direct search bar functionality");

return;
}

return %orig;
}
%end

// AI agents in direct new message view
%hook IGDirectRecipientGenAIBotsResult
- (id)initWithGenAIBots:(id)arg1 lastFetchedTimestamp:(id)arg2 {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: direct recipient ai agents");

return nil;
}

return %orig;
}
%end

// Meta AI suggested user in direct new message view
%hook IGDirectThreadCreationViewController
- (id)objectsForListAdapter:(id)arg1 {
NSMutableArray *newObjs = [%orig mutableCopy];

[newObjs enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

if ([obj isKindOfClass:%c(IGDirectRecipientCellViewModel)]) {

// Meta AI suggested user
if ([[[obj recipient] threadName] isEqualToString:@"Meta AI"]) {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: explore search results ai suggestion");

[newObjs removeObjectAtIndex:idx];
}

}

}

}];

return [newObjs copy];
}
%end

// Meta AI direct search suggested topics clouds
%hook IGDirectInboxSearchAIAgentsPillsContainerCell
- (void)didMoveToWindow {
%orig;

if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: direct search suggested topics clouds");

[self removeFromSuperview];
}
}
%end

// Meta AI direct search suggested topics header
%hook IGLabelItemViewModel
- (id)initWithLabelTitle:(id)arg1
tag:(NSInteger)arg2
uniqueIdentifier:(id)arg3
configuration:(id)arg4
accessibilityTraits:(NSUInteger)arg5
{
self = %orig;

if ([[self labelTitle] isEqualToString:@"Ask Meta AI"]) {

if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: explore suggested topics header");

return nil;
}

}

return self;
}
%end

// Meta AI direct search prompt suggestions in search results
%hook IGDirectInboxSearchAIAgentsSuggestedPromptRowCell
- (void)didMoveToWindow {
%orig;

if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: direct search ai prompt suggestions");

[self removeFromSuperview];
}
}
%end

// Meta AI search bar: opening meta ai chat on return key
%hook IGDirectInboxSearchController
- (void)_presentMetaAiWithPrompt:(id)arg1 presentationCompletion:(id)arg2 entryPoint:(NSInteger)arg3 {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: present meta ai thread from direct search");

return;
}

return %orig;
}
%end

/////////////////////////////////////////////////////////////////////////////

// Explore

// Meta AI search bar: explore search results data
%hook IGSearchListKitDataSource
- (id)objectsForListAdapter:(id)arg1 {
NSMutableArray *newObjs = [%orig mutableCopy];

[newObjs enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

// Section header
if ([obj isKindOfClass:%c(IGLabelItemViewModel)]) {

// "Ask Meta AI" search results header
if ([[obj labelTitle] isEqualToString:@"Ask Meta AI"]) {

if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: explore search results header");

[newObjs removeObjectAtIndex:idx];
}

}

}

// Meta AI suggested search results
if ([obj isKindOfClass:%c(IGSearchResultViewModel)]) {

// itemType 6 is meta ai suggestions
if ([obj itemType] == 6) {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: explore search results ai suggestion");

[newObjs removeObjectAtIndex:idx];
}

}

}

}];

return [newObjs copy];
}
%end
// Meta AI explore suggested topics clouds
%hook IGSearchResultCloudSectionController
- (id)initWithUserSession:(id)arg1 analyticsModule:(id)arg2 loggingProvider:(id)arg3 {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: explore suggested topics clouds");

return nil;
}

return %orig;
}
%end

/////////////////////////////////////////////////////////////////////////////

// Search / Buttons

// In-app search bars
%hook IGSearchBar
- (void)didMoveToWindow {
%orig;

if ([SCIManager hideMetaAI]) {

// Right meta ai button (in direct search)
UIView *_secondaryRightButton = MSHookIvar<UIView *>(self, "_secondaryRightButton");
if (_secondaryRightButton) {
NSLog(@"[SCInsta] Hiding meta ai: secondary right search bar icon");

[_secondaryRightButton removeFromSuperview];
}

}
}

- (void)_didTapDirectSendButton {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: tap on direct send button");

return;
}

return %orig;
}

- (void)_didTapMetaAIButton {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: tap on meta ai button");

return;
}

return %orig;
}

// This removes the padding added to the placeholder text, for the meta ai button
- (CGFloat)_getTextFieldOrginXForSearchBarWithLeftIcon {
if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: search bar padding for meta ai button");

// 43 (orig width) - 22 (meta ai button width) = 21
return 21;
}

return %orig;
}
%end

// Search typeahead
%hook IGSearchTypeaheadViewController
- (void)_presentMetaAIThreadWithDirectEntryPoint:(NSInteger)arg1 searchEntryPoint:(NSInteger)arg2 prompt:(id)arg3 {

if ([SCIManager hideMetaAI]) {
NSLog(@"[SCInsta] Hiding meta ai: present meta ai thread from search");

return;
}

return %orig;
}
%end

// Themed in-app buttons
%hook IGTapButton
- (void)didMoveToWindow {
%orig;

if ([SCIManager hideMetaAI]) {

// Hide buttons that are associated with meta ai
if ([self.accessibilityIdentifier containsString:@"meta_ai"]) {
NSLog(@"[SCInsta] Hiding meta ai: meta ai associated button");

[self removeFromSuperview];
}

}
}
%end

// Animated spinning icon
%hook IGKeyframeAnimationViewController
- (id)initWithUserSession:(id)arg1 assetURL:(id)assetURL cacheKey:(id)arg3 {
if ([SCIManager hideMetaAI]) {

if ([[assetURL absoluteString] isEqualToString:@"https://lookaside.facebook.com/ras/v2/?id=AQABh50YCM9z"]) {
NSLog(@"[SCInsta] Hiding meta ai: animated spining icon");

return nil;
}

else if ([[assetURL absoluteString] isEqualToString:@"https://lookaside.facebook.com/ras/v2/?id=AQAGo_cgnUHA"]) {
NSLog(@"[SCInsta] Hiding meta ai: animated spinning icon");

return nil;
}

}

return %orig;
}
%end
Loading

0 comments on commit fed0f7d

Please sign in to comment.