Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Add Hide Suggested Contact in Search, refactor settings view
Browse files Browse the repository at this point in the history
  • Loading branch information
haoict committed Aug 11, 2020
1 parent 607a2cd commit 6fe0cee
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.theos
packages
**/.DS_Store
HAOUtils*
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ include $(THEOS_MAKE_PATH)/aggregate.mk
internal-stage::
$(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/Application\ Support/MessengerNoAds.bundle/$(ECHO_END)
$(ECHO_NOTHING)cp -a settingsview/Resources/. $(THEOS_STAGING_DIR)/Library/Application\ Support/MessengerNoAds.bundle/$(ECHO_END)

clean::
rm -rf .theos packages
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Not only removing ads but shipped with many nice features
- Disable Story Seen (see others's stories but they won't know it)
- Can save friend's story. (Tap ... on top right of story view -> Save)
- Hide Search Bar (iOS12) / Hide Stories Row / Hide People tab
- Hide Suggested Contact in Search
- Extend Story Video Upload Length (from default is 20 seconds to 10 minutes)
- Support iOS 11 (tested) - 12 (tested) - 13 (tested)
- Support latest Messenger version (If it doesn't work, you should update the app to latest version >=258.0)
Expand Down
5 changes: 5 additions & 0 deletions Tweak.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@

@interface MSGListBinder : NSObject <UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, assign) BOOL didAddMNACellHeaderView;
@end

@interface LSContactListViewController : UIViewController {
NSString *_featureIdentifier;
}
@end
15 changes: 15 additions & 0 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ BOOL cansavefriendsstory;
BOOL hidesearchbar;
BOOL hidestoriesrow;
BOOL hidepeopletab;
BOOL hideSuggestedContactInSearch;
BOOL showTheEyeButton;
BOOL extendStoryVideoUploadLength;
NSString *plistPath;
Expand All @@ -30,6 +31,7 @@ static void reloadPrefs() {
hidesearchbar = [[settings objectForKey:@"hidesearchbar"] ?: @(NO) boolValue];
hidestoriesrow = [[settings objectForKey:@"hidestoriesrow"] ?: @(NO) boolValue];
hidepeopletab = [[settings objectForKey:@"hidepeopletab"] ?: @(NO) boolValue];
hideSuggestedContactInSearch = [[settings objectForKey:@"hideSuggestedContactInSearch"] ?: @(NO) boolValue];
showTheEyeButton = [[settings objectForKey:@"showTheEyeButton"] ?: @(YES) boolValue];
extendStoryVideoUploadLength = [[settings objectForKey:@"extendStoryVideoUploadLength"] ?: @(YES) boolValue];
}
Expand Down Expand Up @@ -182,9 +184,22 @@ static void reloadPrefs() {
- (void)handleMNACellTap:(UITapGestureRecognizer *)recognizer {
MNASettingsViewController *settingsVC = [[MNASettingsViewController alloc] init];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:settingsVC];
navVC.modalPresentationStyle = UIModalPresentationFullScreen;
[[%c(LSAppDelegate) sharedInstance] presentViewController:navVC animated:true completion:nil];
}
%end

%hook LSContactListViewController
- (void)_updateContactList {
if (hideSuggestedContactInSearch) {
NSString *_featureIdentifier = MSHookIvar<NSString *>(self, "_featureIdentifier");
if ([_featureIdentifier isEqualToString:@"universal_search_null_state"]) {
return;
}
}
%orig;
}
%end
%end

%group NoAdsNoStoriesRow
Expand Down
3 changes: 2 additions & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.haoict.messengernoads
Name: Messenger No Ads
Depends: mobilesubstrate, com.haoict.libhdev (>= 4.5.0), firmware (>= 10)
Version: 3.7.0
Version: 3.8.0
Architecture: iphoneos-arm
Description: The best tweak for Messenger app.
The best tweak for Messenger app.
Expand All @@ -13,6 +13,7 @@ Description: The best tweak for Messenger app.
- Disable Story Seen Receipt
- Can Save Friend's Story
- Hide Search Bar, Stories row, People tab
- Hide Suggested Contact in Search
- Extend Story Video Upload Length (from default is 20 seconds to 10 minutes)
- Support iOS 10 (not tested) - 11 (tested) - 12 (tested) - 13 (tested)
- Support latest Messenger version (If it doesn't work, you should update the app to latest version >= 258.0)
Expand Down
7 changes: 7 additions & 0 deletions layout/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "👋 Thank you for installing"
echo "💪 I work very hard to make good, free and open source tweaks for everyone"
echo "💰 If you want to support, you can buy me a coffee at www.paypal.me/haoict"
echo "💖 Hope you enjoy the tweak"
echo "👨‍💻 Developer: Hao Nguyen"
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
Binary file not shown.
1 change: 1 addition & 0 deletions settingsview/MNASettingsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
UIImageView *_headerImageView;
UILabel *_titleLabel;
UIImageView *_iconView;
NSMutableDictionary *_originalSettings;
}
@end
63 changes: 55 additions & 8 deletions settingsview/MNASettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ - (void)viewWillAppear:(BOOL)animated {
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
// set status bar text color
// [UIApplication sharedApplication]

_originalSettings = [MNAUtil getCurrentSettingsFromPlist];
}

- (void)viewWillDisappear:(BOOL)animated {
Expand Down Expand Up @@ -84,7 +86,7 @@ - (void)viewDidLoad {
[_tableView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
[_tableView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor],
[_tableView.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor],
[_tableView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
[_tableView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
]];
} else {
[NSLayoutConstraint activateConstraints:@[
Expand All @@ -95,12 +97,14 @@ - (void)viewDidLoad {
]];
}


// setup table image header
_headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
_headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
_headerImageView.contentMode = (IS_iPAD || self.view.bounds.size.width > self.view.bounds.size.height) ? UIViewContentModeScaleAspectFit : UIViewContentModeScaleAspectFill;
_headerImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", @PREF_BUNDLE_PATH, @"Banner.jpg"]];
_headerImageView.translatesAutoresizingMaskIntoConstraints = NO;
_headerImageView.clipsToBounds = YES;

[_headerView addSubview:_headerImageView];
[NSLayoutConstraint activateConstraints:@[
Expand Down Expand Up @@ -149,6 +153,10 @@ - (void)initTableData {
hidePeopleTabSwitchCell.prefKey = @"hidepeopletab";
hidePeopleTabSwitchCell.defaultValue = @"false";
hidePeopleTabSwitchCell.isRestartRequired = TRUE;
MNACellModel *hideSuggestedContactInSearch = [[MNACellModel alloc] initWithType:Switch withLabel:[MNAUtil localizedItem:@"HIDE_SUGGESTED_CONTACT_IN_SEARCH"]];
hideSuggestedContactInSearch.prefKey = @"hideSuggestedContactInSearch";
hideSuggestedContactInSearch.defaultValue = @"false";
hideSuggestedContactInSearch.isRestartRequired = TRUE;

MNACellModel *extendStoryVideoUploadLengthSwitchCell = [[MNACellModel alloc] initWithType:Switch withLabel:[MNAUtil localizedItem:@"EXTEND_STORY_VIDEO_UPLOAD_LENGTH"]];
extendStoryVideoUploadLengthSwitchCell.prefKey = @"extendStoryVideoUploadLength";
Expand Down Expand Up @@ -186,6 +194,7 @@ - (void)initTableData {
[_tableData addObject:hideSearchBarSwitchCell];
[_tableData addObject:hideStoriesRowSwitchCell];
[_tableData addObject:hidePeopleTabSwitchCell];
[_tableData addObject:hideSuggestedContactInSearch];
[_tableData addObject:extendStoryVideoUploadLengthSwitchCell];

[_tableData addObject:otherPreferencesCell];
Expand All @@ -209,7 +218,38 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
}

- (void)close {
[self dismissViewControllerAnimated:YES completion:nil];
BOOL isRestartRequired = FALSE;
NSMutableDictionary *newSettings = [MNAUtil getCurrentSettingsFromPlist];

// get diff from original settings with new settings
NSDictionary *diff = [MNAUtil compareNSDictionary:_originalSettings withNSDictionary:newSettings];
// get all keys array from diff
NSArray *diffAllKeys = [diff allKeys];

if ([diffAllKeys count] > 0) {
// check if changed keys has isRestartRequired
for (NSString *key in diffAllKeys) {
for (MNACellModel *cellModel in _tableData) {
if ([key isEqualToString:cellModel.prefKey] && cellModel.isRestartRequired) {
isRestartRequired = TRUE;
}
}
}
}

if (isRestartRequired) {
// show restart required alert
UIAlertController* alert = [UIAlertController alertControllerWithTitle:[MNAUtil localizedItem:@"APP_RESTART_REQUIRED"] message:[MNAUtil localizedItem:@"DO_YOU_REALLY_WANT_TO_KILL_MESSENGER"] preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:[MNAUtil localizedItem:@"CONFIRM"] style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
exit(0);
}]];
[alert addAction:[UIAlertAction actionWithTitle:[MNAUtil localizedItem:@"CANCEL"] style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alert animated:YES completion:nil];
} else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
Expand Down Expand Up @@ -249,12 +289,19 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}

- (void)resetSettings {
NSString *plistPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@PLIST_FILENAME];
[@{} writeToFile:plistPath atomically:YES];
[_tableView reloadData];
notify_post(PREF_CHANGED_NOTIF);
// [HCommon showToastMessage:@"" withTitle:@"Done!" timeout:0.5 viewController:self];
[MNAUtil showRequireRestartAlert:self];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Are you sure?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
NSString *plistPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@PLIST_FILENAME];
[@{} writeToFile:plistPath atomically:YES];
[_tableView reloadData];
notify_post(PREF_CHANGED_NOTIF);
exit(0);
}];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:confirmAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
Expand Down
8 changes: 4 additions & 4 deletions settingsview/MNATableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ - (id)initWithData:(MNACellModel *)cellData reuseIdentifier:(NSString *)reuseIde
self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
_cellData = cellData;
_vc = vc;
_plistPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@PLIST_FILENAME];
_plistPath = [MNAUtil getPlistPath];
if (self) {
self.textLabel.text = cellData.label;
self.textLabel.textColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @LABEL_COLOR_DARKMODE : @LABEL_COLOR];
Expand Down Expand Up @@ -100,9 +100,9 @@ - (void)setPreferenceValue:(id)value {
} else {
notify_post(PREF_CHANGED_NOTIF);

if (_cellData.isRestartRequired) {
[MNAUtil showRequireRestartAlert:_vc];
}
// if (_cellData.isRestartRequired) {
// [MNAUtil showRequireRestartAlert:_vc];
// }
}
}

Expand Down
3 changes: 3 additions & 0 deletions settingsview/MNAUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
@interface MNAUtil : NSObject
+ (NSString *)localizedItem:(NSString *)key;
+ (void)showRequireRestartAlert:(UIViewController *)vc;
+ (NSString *)getPlistPath;
+ (NSMutableDictionary *)getCurrentSettingsFromPlist;
+ (NSDictionary *)compareNSDictionary:(NSDictionary *)d1 withNSDictionary:(NSDictionary *)d2;
@end
32 changes: 32 additions & 0 deletions settingsview/MNAUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,36 @@ + (void)showRequireRestartAlert:(UIViewController *)vc {
[vc presentViewController:alert animated:YES completion:nil];
}
}

