Aww yeah, fixing race condition for drawing stories.

This commit is contained in:
Samuel Clay 2015-10-06 18:52:58 -07:00
parent 58b092c46e
commit 8c26fb1117
16 changed files with 45 additions and 23 deletions

View file

@ -103,7 +103,7 @@
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setDidFinishSelector:@selector(finishLoadActivities:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDelegate:self];

View file

@ -8,6 +8,7 @@
- (ASIHTTPRequest*) requestWithURL:(NSString*) s {
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:s]];
[request setValidatesSecureCertificate:NO];
[self addRequest:request];
return request;
}

View file

@ -676,6 +676,7 @@
[request setDelegate:self];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
[request setValidatesSecureCertificate:NO];
[request setUserInfo:@{@"feedPage": [NSNumber numberWithInt:storiesCollection.feedPage]}];
[request setFailedBlock:^(void) {
NSLog(@"in failed block %@", request);
@ -888,6 +889,7 @@
[self cancelRequests];
__weak ASIHTTPRequest *request = [self requestWithURL:theFeedDetailURL];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
@ -2051,10 +2053,11 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state
- (void)changeActiveFeedDetailRow {
NSInteger rowIndex = [storiesCollection locationOfActiveStory];
int offset = 1;
NSInteger offset = 1;
if ([[self.storyTitlesTable visibleCells] count] <= 4) {
offset = 0;
}
if (offset > rowIndex) offset = rowIndex;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0];
NSIndexPath *offsetIndexPath = [NSIndexPath indexPathForRow:(rowIndex - offset) inSection:0];
@ -2117,6 +2120,7 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state
[storiesCollection.activeFeed objectForKey:@"id"]];
[self cancelRequests];
ASIHTTPRequest *request = [self requestWithURL:urlString];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];

View file

@ -158,6 +158,7 @@
NSURL *url = [NSURL URLWithString:urlS];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];

View file

@ -118,6 +118,7 @@
NEWSBLUR_URL];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setDidFinishSelector:@selector(finishConnectFromSocial:)];
[request setDidFailSelector:@selector(requestFailed:)];

View file

@ -117,6 +117,7 @@
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];
@ -129,6 +130,7 @@
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setDidFinishSelector:@selector(loadSuggestedFriendsListFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];

View file

@ -107,6 +107,7 @@
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setDidFinishSelector:@selector(finishLoadInteractions:)];
[request setDidFailSelector:@selector(requestFailed:)];

View file

@ -963,6 +963,7 @@
NEWSBLUR_URL]];
ASIHTTPRequest *_request = [ASIHTTPRequest requestWithURL:url];
__weak ASIHTTPRequest *request = _request;
[request setValidatesSecureCertificate:NO];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
[request setFailedBlock:^(void) {
@ -1001,6 +1002,7 @@
NSURL *url = [NSURL URLWithString:urlS];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
@ -1793,7 +1795,7 @@
storyPageControl.currentPage,
storyPageControl.nextPage]) {
if ([[page.activeStory objectForKey:@"story_hash"]
isEqualToString:[story objectForKey:@"story_hash"]]) {
isEqualToString:[story objectForKey:@"story_hash"]] && page.isRecentlyUnread) {
page.isRecentlyUnread = NO;
[storyPageControl refreshHeaders];
}

View file

