66BOOL noads;
77BOOL canSaveVideo;
88BOOL hideNewsFeedComposer;
9- BOOL hideNewsFeedRoom;
109BOOL hideNewsFeedStories;
1110
1211static void reloadPrefs () {
@@ -15,14 +14,29 @@ static void reloadPrefs() {
1514 noads = [[settings objectForKey: @" noads" ] ?: @(YES ) boolValue ];
1615 canSaveVideo = [[settings objectForKey: @" canSaveVideo" ] ?: @(YES ) boolValue ];
1716 hideNewsFeedComposer = [[settings objectForKey: @" hideNewsFeedComposer" ] ?: @(NO ) boolValue ];
18- hideNewsFeedRoom = [[settings objectForKey: @" hideNewsFeedRoom" ] ?: @(NO ) boolValue ];
1917 hideNewsFeedStories = [[settings objectForKey: @" hideNewsFeedStories" ] ?: @(NO ) boolValue ];
2018}
2119
2220%group NoAds
23- %hook FBMemSponsoredData
21+ %hook FBMemNewsFeedEdge
2422 - (id )initWithFBTree:(void *)arg1 {
25- return nil ;
23+ id orig = %orig ;
24+ id category = [orig category ];
25+ return category ? [category isEqualToString: @" ORGANIC" ] ? orig : nil : orig;
26+ }
27+ %end
28+
29+ %hook FBMemFeedStory
30+ - (id )initWithFBTree:(void *)arg1 {
31+ id orig = %orig ;
32+ return [orig sponsoredData ] == nil ? orig : nil ;
33+ }
34+ %end
35+
36+ %hook FBVideoChannelPlaylistItem
37+ - (id )Bi:(id )arg1 :(id )arg2 :(id )arg3 :(id )arg4 :(id )arg5 :(id )arg6 :(id )arg7 {
38+ id orig = %orig ;
39+ return [orig isSponsored ] ? nil : orig;
2640 }
2741 %end
2842%end
@@ -67,11 +81,11 @@ static void reloadPrefs() {
6781 %new
6882 - (BOOL )shouldHideSectionNumber:(int )sectionNumber {
6983 if (hideNewsFeedComposer) {
70- if (sectionNumber == 0 ) {
84+ if (([ self dataSourceState ]. sections . count == 3 && sectionNumber == 0 ) || ([ self dataSourceState ]. sections . count == 4 && sectionNumber == 1 ) ) {
7185 return TRUE ;
7286 }
7387 } else {
74- if (sectionNumber == 1 ) {
88+ if (([ self dataSourceState ]. sections . count == 4 && sectionNumber == 1 ) || ([ self dataSourceState ]. sections . count == 5 && sectionNumber == 2 ) ) {
7589 return TRUE ;
7690 }
7791 }
@@ -98,11 +112,17 @@ static void reloadPrefs() {
98112 %new
99113 - (void )handleLongPress:(UILongPressGestureRecognizer *)sender {
100114 if (sender.state == UIGestureRecognizerStateBegan) {
115+ FBVideoPlaybackItem *videoPlaybackItem = [self .controller currentVideoPlaybackItem ];
116+ if (!videoPlaybackItem) {
117+ [HCommon showAlertMessage: @" Can't find Video source, please report to developer" withTitle: @" Error" viewController: nil ];
118+ return ;
119+ }
120+
101121 UIAlertController* alert = [UIAlertController alertControllerWithTitle: nil message: nil preferredStyle: UI_USER_INTERFACE_IDIOM () == UIUserInterfaceIdiomPad ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
102122 [alert addAction: [UIAlertAction actionWithTitle: @" Download Video" style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action) {
103- NSURL *videoURL = [ self .controller currentVideoPlaybackItem ] .HDPlaybackURL ;
123+ NSURL *videoURL = videoPlaybackItem .HDPlaybackURL ;
104124 if (!videoURL) {
105- videoURL = [ self .controller currentVideoPlaybackItem ] .SDPlaybackURL ;
125+ videoURL = videoPlaybackItem .SDPlaybackURL ;
106126 }
107127 NSString *videoURLString = videoURL.absoluteString ;
108128 [HCommon showToastMessage: @" Downloading in background..." withTitle: @" Please wait" timeout: 1.0 viewController: nil ];
@@ -133,15 +153,36 @@ static void reloadPrefs() {
133153 if (sender.state == UIGestureRecognizerStateBegan) {
134154 UIView *view = self.superview .superview .superview .superview ;
135155 if (![view isKindOfClass: %c (VideoContainerView)]) {
136- view = self.superview .subviews [1 ].subviews [0 ].subviews [0 ];
156+ @try {
157+ view = self.superview .subviews [1 ].subviews [0 ].subviews [0 ];
158+ } @catch (NSException *exception) { }
159+ }
160+ if (![view isKindOfClass: %c (VideoContainerView)]) {
161+ @try {
162+ view = self.superview .subviews [2 ].subviews [0 ].subviews [0 ];
163+ } @catch (NSException *exception) { }
164+ }
165+ if (![view isKindOfClass: %c (VideoContainerView)]) {
166+ @try {
167+ view = self.superview .subviews [3 ].subviews [0 ].subviews [0 ];
168+ } @catch (NSException *exception) { }
169+ }
170+ if (![view isKindOfClass: %c (VideoContainerView)]) {
171+ [HCommon showAlertMessage: @" Can't find Video container, please report to developer" withTitle: @" Error" viewController: nil ];
172+ return ;
137173 }
138174 VideoContainerView *videoContainerView = (VideoContainerView *)view;
175+ FBVideoPlaybackItem *videoPlaybackItem = [videoContainerView.controller currentVideoPlaybackItem ];
176+ if (!videoPlaybackItem) {
177+ [HCommon showAlertMessage: @" Can't find Video source, please report to developer" withTitle: @" Error" viewController: nil ];
178+ return ;
179+ }
139180
140181 UIAlertController* alert = [UIAlertController alertControllerWithTitle: nil message: nil preferredStyle: UI_USER_INTERFACE_IDIOM () == UIUserInterfaceIdiomPad ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
141182 [alert addAction: [UIAlertAction actionWithTitle: @" Download Video" style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action) {
142- NSURL *videoURL = [videoContainerView.controller currentVideoPlaybackItem ] .HDPlaybackURL ;
183+ NSURL *videoURL = videoPlaybackItem .HDPlaybackURL ;
143184 if (!videoURL) {
144- videoURL = [videoContainerView.controller currentVideoPlaybackItem ] .SDPlaybackURL ;
185+ videoURL = videoPlaybackItem .SDPlaybackURL ;
145186 }
146187 NSString *videoURLString = videoURL.absoluteString ;
147188 [HCommon showToastMessage: @" Downloading in background..." withTitle: @" Please wait" timeout: 1.0 viewController: nil ];
@@ -170,7 +211,7 @@ static void reloadPrefs() {
170211 %init (HideNewsFeedComposer);
171212 }
172213
173- if (hideNewsFeedRoom || hideNewsFeedStories) {
214+ if (hideNewsFeedStories) {
174215 %init (HideNewsFeedChatRoomStories);
175216 }
176217}
0 commit comments