+ (NSString *)getPlistPath {
return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@PLIST_FILENAME];
}

+ (NSMutableDictionary *)getCurrentSettingsFromPlist {
return [[NSMutableDictionary alloc] initWithContentsOfFile:[MNAUtil getPlistPath]] ?: [@{} mutableCopy];
}

+ (NSDictionary *)compareNSDictionary:(NSDictionary *)d1 withNSDictionary:(NSDictionary *)d2 {
NSMutableDictionary *result = NSMutableDictionary.dictionary;

// Find objects in d1 that don't exist or are different in d2
[d1 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
id otherObj = d2[key];

if (![obj isEqual:otherObj]) {
result[key] = obj;
}
}];

// Find objects in d2 that don't exist in d1
[d2 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
id d1Obj = d1[key];

if (!d1Obj) {
result[key] = obj;
}
}];

return result;
}
@end
1 change: 1 addition & 0 deletions settingsview/Resources/ar.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"HIDE_SEARCH_BAR" = "اخفاء شريط البحث - تعمل فقط مع الاصدار 12";
"HIDE_STORIES_ROW" = "الغاء شريط الحاله";
"HIDE_PEOPLE_TAB" = "اخفاء ايقونه الاشخاص";
"HIDE_SUGGESTED_CONTACT_IN_SEARCH" = "Hide Suggested Contact In Search";
"EXTEND_STORY_VIDEO_UPLOAD_LENGTH" = "تمديد طول تحميل الفيديو القصة";
"OTHER_PREFERENCES" = "الاعدادات الاخرى";
"SHOW_THE_EYE_BUTTON" = "إظهار زر العين";
Expand Down
1 change: 1 addition & 0 deletions settingsview/Resources/base.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"HIDE_SEARCH_BAR" = "Hide Search Bar (iOS 12 only)";
"HIDE_STORIES_ROW" = "Hide Stories Row";
"HIDE_PEOPLE_TAB" = "Hide People Tab";
"HIDE_SUGGESTED_CONTACT_IN_SEARCH" = "Hide Suggested Contact In Search";
"EXTEND_STORY_VIDEO_UPLOAD_LENGTH" = "Extend Story Video Upload Length";
"OTHER_PREFERENCES" = "Other Preferences";
"SHOW_THE_EYE_BUTTON" = "Show The Eye Button";
Expand Down
1 change: 1 addition & 0 deletions settingsview/Resources/en.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"HIDE_SEARCH_BAR" = "Hide Search Bar (iOS 12 only)";
"HIDE_STORIES_ROW" = "Hide Stories Row";
"HIDE_PEOPLE_TAB" = "Hide People Tab";
"HIDE_SUGGESTED_CONTACT_IN_SEARCH" = "Hide Suggested Contact In Search";
"EXTEND_STORY_VIDEO_UPLOAD_LENGTH" = "Extend Story Video Upload Length";
"OTHER_PREFERENCES" = "Other Preferences";
"SHOW_THE_EYE_BUTTON" = "Show The Eye Button";
Expand Down
1 change: 1 addition & 0 deletions settingsview/Resources/fr.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"HIDE_SEARCH_BAR" = "Cacher barre de recherche (iOS12)";
"HIDE_STORIES_ROW" = "Cacher la rangée des Stories";
"HIDE_PEOPLE_TAB" = "Cacher l'onglet Personnes";
"HIDE_SUGGESTED_CONTACT_IN_SEARCH" = "Hide Suggested Contact In Search";
"EXTEND_STORY_VIDEO_UPLOAD_LENGTH" = "Prolonger la durée de téléchargement de la vidéo de l'histoire";
"OTHER_PREFERENCES" = "Autres réglages";
"SHOW_THE_EYE_BUTTON" = "Afficher le bouton oeil";
Expand Down
1 change: 1 addition & 0 deletions settingsview/Resources/nl.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"HIDE_SEARCH_BAR" = "Zoekbalk verbergen (alleen iOS 12)";
"HIDE_STORIES_ROW" = "Verhalenrij verbergen";
"HIDE_PEOPLE_TAB" = "Tabblad Personen verbergen";
"HIDE_SUGGESTED_CONTACT_IN_SEARCH" = "Hide Suggested Contact In Search";
"EXTEND_STORY_VIDEO_UPLOAD_LENGTH" = "Verleng de lengte van de uploadvideo van het verhaal";
"OTHER_PREFERENCES" = "Andere voorkeuren";
"SHOW_THE_EYE_BUTTON" = "Toon de oogknop";
Expand Down
1 change: 1 addition & 0 deletions settingsview/Resources/th.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"HIDE_SEARCH_BAR" = "ซ่อนแท็บค้นหา (เฉพาะ iOS 12)";
"HIDE_STORIES_ROW" = "ซ่อนแถบสตอรี่";
"HIDE_PEOPLE_TAB" = "ซ่อนแท็บผู้คน";
"HIDE_SUGGESTED_CONTACT_IN_SEARCH" = "Hide Suggested Contact In Search";
"EXTEND_STORY_VIDEO_UPLOAD_LENGTH" = "เพิ่มความยาวเวลาบันทึกวิดีโอสตอรี่";
"OTHER_PREFERENCES" = "ตั้งค่าอื่น ๆ";
"SHOW_THE_EYE_BUTTON" = "แสดงปุ่มดวงตา";
Expand Down
1 change: 1 addition & 0 deletions settingsview/Resources/vi.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"HIDE_SEARCH_BAR" = "Ẩn ô tìm kiếm (iOS 12)";
"HIDE_STORIES_ROW" = "Ẩn hàng story";
"HIDE_PEOPLE_TAB" = "Ẩn tab Mọi người";
"HIDE_SUGGESTED_CONTACT_IN_SEARCH" = "Ẩn bạn bè \"được gợi ý\" trong mục tìm kiếm";
"EXTEND_STORY_VIDEO_UPLOAD_LENGTH" = "Tăng thời lượng tải lên Story video";
"OTHER_PREFERENCES" = "Tùy chỉnh phụ";
"SHOW_THE_EYE_BUTTON" = "Hiện nút con mắt";
Expand Down

0 comments on commit 6fe0cee

Please sign in to comment.