@ -392,6 +392,7 @@ static UIFont *userLabelFont;
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlFeedList];
[[NSHTTPCookieStorage sharedHTTPCookieStorage]
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
@ -1727,6 +1728,7 @@ heightForHeaderInSection:(NSInteger)section {
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlFeedList];
[[NSHTTPCookieStorage sharedHTTPCookieStorage]
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request setResponseEncoding:NSUTF8StringEncoding];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
@ -1983,9 +1985,6 @@ heightForHeaderInSection:(NSInteger)section {
positiveCount.frame = CGRectMake(greenIcon.frame.size.width + greenIcon.frame.origin.x + 2,
greenIcon.frame.origin.y - 3, 100, 16);
[positiveCount sizeToFit];
NSLog(@"User info size pre: %@", NSStringFromCGRect(userInfoBarButton.customView.frame));
NSLog(@"User info size post: %@", NSStringFromCGRect(userInfoBarButton.customView.frame));
}
- (void)showRefreshNotifier {

View file

@ -26,6 +26,7 @@ UIActionSheetDelegate> {
BOOL pullingScrollview;
BOOL inTextView;
BOOL inDoubleTap;
BOOL hasScrolled;
NSURL *activeLongPressUrl;
NSInteger actionSheetViewImageIndex;
NSInteger actionSheetCopyImageIndex;

View file

@ -259,9 +259,6 @@
#pragma mark Story setup
- (void)initStory {
NSString *feedIdStr = [NSString stringWithFormat:@"%@",
[self.activeStory
objectForKey:@"story_feed_id"]];
appDelegate.inStoryDetail = YES;
self.noStoryMessage.hidden = YES;
self.webView.hidden = NO;
@ -280,12 +277,13 @@
}
- (void)drawStory:(BOOL)force withOrientation:(UIInterfaceOrientation)orientation {
if (!force && self.activeStoryId == [self.activeStory objectForKey:@"story_hash"]) {
NSLog(@"Already drawn story.");
if (!force && [self.activeStoryId isEqualToString:[self.activeStory objectForKey:@"story_hash"]]) {
NSLog(@"Already drawn story, drawing anyway: %@", [self.activeStory objectForKey:@"story_title"]);
// return;
}
scrollPct = 0;
hasScrolled = NO;
NSString *shareBarString = [self getShareBar];
NSString *commentString = [self getComments];
@ -316,7 +314,7 @@
int contentWidth = CGRectGetWidth(self.webView.scrollView.bounds);
NSString *contentWidthClass;
NSLog(@"Drawing story: %d", contentWidth);
NSLog(@"Drawing story: %@ / %d", [self.activeStory objectForKey:@"story_title"], contentWidth);
if (UIInterfaceOrientationIsLandscape(orientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
contentWidthClass = @"NB-ipad-wide";
@ -406,12 +404,12 @@
NSURL *baseURL = [NSURL fileURLWithPath:path];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Drawing Story: %@", [self.activeStory objectForKey:@"story_title"]);
[self.webView setMediaPlaybackRequiresUserAction:NO];
[self.webView loadHTMLString:htmlString baseURL:baseURL];
[appDelegate.storyPageControl setTextButton:self];
});
// NSLog(@"Drawing Story: %@", [self.activeStory objectForKey:@"story_title"]);
self.activeStoryId = [self.activeStory objectForKey:@"story_hash"];
}
@ -458,6 +456,7 @@
- (void)clearStory {
self.activeStoryId = nil;
if (self.activeStory) self.activeStoryId = [self.activeStory objectForKey:@"story_hash"];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
[MBProgressHUD hideHUDForView:self.webView animated:NO];
}
@ -1111,6 +1110,7 @@
}
if (appDelegate.storyPageControl.currentPage != self) return;
if (!hasScrolled) hasScrolled = YES;
int webpageHeight = self.webView.scrollView.contentSize.height;
int viewportHeight = self.webView.scrollView.frame.size.height;
@ -1213,6 +1213,9 @@
}
- (void)scrollToLastPosition:(BOOL)animated {
if (hasScrolled) return;
hasScrolled = YES;
__block NSString *storyHash = [self.activeStory objectForKey:@"story_hash"];
__weak __typeof(&*self)weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,

View file

@ -553,10 +553,16 @@
self.scrollingToPage < 0 ||
ABS(newIndex - self.scrollingToPage) <= 1) {
[pageController drawFeedGradient];
NSString *originalStoryId = pageController.activeStoryId;
__block StoryDetailViewController *blockPageController = pageController;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul), ^{
[pageController initStory];
[pageController drawStory];
[pageController showTextOrStoryView];
if (blockPageController.activeStoryId && ![blockPageController.activeStoryId isEqualToString:originalStoryId]) {
NSLog(@"Stale story, already drawn. Was: %@, Now: %@", originalStoryId, blockPageController.activeStoryId);
return;
}
[blockPageController initStory];
[blockPageController drawStory];
[blockPageController showTextOrStoryView];
});
} else {
// [pageController clearStory];

View file

@ -75,6 +75,7 @@
NSString *storyTimestamp = [urlArray objectAtIndex:2];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setValidatesSecureCertificate:NO];
[request setUserInfo:@{@"story_hash": storyHash, @"story_timestamp": storyTimestamp}];
[request setDelegate:self];
[request setDidFinishSelector:@selector(storeCachedImage:)];

View file

@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>5.0.0b2</string>
<string>4.9.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
@ -58,7 +58,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>52</string>
<string>53</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>

View file

@ -2656,7 +2656,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.newsblur.NewsBlur;
PRODUCT_NAME = NewsBlur;
PROVISIONING_PROFILE = "ca3e3dd7-8eb5-4b4a-93e7-f66666a8cdab";
PROVISIONING_PROFILE = "a33bf1f3-82b0-4761-a144-cb612ef478e9";
STRIP_INSTALLED_PRODUCT = NO;
TARGETED_DEVICE_FAMILY = "1,2";
"WARNING_CFLAGS[arch=*]" = "-Wall";
@ -2696,7 +2696,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.newsblur.NewsBlur;
PRODUCT_NAME = NewsBlur;
PROVISIONING_PROFILE = "ca3e3dd7-8eb5-4b4a-93e7-f66666a8cdab";
PROVISIONING_PROFILE = "a33bf1f3-82b0-4761-a144-cb612ef478e9";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};

View file

@ -5,7 +5,7 @@
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#define DEBUG 1
//#define DEBUG 1
//#define PROD_DEBUG 1
#ifdef DEBUG