sharing and replying features

This commit is contained in:
Roy Yang 2012-07-20 15:54:10 -07:00
parent 884fa8a98f
commit 8ed7415b2c
14 changed files with 193 additions and 44 deletions

3
.gitignore vendored
View file

@ -2,6 +2,7 @@ logs/*.log
logs/*.log.*
logs/*.pid
*.pyc
static.tgz
static/*
local_settings.py
media/iphone/NewsBlur/build
@ -20,4 +21,4 @@ xcuserdata
*.mode1v3
*.pbxuser
media/maintenance.html
config/settings
config/settings

View file

@ -0,0 +1,15 @@
//
// DataUtilities.h
// NewsBlur
//
// Created by Roy Yang on 7/20/12.
// Copyright (c) 2012 NewsBlur. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DataUtilities : NSObject
+ (NSArray *)updateUserProfiles:(NSArray *)userProfiles withNewUserProfiles:(NSArray *)newUserProfiles;
@end

View file

@ -0,0 +1,39 @@
//
// DataUtilities.m
// NewsBlur
//
// Created by Roy Yang on 7/20/12.
// Copyright (c) 2012 NewsBlur. All rights reserved.
//
#import "DataUtilities.h"
#import "NewsBlurAppDelegate.h"
@implementation DataUtilities
+ (NSArray *)updateUserProfiles:(NSArray *)userProfiles withNewUserProfiles:(NSArray *)newUserProfiles {
NSMutableArray *updatedUserProfiles = [userProfiles mutableCopy];
for (int i = 0; i < newUserProfiles.count; i++) {
BOOL isInUserProfiles = NO;
NSDictionary *newUser = [newUserProfiles objectAtIndex:i];
NSString *newUserIdStr = [NSString stringWithFormat:@"%@", [newUser objectForKey:@"user_id"]];
for (int j = 0; j < userProfiles.count; j++) {
NSDictionary *user = [userProfiles objectAtIndex:i];
NSString *userIdStr = [NSString stringWithFormat:@"%@", [user objectForKey:@"user_id"]];
if ([newUserIdStr isEqualToString:userIdStr]) {
isInUserProfiles = YES;
break;
}
}
if (!isInUserProfiles) {
[updatedUserProfiles addObject:newUser];
}
}
return updatedUserProfiles;
}
@end

View file

@ -1138,6 +1138,12 @@
- (void)loadFaviconsFromActiveFeed {
NSArray * keys = [appDelegate.dictActiveFeeds allKeys];
if (![keys count]) {
// if no new favicons, return
return;
}
NSString *feedIdsQuery = [NSString stringWithFormat:@"?feed_ids=%@",
[[keys valueForKey:@"description"] componentsJoinedByString:@"&feed_ids="]];
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/favicons%@",

View file

@ -199,7 +199,7 @@
- (void)hideStoryDetailView;
- (void)changeActiveFeedDetailRow;
- (void)dragFeedDetailView:(float)y;
- (void)showShareView:(NSString *)userId setUsername:(NSString *)username;
- (void)showShareView:(NSString *)type setUserId:(NSString *)userId setUsername:(NSString *)username setCommentIndex:(NSString *)commentIndex;
- (void)hideShareView:(BOOL)resetComment;
- (void)refreshComments;
- (void)resetShareComments;

View file

@ -253,13 +253,17 @@
self.feedDashboardViewController.storyLabel.hidden = NO;
}
- (void)showShareView:(NSString *)userId
setUsername:(NSString *)username {
- (void)showShareView:(NSString *)type
setUserId:(NSString *)userId
setUsername:(NSString *)username
setCommentIndex:(NSString *)commentIndex {
self.isShowingShare = YES;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// add shareViewController to storyDetail
[self.storyDetailViewController.view addSubview:self.shareViewController.view];
[self.shareViewController setSiteInfo:userId setUsername:username];
[self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setCommentIndex:commentIndex];
self.shareViewController.view.frame = CGRectMake(0,
self.storyDetailViewController.view.frame.size.height,
self.storyDetailViewController.view.frame.size.width,
@ -288,7 +292,7 @@
} else {
ShareViewController *shareView = [[ShareViewController alloc] init];
self.shareViewController = shareView;
[self.shareViewController setSiteInfo:userId setUsername:username];
[self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setCommentIndex:commentIndex];
[self.navigationController presentModalViewController:self.shareViewController animated:YES];
}
}

View file

@ -1044,13 +1044,12 @@
}
if ([folderName isEqualToString:@""]){
NSLog(@"feedLocations count is %i: ", [feedLocations count]);
// NSLog(@"feedLocations count is %i: ", [feedLocations count]);
}
// NSLog(@"feedLocations %@", feedLocations);
[self.activeFeedLocations setObject:feedLocations forKey:folderName];
}
NSLog(@"second here");
// NSLog(@"Active feed locations %@", self.activeFeedLocations);
}

View file

@ -20,7 +20,7 @@
@property ( nonatomic) IBOutlet UIBarButtonItem *submitButton;
@property ( nonatomic) IBOutlet UIBarButtonItem *toolbarTitle;
- (void)setSiteInfo:(NSString *)userId setUsername:(NSString *)username;
- (void)setSiteInfo:(NSString *)type setUserId:(NSString *)userId setUsername:(NSString *)username setCommentIndex:(NSString *)commentIndex;
- (void)clearComments;
- (IBAction)doCancelButton:(id)sender;
- (IBAction)doToggleButton:(id)sender;

View file

@ -11,6 +11,7 @@
#import "StoryDetailViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Utilities.h"
#import "DataUtilities.h"
#import "JSON.h"
#import "ASIHTTPRequest.h"
@ -107,14 +108,41 @@
[userPreferences synchronize];
}
- (void)setSiteInfo:(NSString *)userId setUsername:(NSString *)username {
if (userId) {
- (void)setSiteInfo:(NSString *)type setUserId:(NSString *)userId setUsername:(NSString *)username setCommentIndex:(NSString *)commentIndex {
if ([type isEqualToString: @"edit-reply"]) {
[submitButton setTitle:@"Save"];
facebookButton.hidden = YES;
twitterButton.hidden = YES;
[toolbarTitle setTitle:[NSString stringWithFormat:@"Edit Your Reply"]];
[submitButton setAction:(@selector(doReplyToComment:))];
// get old comment
NSArray *replies = [appDelegate.activeComment objectForKey:@"replies"];
int commentIdx = [commentIndex intValue];
self.commentField.text = [[replies objectAtIndex:commentIdx] objectForKey:@"comments"];
} else if ([type isEqualToString: @"reply"]) {
[submitButton setTitle:@"Reply"];
facebookButton.hidden = YES;
twitterButton.hidden = YES;
[toolbarTitle setTitle:[NSString stringWithFormat:@"Reply to %@", username]];
[submitButton setAction:(@selector(doReplyToComment:))];
} else {
} else if ([type isEqualToString: @"edit-share"]) {
facebookButton.hidden = NO;
twitterButton.hidden = NO;
// get old comment
self.commentField.text = [appDelegate.activeComment objectForKey:@"comments"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[toolbarTitle setTitle:@"Edit Your Comment"];
[submitButton setTitle:@"Save"];
} else {
[toolbarTitle setTitle:@"Edit"];
[submitButton setTitle:@"Save"];
}
[submitButton setAction:(@selector(doShareThisStory:))];
} else if ([type isEqualToString: @"share"]) {
facebookButton.hidden = NO;
twitterButton.hidden = NO;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
@ -123,7 +151,6 @@
} else {
[toolbarTitle setTitle:@"Post"];
[submitButton setTitle:@"Share"];
NSLog(@"set title");
}
[submitButton setAction:(@selector(doShareThisStory:))];
}
@ -183,7 +210,7 @@
}
- (void)finishAddReply:(ASIHTTPRequest *)request {
NSLog(@"%@", [request responseString]);
NSLog(@"/n/n/n%@/n/n/n/", [request responseString]);;
NSLog(@"Successfully added.");
NSString *responseString = [request responseString];
NSDictionary *results = [[NSDictionary alloc]
@ -191,6 +218,12 @@
// add the comment into the activeStory dictionary
NSDictionary *comment = [results objectForKey:@"comment"];
NSArray *userProfiles = [results objectForKey:@"user_profiles"];
appDelegate.activeFeedUserProfiles = [DataUtilities
updateUserProfiles:appDelegate.activeFeedUserProfiles
withNewUserProfiles:userProfiles];
NSString *commentUserId = [NSString stringWithFormat:@"%@", [comment objectForKey:@"user_id"]];
BOOL foundComment = NO;
@ -223,6 +256,8 @@
[newPublicComments addObject:[publicComments objectAtIndex:i]];
}
}
[newActiveStory setValue:[NSArray arrayWithArray:publicComments] forKey:@"public_comments"];
} else {
[newActiveStory setValue:[NSArray arrayWithArray:newFriendsComments] forKey:@"friend_comments"];
}
@ -231,9 +266,7 @@
}
- (void)finishAddComment:(ASIHTTPRequest *)request {
NSLog(@"%@", [request responseString]);
NSLog(@"Successfully added.");
NSLog(@"/n/n/n%@/n/n/n/", [request responseString]);
NSString *responseString = [request responseString];
NSDictionary *results = [[NSDictionary alloc]

View file

@ -66,7 +66,7 @@
- (void)changeFontSize:(NSString *)fontSize;
- (NSString *)getComments:(NSString *)type;
- (NSString *)getComment:(NSDictionary *)commentDict;
- (NSString *)getReplies:(NSArray *)replies;
- (NSString *)getReplies:(NSArray *)replies forUserId:(NSString *)commentUserId;
- (NSString *)getAvatars:(BOOL)areFriends;
- (NSDictionary *)getUser:(int)user_id;

View file

@ -284,7 +284,7 @@
userEditButton = [NSString stringWithFormat:@
"<div class=\"NB-story-comment-edit-button NB-story-comment-share-edit-button\">"
"<div class=\"NB-story-comment-edit-button-wrapper\">"
"<a href=\"http://ios.newsblur.com/share\">edit</a>"
"<a href=\"http://ios.newsblur.com/edit-share\">edit</a>"
"</div>"
"</div>"
];
@ -331,22 +331,35 @@
[commentDict objectForKey:@"user_id"],
[user objectForKey:@"username"],
[commentDict objectForKey:@"comments"],
[self getReplies:[commentDict objectForKey:@"replies"]]];
[self getReplies:[commentDict objectForKey:@"replies"] forUserId:[commentDict objectForKey:@"user_id"]]];
return comment;
}
- (NSString *)getReplies:(NSArray *)replies {
- (NSString *)getReplies:(NSArray *)replies forUserId:(NSString *)commentUserId {
NSString *repliesString = @"";
if (replies.count > 0) {
repliesString = [repliesString stringByAppendingString:@"<div class=\"NB-story-comment-replies\">"];
for (int i = 0; i < replies.count; i++) {
NSDictionary *reply_dict = [replies objectAtIndex:i];
NSDictionary *user = [self getUser:[[reply_dict objectForKey:@"user_id"] intValue]];
// NSString *editStr = [NSString stringWithFormat:@
// " <div class=\"NB-story-comment-edit-button NB-story-comment-reply-edit-button\">"
// " <div class=\"NB-story-comment-edit-button-wrapper\">edit</div>"
// " </div>"];
NSDictionary *replyDict = [replies objectAtIndex:i];
NSDictionary *user = [self getUser:[[replyDict objectForKey:@"user_id"] intValue]];
NSString *userEditButton = @"";
NSString *replyUserId = [NSString stringWithFormat:@"%@", [replyDict objectForKey:@"user_id"]];
NSString *currentUserId = [NSString stringWithFormat:@"%@", [appDelegate.dictUserProfile objectForKey:@"user_id"]];
if ([replyUserId isEqualToString:currentUserId]) {
userEditButton = [NSString stringWithFormat:@
"<div class=\"NB-story-comment-edit-button NB-story-comment-share-edit-button\">"
"<div class=\"NB-story-comment-edit-button-wrapper\">"
"<a href=\"http://ios.newsblur.com/edit-reply/%@/%@/%i\">edit</a>"
"</div>"
"</div>",
commentUserId,
replyUserId,
i // comment number in array
];
}
NSString *reply = [NSString stringWithFormat:@
"<div class=\"NB-story-comment-reply\">"
@ -355,13 +368,15 @@
" </a>"
" <div class=\"NB-story-comment-username NB-story-comment-reply-username\">%@</div>"
" <div class=\"NB-story-comment-date NB-story-comment-reply-date\">%@ ago</div>"
" %@" //User Edit Button>"
" <div class=\"NB-story-comment-reply-content\">%@</div>"
"</div>",
[user objectForKey:@"user_id"],
[user objectForKey:@"photo_url"],
[user objectForKey:@"username"],
[reply_dict objectForKey:@"publish_date"],
[reply_dict objectForKey:@"comments"]];
[replyDict objectForKey:@"publish_date"],
userEditButton,
[replyDict objectForKey:@"comments"]];
repliesString = [repliesString stringByAppendingString:reply];
}
repliesString = [repliesString stringByAppendingString:@"</div>"];
@ -576,7 +591,9 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
// the pathComponents do not work correctly unless it is a correctly formed url
// Is there a better way? Someone show me the light
if ([[url host] isEqualToString: @"ios.newsblur.com"]){
if ([action isEqualToString:@"reply"]) {
if ([action isEqualToString:@"reply"] ||
[action isEqualToString:@"edit-reply"] ||
[action isEqualToString:@"edit-share"]) {
appDelegate.activeComment = nil;
// search for the comment from friends comments
NSArray *friendComments = [appDelegate.activeStory objectForKey:@"friend_comments"];
@ -600,11 +617,29 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
}
}
}
[appDelegate showShareView:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:2]]
setUsername:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:3]]];
return NO;
if ([action isEqualToString:@"reply"]) {
[appDelegate showShareView:@"reply"
setUserId:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:2]]
setUsername:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:3]]
setCommentIndex:nil];
} else if ([action isEqualToString:@"edit-reply"]) {
[appDelegate showShareView:@"edit-reply"
setUserId:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:2]]
setUsername:nil
setCommentIndex:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:4]]];
} else if ([action isEqualToString:@"edit-share"]) {
[appDelegate showShareView:@"edit-share"
setUserId:nil
setUsername:nil
setCommentIndex:[NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:3]]];
}
return NO;
} else if ([action isEqualToString:@"share"]) {
[appDelegate showShareView:nil setUsername:nil];
[appDelegate showShareView:@"share"
setUserId:nil
setUsername:nil
setCommentIndex:nil];
return NO;
} else if ([action isEqualToString:@"show-profile"]) {
appDelegate.activeUserProfileId = [NSString stringWithFormat:@"%@", [urlComponents objectAtIndex:2]];
@ -768,10 +803,13 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
}
- (void)refreshComments {
NSString *friendsCommentString = [self getComments:@"friends"];
NSString *commentString = [self getComments:@"friends"];
NSString *jsString = [[NSString alloc] initWithFormat:@
"document.getElementById('NB-comments-wrapper').innerHTML = '%@';",
friendsCommentString];
//"document.getElementById('NB-comments-wrapper').innerHTML = '%@';",
"document.write(%@)",
commentString];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}

View file

@ -49,11 +49,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3</string>
<string>1.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.3</string>
<string>1.5</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
@ -62,6 +62,8 @@
<string>MainWindow~ipad</string>
<key>UIPrerenderedIcon</key>
<true/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
@ -76,7 +78,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
</dict>
</plist>

View file

@ -193,6 +193,7 @@
43C95C48158BEC450086C69B /* GoogleReaderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 43C95C46158BEC440086C69B /* GoogleReaderViewController.m */; };
43C95C49158BEC450086C69B /* GoogleReaderViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43C95C47158BEC440086C69B /* GoogleReaderViewController.xib */; };
43C95C4B158BF8810086C69B /* google_reader_selected_background.png in Resources */ = {isa = PBXBuildFile; fileRef = 43C95C4A158BF8810086C69B /* google_reader_selected_background.png */; };
43D818A315B940C200733444 /* DataUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 43D818A215B940C200733444 /* DataUtilities.m */; };
43E8856015951F930032022E /* reader.css in Resources */ = {isa = PBXBuildFile; fileRef = 43E8855F15951F930032022E /* reader.css */; };
43F44B1C159D8DBC00F48F8A /* FeedTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F44B1B159D8D7200F48F8A /* FeedTableCell.m */; };
43F6A79915B0C57F0092EE91 /* flag_orange.png in Resources */ = {isa = PBXBuildFile; fileRef = 43F6A79815B0C57F0092EE91 /* flag_orange.png */; };
@ -525,6 +526,8 @@
43D045261565BC150085F811 /* AddSiteViewController~ipad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "AddSiteViewController~ipad.xib"; path = "Resources-iPad/Classes/AddSiteViewController~ipad.xib"; sourceTree = "<group>"; };
43D045271565BC150085F811 /* AddSiteAutocompleteCell~ipad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "AddSiteAutocompleteCell~ipad.xib"; path = "Resources-iPad/Classes/AddSiteAutocompleteCell~ipad.xib"; sourceTree = SOURCE_ROOT; };
43D045281565BC150085F811 /* MoveSiteViewController~ipad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MoveSiteViewController~ipad.xib"; path = "Resources-iPad/Classes/MoveSiteViewController~ipad.xib"; sourceTree = "<group>"; };
43D818A115B940C200733444 /* DataUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataUtilities.h; sourceTree = "<group>"; };
43D818A215B940C200733444 /* DataUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DataUtilities.m; sourceTree = "<group>"; };
43E8855F15951F930032022E /* reader.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; name = reader.css; path = ../reader.css; sourceTree = "<group>"; };
43F44B1A159D8D7200F48F8A /* FeedTableCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FeedTableCell.h; sourceTree = "<group>"; };
43F44B1B159D8D7200F48F8A /* FeedTableCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FeedTableCell.m; sourceTree = "<group>"; };
@ -754,6 +757,7 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
43D8189F15B9404D00733444 /* Models */,
437F974715ACA0C50007136B /* Dashboard */,
431B857415A1324200DCE497 /* Story */,
431B857315A131C300DCE497 /* Feeds */,
@ -764,6 +768,8 @@
FFD1D7301459B63500E46F89 /* BaseViewController.m */,
FFE5322D144C8AC300ACFDE0 /* Utilities.h */,
FFE5322E144C8AC300ACFDE0 /* Utilities.m */,
43D818A115B940C200733444 /* DataUtilities.h */,
43D818A215B940C200733444 /* DataUtilities.m */,
);
path = Classes;
sourceTree = "<group>";
@ -1176,6 +1182,13 @@
name = "Resources-iPad";
sourceTree = "<group>";
};
43D8189F15B9404D00733444 /* Models */ = {
isa = PBXGroup;
children = (
);
name = Models;
sourceTree = "<group>";
};
78095E23128EF30C00230C8E /* ASI */ = {
isa = PBXGroup;
children = (
@ -1911,6 +1924,7 @@
43A3914B15B73A7B0074B212 /* AFURLConnectionOperation.m in Sources */,
43A3914C15B73A7B0074B212 /* AFXMLRequestOperation.m in Sources */,
43A3914D15B73A7B0074B212 /* UIImageView+AFNetworking.m in Sources */,
43D818A315B940C200733444 /* DataUtilities.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -12,10 +12,10 @@
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define BACKGROUND_REFRESH_SECONDS -5
// #define BACKGROUND_REFRESH_SECONDS -10*60
// f#define BACKGROUND_REFRESH_SECONDS -5
#define BACKGROUND_REFRESH_SECONDS -10*60
#define NEWSBLUR_URL [NSString stringWithFormat:@"nb.local.host:8000"]
#define NEWSBLUR_URL [NSString stringWithFormat:@"nb.local.host"]
// #define NEWSBLUR_URL [NSString stringWithFormat:@"dev.newsblur.com"]
#define NEWSBLUR_ORANGE 0xAE5D15