2012-06-21 11:53:48 -07:00
|
|
|
//
|
|
|
|
// ShareViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Roy Yang on 6/21/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ShareViewController.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-06-22 22:57:17 -07:00
|
|
|
#import "StoryDetailViewController.h"
|
2012-11-28 15:46:11 -08:00
|
|
|
#import "FeedDetailViewController.h"
|
2012-11-09 14:13:44 -08:00
|
|
|
#import "StoryPageControl.h"
|
2012-06-22 11:52:10 -07:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2012-06-24 18:55:57 -07:00
|
|
|
#import "Utilities.h"
|
2012-07-20 15:54:10 -07:00
|
|
|
#import "DataUtilities.h"
|
2012-06-22 11:52:10 -07:00
|
|
|
#import "ASIHTTPRequest.h"
|
2014-02-12 20:09:37 -08:00
|
|
|
#import "StoriesCollection.h"
|
2014-02-26 18:01:01 -08:00
|
|
|
#import "NSString+HTML.h"
|
2012-06-21 11:53:48 -07:00
|
|
|
|
|
|
|
@implementation ShareViewController
|
2012-07-12 13:34:41 -07:00
|
|
|
|
2012-06-24 20:08:39 -07:00
|
|
|
@synthesize facebookButton;
|
|
|
|
@synthesize twitterButton;
|
2013-03-02 19:15:08 -08:00
|
|
|
@synthesize appdotnetButton;
|
2012-06-25 18:05:25 -07:00
|
|
|
@synthesize submitButton;
|
2012-06-22 11:52:10 -07:00
|
|
|
@synthesize commentField;
|
2012-06-21 11:53:48 -07:00
|
|
|
@synthesize appDelegate;
|
2012-07-30 14:58:57 -07:00
|
|
|
@synthesize activeReplyId;
|
2013-09-23 15:07:25 -07:00
|
|
|
@synthesize activeCommentId;
|
2013-09-25 12:05:17 -07:00
|
|
|
@synthesize activeStoryId;
|
2012-08-13 23:54:10 -07:00
|
|
|
@synthesize currentType;
|
2013-03-02 19:15:08 -08:00
|
|
|
@synthesize storyTitle;
|
2012-06-21 11:53:48 -07:00
|
|
|
|
2012-08-02 00:57:01 -07:00
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
|
|
|
{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (self) {
|
|
|
|
// Custom initialization
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-08-13 18:45:06 -07:00
|
|
|
- (void)viewDidLoad {
|
|
|
|
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
2012-08-03 00:13:56 -07:00
|
|
|
|
2012-08-08 13:48:10 -07:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(onTextChange:)
|
|
|
|
name:UITextViewTextDidChangeNotification
|
|
|
|
object:self.commentField];
|
|
|
|
|
2012-11-28 15:21:44 -08:00
|
|
|
UIBarButtonItem *cancel = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Cancel"
|
|
|
|
style:UIBarButtonSystemItemCancel
|
|
|
|
target:self
|
|
|
|
action:@selector(doCancelButton:)];
|
2012-08-03 00:13:56 -07:00
|
|
|
self.navigationItem.leftBarButtonItem = cancel;
|
|
|
|
|
2012-11-28 15:21:44 -08:00
|
|
|
UIBarButtonItem *submit = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"Post"
|
|
|
|
style:UIBarButtonSystemItemDone
|
|
|
|
target:self
|
|
|
|
action:@selector(doShareThisStory:)];
|
2012-08-03 00:13:56 -07:00
|
|
|
self.submitButton = submit;
|
|
|
|
self.navigationItem.rightBarButtonItem = submit;
|
|
|
|
|
|
|
|
|
2012-06-21 11:53:48 -07:00
|
|
|
// Do any additional setup after loading the view from its nib.
|
2012-06-22 11:52:10 -07:00
|
|
|
commentField.layer.borderWidth = 1.0f;
|
2012-08-13 20:09:43 -07:00
|
|
|
commentField.layer.cornerRadius = 4;
|
2012-06-22 11:52:10 -07:00
|
|
|
commentField.layer.borderColor = [[UIColor grayColor] CGColor];
|
2012-06-24 20:08:39 -07:00
|
|
|
|
2013-03-02 19:15:08 -08:00
|
|
|
twitterButton.layer.borderWidth = 1.0f;
|
|
|
|
twitterButton.layer.cornerRadius = 1.0f;
|
|
|
|
facebookButton.layer.borderWidth = 1.0f;
|
|
|
|
facebookButton.layer.cornerRadius = 1.0f;
|
|
|
|
appdotnetButton.layer.borderWidth = 1.0f;
|
|
|
|
appdotnetButton.layer.cornerRadius = 1.0f;
|
2012-07-12 23:44:14 -07:00
|
|
|
|
2012-07-20 18:04:54 -07:00
|
|
|
[super viewDidLoad];
|
2012-06-21 11:53:48 -07:00
|
|
|
}
|
|
|
|
|
2012-08-08 13:48:10 -07:00
|
|
|
- (void)dealloc {
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:21:44 -08:00
|
|
|
- (void)viewDidUnload {
|
2012-06-22 11:52:10 -07:00
|
|
|
[self setCommentField:nil];
|
2012-06-24 20:08:39 -07:00
|
|
|
[self setFacebookButton:nil];
|
|
|
|
[self setTwitterButton:nil];
|
2012-06-25 18:05:25 -07:00
|
|
|
[self setSubmitButton:nil];
|
2012-06-21 11:53:48 -07:00
|
|
|
[super viewDidUnload];
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
|
|
|
}
|
|
|
|
|
2012-07-12 13:34:41 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
2012-06-21 11:53:48 -07:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2012-08-07 11:27:00 -07:00
|
|
|
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
|
|
|
|
[self adjustCommentField];
|
|
|
|
}
|
|
|
|
|
2012-07-26 10:17:08 -07:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2013-03-02 19:59:21 -08:00
|
|
|
[self adjustCommentField];
|
2013-03-05 09:25:42 -08:00
|
|
|
[self adjustShareButtons];
|
|
|
|
|
2012-07-26 10:17:08 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
2014-02-26 18:01:01 -08:00
|
|
|
self.storyTitle.text = [[appDelegate.activeStory objectForKey:@"story_title"]
|
|
|
|
stringByDecodingHTMLEntities];
|
2012-07-26 10:17:08 -07:00
|
|
|
[self.commentField becomeFirstResponder];
|
2013-03-02 19:15:08 -08:00
|
|
|
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",
|
|
|
|
[appDelegate.activeStory objectForKey:@"story_feed_id"]];
|
2014-02-24 18:56:51 -08:00
|
|
|
UIImage *titleImage = [appDelegate getFavicon:feedIdStr];
|
2013-03-02 19:15:08 -08:00
|
|
|
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:titleImage];
|
|
|
|
titleImageView.frame = CGRectMake(0.0, 2.0, 16.0, 16.0);
|
|
|
|
titleImageView.hidden = YES;
|
|
|
|
titleImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
self.navigationItem.titleView = titleImageView;
|
|
|
|
titleImageView.hidden = NO;
|
2012-08-07 11:27:00 -07:00
|
|
|
}
|
2013-03-05 09:25:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)adjustShareButtons {
|
2013-03-04 20:21:29 -08:00
|
|
|
if (twitterButton.selected &&
|
|
|
|
[[[appDelegate.dictSocialServices objectForKey:@"twitter"]
|
|
|
|
objectForKey:@"twitter_uid"] class] == [NSNull class]) {
|
|
|
|
[self doToggleButton:twitterButton];
|
2013-03-05 09:25:42 -08:00
|
|
|
} else {
|
|
|
|
twitterButton.selected = NO;
|
|
|
|
twitterButton.layer.borderColor = [UIColorFromRGB(0xD9DBD6) CGColor];
|
2013-03-04 20:21:29 -08:00
|
|
|
}
|
2013-03-05 09:25:42 -08:00
|
|
|
|
2013-03-04 20:21:29 -08:00
|
|
|
if (facebookButton.selected &&
|
|
|
|
[[[appDelegate.dictSocialServices objectForKey:@"facebook"]
|
|
|
|
objectForKey:@"facebook_uid"] class] == [NSNull class]) {
|
|
|
|
[self doToggleButton:facebookButton];
|
2013-03-05 09:25:42 -08:00
|
|
|
} else {
|
|
|
|
facebookButton.selected = NO;
|
|
|
|
facebookButton.layer.borderColor = [UIColorFromRGB(0xD9DBD6) CGColor];
|
2013-03-04 20:21:29 -08:00
|
|
|
}
|
2013-03-05 09:25:42 -08:00
|
|
|
|
2013-03-04 20:21:29 -08:00
|
|
|
if (appdotnetButton.selected &&
|
|
|
|
[[[appDelegate.dictSocialServices objectForKey:@"appdotnet"]
|
|
|
|
objectForKey:@"appdotnet_uid"] class] == [NSNull class]) {
|
|
|
|
[self doToggleButton:appdotnetButton];
|
2013-03-05 09:25:42 -08:00
|
|
|
} else {
|
|
|
|
appdotnetButton.selected = NO;
|
|
|
|
appdotnetButton.layer.borderColor = [UIColorFromRGB(0xD9DBD6) CGColor];
|
2013-03-04 20:21:29 -08:00
|
|
|
}
|
2012-08-07 11:27:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)adjustCommentField {
|
2013-03-02 19:59:21 -08:00
|
|
|
CGSize v = self.view.frame.size;
|
|
|
|
int bP = 8;
|
|
|
|
int bW = 32;
|
|
|
|
int bH = 24;
|
|
|
|
int k = 0;
|
|
|
|
int stOffset = 6;
|
|
|
|
int stHeight = 0;
|
|
|
|
|
2013-03-02 19:15:08 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[UIApplication sharedApplication]
|
|
|
|
statusBarOrientation];
|
2013-03-02 19:59:21 -08:00
|
|
|
k = UIInterfaceOrientationIsPortrait(orientation) ? 216 : 162;
|
|
|
|
self.storyTitle.frame = CGRectMake(20, 8, v.width - 20*2, 24);
|
|
|
|
stOffset = self.storyTitle.frame.origin.y + self.storyTitle.frame.size.height;
|
|
|
|
stHeight = self.storyTitle.frame.size.height;
|
2012-07-26 10:17:08 -07:00
|
|
|
}
|
2013-03-02 21:27:29 -08:00
|
|
|
NSLog(@"Share type: %@", self.currentType);
|
|
|
|
BOOL showingShareButtons = [self.currentType isEqualToString:@"share"] ||
|
|
|
|
[self.currentType isEqualToString:@"edit-share"];
|
2013-03-02 19:59:21 -08:00
|
|
|
self.commentField.frame = CGRectMake(20, stOffset + 4,
|
|
|
|
v.width - 20*2,
|
2013-03-02 21:27:29 -08:00
|
|
|
v.height - k - (showingShareButtons ? bH + bP*2 : 6) - 12 - stHeight);
|
2013-03-02 19:59:21 -08:00
|
|
|
CGPoint o = self.commentField.frame.origin;
|
|
|
|
CGSize c = self.commentField.frame.size;
|
|
|
|
self.twitterButton.frame = CGRectMake(v.width - 20 - bW*3 - bP*2, o.y + c.height + bP, bW, bH);
|
|
|
|
self.facebookButton.frame = CGRectMake(v.width - 20 - bW*2 - bP*1, o.y + c.height + bP, bW, bH);
|
|
|
|
self.appdotnetButton.frame = CGRectMake(v.width - 20 - bW*1 - bP*0, o.y + c.height + bP, bW, bH);
|
2013-09-25 12:05:17 -07:00
|
|
|
|
|
|
|
[self onTextChange:nil];
|
2012-06-21 11:53:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)doCancelButton:(id)sender {
|
2012-07-12 13:34:41 -07:00
|
|
|
[appDelegate hideShareView:NO];
|
2012-06-21 11:53:48 -07:00
|
|
|
}
|
2012-06-22 11:52:10 -07:00
|
|
|
|
|
|
|
- (IBAction)doToggleButton:(id)sender {
|
|
|
|
UIButton *button = (UIButton *)sender;
|
2012-11-19 19:15:05 -08:00
|
|
|
button.selected = !button.selected;
|
|
|
|
int selected = button.selected ? 1 : 0;
|
|
|
|
|
2013-03-04 20:21:29 -08:00
|
|
|
if (button.tag == 1) { // Twitter
|
2013-03-02 19:15:08 -08:00
|
|
|
if (selected) {
|
2013-03-04 20:21:29 -08:00
|
|
|
[self checkService:@"twitter"];
|
2013-03-02 19:15:08 -08:00
|
|
|
button.layer.borderColor = [UIColorFromRGB(0x4E8ECD) CGColor];
|
|
|
|
} else {
|
|
|
|
button.layer.borderColor = [UIColorFromRGB(0xD9DBD6) CGColor];
|
|
|
|
}
|
2013-03-04 20:21:29 -08:00
|
|
|
} else if (button.tag == 2) { // Facebook
|
2013-03-02 19:15:08 -08:00
|
|
|
if (selected) {
|
2013-03-04 20:21:29 -08:00
|
|
|
[self checkService:@"facebook"];
|
2013-03-02 19:15:08 -08:00
|
|
|
button.layer.borderColor = [UIColorFromRGB(0x6884CD) CGColor];
|
|
|
|
} else {
|
|
|
|
button.layer.borderColor = [UIColorFromRGB(0xD9DBD6) CGColor];
|
|
|
|
}
|
2013-03-04 20:21:29 -08:00
|
|
|
} else if (button.tag == 3) { // App.net
|
2013-03-02 19:15:08 -08:00
|
|
|
if (selected) {
|
2013-03-04 20:21:29 -08:00
|
|
|
[self checkService:@"appdotnet"];
|
2013-03-02 19:15:08 -08:00
|
|
|
button.layer.borderColor = [UIColorFromRGB(0xD16857) CGColor];
|
|
|
|
} else {
|
|
|
|
button.layer.borderColor = [UIColorFromRGB(0xD9DBD6) CGColor];
|
|
|
|
}
|
2012-06-22 11:52:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:21:29 -08:00
|
|
|
- (void)checkService:(NSString *)service {
|
|
|
|
if ([service isEqualToString:@"twitter"] &&
|
|
|
|
[[[appDelegate.dictSocialServices objectForKey:@"twitter"]
|
|
|
|
objectForKey:@"twitter_uid"] class] == [NSNull class]) {
|
|
|
|
[appDelegate showConnectToService:service];
|
|
|
|
} else if ([service isEqualToString:@"facebook"] &&
|
|
|
|
[[[appDelegate.dictSocialServices objectForKey:@"facebook"]
|
|
|
|
objectForKey:@"facebook_uid"] class] == [NSNull class]) {
|
|
|
|
[appDelegate showConnectToService:service];
|
|
|
|
} else if ([service isEqualToString:@"appdotnet"] &&
|
|
|
|
[[[appDelegate.dictSocialServices objectForKey:@"appdotnet"]
|
|
|
|
objectForKey:@"appdotnet_uid"] class] == [NSNull class]) {
|
|
|
|
[appDelegate showConnectToService:service];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-02 21:27:29 -08:00
|
|
|
- (void)setCommentType:(NSString *)type {
|
|
|
|
self.currentType = type;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:21:44 -08:00
|
|
|
- (void)setSiteInfo:(NSString *)type
|
|
|
|
setUserId:(NSString *)userId
|
|
|
|
setUsername:(NSString *)username
|
|
|
|
setReplyId:(NSString *)replyId {
|
2013-03-02 21:27:29 -08:00
|
|
|
NSLog(@"SetSiteInfo: %@", type);
|
2012-08-13 18:45:06 -07:00
|
|
|
[self.submitButton setStyle:UIBarButtonItemStyleDone];
|
2012-07-20 15:54:10 -07:00
|
|
|
if ([type isEqualToString: @"edit-reply"]) {
|
2012-08-13 19:46:47 -07:00
|
|
|
[submitButton setTitle:@"Save your reply"];
|
2012-07-20 15:54:10 -07:00
|
|
|
facebookButton.hidden = YES;
|
|
|
|
twitterButton.hidden = YES;
|
2013-03-02 19:15:08 -08:00
|
|
|
appdotnetButton.hidden = YES;
|
2012-07-20 15:54:10 -07:00
|
|
|
[submitButton setAction:(@selector(doReplyToComment:))];
|
2012-07-30 14:58:57 -07:00
|
|
|
self.activeReplyId = replyId;
|
2012-07-20 18:04:54 -07:00
|
|
|
|
2012-07-30 14:58:57 -07:00
|
|
|
// get existing reply
|
2012-07-20 15:54:10 -07:00
|
|
|
NSArray *replies = [appDelegate.activeComment objectForKey:@"replies"];
|
2012-07-30 14:58:57 -07:00
|
|
|
NSDictionary *reply = nil;
|
|
|
|
for (int i = 0; i < replies.count; i++) {
|
2012-11-28 15:21:44 -08:00
|
|
|
NSString *replyId = [NSString stringWithFormat:@"%@",
|
|
|
|
[[replies objectAtIndex:i] valueForKey:@"reply_id"]];
|
2012-07-30 14:58:57 -07:00
|
|
|
if ([replyId isEqualToString:self.activeReplyId]) {
|
|
|
|
reply = [replies objectAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reply) {
|
|
|
|
self.commentField.text = [self stringByStrippingHTML:[reply objectForKey:@"comments"]];
|
|
|
|
}
|
2012-07-20 15:54:10 -07:00
|
|
|
} else if ([type isEqualToString: @"reply"]) {
|
2012-07-30 14:58:57 -07:00
|
|
|
self.activeReplyId = nil;
|
2012-08-13 19:46:47 -07:00
|
|
|
[submitButton setTitle:[NSString stringWithFormat:@"Reply to %@", username]];
|
2012-07-12 22:05:23 -07:00
|
|
|
facebookButton.hidden = YES;
|
|
|
|
twitterButton.hidden = YES;
|
2013-03-02 19:59:21 -08:00
|
|
|
appdotnetButton.hidden = YES;
|
2012-06-25 18:05:25 -07:00
|
|
|
[submitButton setAction:(@selector(doReplyToComment:))];
|
2012-08-13 23:54:10 -07:00
|
|
|
|
2013-09-23 15:07:25 -07:00
|
|
|
// Don't bother to reset comment field for replies while on the same story.
|
|
|
|
// It'll get cleared out on a new story and when posting a reply.
|
2013-09-25 12:05:17 -07:00
|
|
|
if (!self.activeCommentId || ![self.activeCommentId isEqualToString:userId] ||
|
2014-02-12 20:41:29 -08:00
|
|
|
!self.activeStoryId || ![self.activeStoryId isEqualToString:[appDelegate.activeStory objectForKey:@"story_hash"]]) {
|
2013-09-23 15:07:25 -07:00
|
|
|
self.activeCommentId = userId;
|
2014-02-12 20:41:29 -08:00
|
|
|
self.activeStoryId = [appDelegate.activeStory objectForKey:@"story_hash"];
|
2013-09-23 15:07:25 -07:00
|
|
|
self.commentField.text = @"";
|
|
|
|
}
|
2012-07-20 15:54:10 -07:00
|
|
|
} else if ([type isEqualToString: @"edit-share"]) {
|
|
|
|
facebookButton.hidden = NO;
|
|
|
|
twitterButton.hidden = NO;
|
2013-03-02 19:59:21 -08:00
|
|
|
appdotnetButton.hidden = NO;
|
2012-07-20 15:54:10 -07:00
|
|
|
|
|
|
|
// get old comment
|
2012-07-23 16:17:49 -07:00
|
|
|
self.commentField.text = [self stringByStrippingHTML:[appDelegate.activeComment objectForKey:@"comments"]];
|
2012-07-20 15:54:10 -07:00
|
|
|
|
2013-09-25 12:05:17 -07:00
|
|
|
[submitButton setTitle:@"Share with comments"];
|
2012-07-20 15:54:10 -07:00
|
|
|
[submitButton setAction:(@selector(doShareThisStory:))];
|
2012-07-27 12:27:13 -07:00
|
|
|
} else if ([type isEqualToString: @"share"]) {
|
2012-07-12 22:05:23 -07:00
|
|
|
facebookButton.hidden = NO;
|
|
|
|
twitterButton.hidden = NO;
|
2013-03-02 19:59:21 -08:00
|
|
|
appdotnetButton.hidden = NO;
|
2012-08-13 19:46:47 -07:00
|
|
|
[submitButton setTitle:@"Share this story"];
|
2012-06-25 18:05:25 -07:00
|
|
|
[submitButton setAction:(@selector(doShareThisStory:))];
|
2012-08-13 23:54:10 -07:00
|
|
|
if (![self.currentType isEqualToString:@"share"] &&
|
|
|
|
![self.currentType isEqualToString:@"reply"]) {
|
|
|
|
self.commentField.text = @"";
|
|
|
|
}
|
2012-06-25 18:05:25 -07:00
|
|
|
}
|
2012-06-27 15:18:51 -07:00
|
|
|
}
|
2012-06-25 18:05:25 -07:00
|
|
|
|
2012-06-27 15:24:18 -07:00
|
|
|
- (void)clearComments {
|
|
|
|
self.commentField.text = nil;
|
2012-08-13 23:54:10 -07:00
|
|
|
self.currentType = nil;
|
2013-03-02 19:59:21 -08:00
|
|
|
self.twitterButton.selected = NO;
|
|
|
|
self.facebookButton.selected = NO;
|
|
|
|
self.appdotnetButton.selected = NO;
|
2012-06-27 15:24:18 -07:00
|
|
|
}
|
|
|
|
|
2012-07-27 12:27:13 -07:00
|
|
|
# pragma mark
|
|
|
|
# pragma mark Share Story
|
|
|
|
|
|
|
|
- (IBAction)doShareThisStory:(id)sender {
|
2012-11-09 14:13:44 -08:00
|
|
|
[appDelegate.storyPageControl showShareHUD:@"Sharing"];
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/social/share_story",
|
2012-06-22 11:52:10 -07:00
|
|
|
NEWSBLUR_URL];
|
2012-08-06 19:21:39 -07:00
|
|
|
|
2012-07-27 16:48:30 -07:00
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
|
2012-06-22 11:52:10 -07:00
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"story_feed_id"]];
|
|
|
|
NSString *storyIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"id"]];
|
2012-07-26 10:17:08 -07:00
|
|
|
|
2012-06-22 11:52:10 -07:00
|
|
|
[request setPostValue:feedIdStr forKey:@"feed_id"];
|
2012-06-22 22:57:17 -07:00
|
|
|
[request setPostValue:storyIdStr forKey:@"story_id"];
|
2012-08-06 19:21:39 -07:00
|
|
|
|
2013-03-02 19:59:21 -08:00
|
|
|
if (facebookButton.selected) {
|
2012-08-06 19:21:39 -07:00
|
|
|
[request addPostValue:@"facebook" forKey:@"post_to_services"];
|
|
|
|
}
|
2013-03-02 19:59:21 -08:00
|
|
|
if (twitterButton.selected) {
|
|
|
|
[request addPostValue:@"twitter" forKey:@"post_to_services"];
|
|
|
|
}
|
|
|
|
if (appdotnetButton.selected) {
|
|
|
|
[request addPostValue:@"appdotnet" forKey:@"post_to_services"];
|
2012-08-06 19:21:39 -07:00
|
|
|
}
|
2012-08-16 20:10:50 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
if (appDelegate.storiesCollection.isSocialRiverView) {
|
2013-09-28 18:12:46 -07:00
|
|
|
if ([[appDelegate.activeStory objectForKey:@"friend_user_ids"] count] > 0) {
|
|
|
|
[request setPostValue:[NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"friend_user_ids"][0]] forKey:@"source_user_id"];
|
|
|
|
} else if ([[appDelegate.activeStory objectForKey:@"public_user_ids"] count] > 0) {
|
|
|
|
[request setPostValue:[NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"public_user_ids"][0]] forKey:@"source_user_id"];
|
2012-08-16 20:10:50 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ([appDelegate.activeStory objectForKey:@"social_user_id"] != nil) {
|
|
|
|
NSString *sourceUserIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"social_user_id"]];
|
|
|
|
[request setPostValue:sourceUserIdStr forKey:@"source_user_id"];
|
|
|
|
}
|
2012-07-26 10:17:08 -07:00
|
|
|
}
|
2012-08-16 20:10:50 -07:00
|
|
|
|
2012-07-26 10:17:08 -07:00
|
|
|
|
2012-06-22 22:57:17 -07:00
|
|
|
NSString *comments = commentField.text;
|
2012-06-25 18:05:25 -07:00
|
|
|
if ([comments length]) {
|
2012-06-22 22:57:17 -07:00
|
|
|
[request setPostValue:comments forKey:@"comments"];
|
|
|
|
}
|
2012-06-22 11:52:10 -07:00
|
|
|
[request setDelegate:self];
|
2012-07-27 12:27:13 -07:00
|
|
|
[request setDidFinishSelector:@selector(finishShareThisStory:)];
|
2012-06-22 11:52:10 -07:00
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
2012-07-27 12:27:13 -07:00
|
|
|
[appDelegate hideShareView:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishShareThisStory:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
2012-07-27 16:21:44 -07:00
|
|
|
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSError *error;
|
|
|
|
NSDictionary *results = [NSJSONSerialization
|
|
|
|
JSONObjectWithData:responseData
|
|
|
|
options:kNilOptions
|
|
|
|
error:&error];
|
2012-07-27 12:27:13 -07:00
|
|
|
|
2013-09-05 16:34:39 -07:00
|
|
|
if (request.responseStatusCode != 200) {
|
|
|
|
return [self requestFailed:request];
|
|
|
|
}
|
|
|
|
|
2012-08-15 15:38:21 -07:00
|
|
|
NSArray *userProfiles = [results objectForKey:@"user_profiles"];
|
2014-02-12 20:09:37 -08:00
|
|
|
appDelegate.storiesCollection.activeFeedUserProfiles = [DataUtilities
|
|
|
|
updateUserProfiles:appDelegate.storiesCollection.activeFeedUserProfiles
|
|
|
|
withNewUserProfiles:userProfiles];
|
2012-07-30 14:58:57 -07:00
|
|
|
[self replaceStory:[results objectForKey:@"story"] withReplyId:nil];
|
2013-09-26 19:26:10 -07:00
|
|
|
[appDelegate.feedDetailViewController redrawUnreadStory];
|
2012-06-22 11:52:10 -07:00
|
|
|
}
|
|
|
|
|
2012-07-27 12:27:13 -07:00
|
|
|
# pragma mark
|
|
|
|
# pragma mark Reply to Story
|
|
|
|
|
2012-06-25 18:05:25 -07:00
|
|
|
- (IBAction)doReplyToComment:(id)sender {
|
2012-11-09 14:13:44 -08:00
|
|
|
[appDelegate.storyPageControl showShareHUD:@"Replying"];
|
2012-06-25 18:05:25 -07:00
|
|
|
NSString *comments = commentField.text;
|
|
|
|
if ([comments length] == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:58:57 -07:00
|
|
|
// NSLog(@"REPLY TO COMMENT, %@", appDelegate.activeComment);
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/social/save_comment_reply",
|
2012-06-25 18:05:25 -07:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"story_feed_id"]];
|
|
|
|
NSString *storyIdStr = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"id"]];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
[request setPostValue:feedIdStr forKey:@"story_feed_id"];
|
|
|
|
[request setPostValue:storyIdStr forKey:@"story_id"];
|
|
|
|
[request setPostValue:[appDelegate.activeComment objectForKey:@"user_id"] forKey:@"comment_user_id"];
|
|
|
|
[request setPostValue:commentField.text forKey:@"reply_comments"];
|
|
|
|
|
2012-07-30 14:58:57 -07:00
|
|
|
if (self.activeReplyId) {
|
|
|
|
[request setPostValue:activeReplyId forKey:@"reply_id"];
|
2012-07-20 18:04:54 -07:00
|
|
|
}
|
|
|
|
|
2012-06-25 18:05:25 -07:00
|
|
|
[request setDelegate:self];
|
2012-07-20 00:21:24 -07:00
|
|
|
[request setDidFinishSelector:@selector(finishAddReply:)];
|
2012-06-25 18:05:25 -07:00
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request startAsynchronous];
|
2013-09-23 15:07:25 -07:00
|
|
|
[appDelegate hideShareView:NO];
|
2012-06-25 18:05:25 -07:00
|
|
|
}
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
- (void)finishAddReply:(ASIHTTPRequest *)request {
|
|
|
|
NSLog(@"Successfully added.");
|
|
|
|
NSString *responseString = [request responseString];
|
2012-07-27 16:21:44 -07:00
|
|
|
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSError *error;
|
|
|
|
NSDictionary *results = [NSJSONSerialization
|
|
|
|
JSONObjectWithData:responseData
|
|
|
|
options:kNilOptions
|
|
|
|
error:&error];
|
2013-09-05 16:34:39 -07:00
|
|
|
|
|
|
|
if (request.responseStatusCode != 200) {
|
|
|
|
return [self requestFailed:request];
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
// add the comment into the activeStory dictionary
|
2012-07-26 13:54:45 -07:00
|
|
|
NSDictionary *newStory = [DataUtilities updateComment:results for:appDelegate];
|
2012-07-30 14:58:57 -07:00
|
|
|
[self replaceStory:newStory withReplyId:[results objectForKey:@"reply_id"]];
|
2012-07-20 00:21:24 -07:00
|
|
|
}
|
|
|
|
|
2013-03-06 14:29:40 -08:00
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
2013-09-05 16:34:39 -07:00
|
|
|
NSString *error;
|
|
|
|
|
|
|
|
[MBProgressHUD hideHUDForView:appDelegate.storyPageControl.view animated:NO];
|
|
|
|
|
|
|
|
if ([request error]) {
|
|
|
|
error = [NSString stringWithFormat:@"%@", [request error]];
|
|
|
|
} else {
|
|
|
|
error = @"The server barfed!";
|
|
|
|
}
|
2012-07-23 16:17:49 -07:00
|
|
|
NSLog(@"Error: %@", error);
|
2013-09-05 16:34:39 -07:00
|
|
|
[appDelegate.storyPageControl.currentPage informError:error];
|
2012-07-23 16:17:49 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:58:57 -07:00
|
|
|
- (void)replaceStory:(NSDictionary *)newStory withReplyId:(NSString *)replyId {
|
2012-08-07 09:57:21 -07:00
|
|
|
NSMutableDictionary *newStoryParsed = [newStory mutableCopy];
|
|
|
|
[newStoryParsed setValue:[NSNumber numberWithInt:1] forKey:@"read_status"];
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
// update the current story and the activeFeedStories
|
2012-08-07 09:57:21 -07:00
|
|
|
appDelegate.activeStory = newStoryParsed;
|
2014-05-21 12:24:22 -07:00
|
|
|
[appDelegate.storyPageControl.currentPage setActiveStoryAtIndex:-1];
|
|
|
|
|
2012-07-20 00:21:24 -07:00
|
|
|
NSMutableArray *newActiveFeedStories = [[NSMutableArray alloc] init];
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
for (int i = 0; i < appDelegate.storiesCollection.activeFeedStories.count; i++) {
|
|
|
|
NSDictionary *feedStory = [appDelegate.storiesCollection.activeFeedStories objectAtIndex:i];
|
2012-07-15 18:23:08 -07:00
|
|
|
NSString *storyId = [NSString stringWithFormat:@"%@", [feedStory objectForKey:@"id"]];
|
|
|
|
NSString *currentStoryId = [NSString stringWithFormat:@"%@", [appDelegate.activeStory objectForKey:@"id"]];
|
|
|
|
if ([storyId isEqualToString: currentStoryId]){
|
2012-08-07 09:57:21 -07:00
|
|
|
[newActiveFeedStories addObject:newStoryParsed];
|
2012-07-20 00:21:24 -07:00
|
|
|
} else {
|
2014-02-12 20:09:37 -08:00
|
|
|
[newActiveFeedStories addObject:[appDelegate.storiesCollection.activeFeedStories objectAtIndex:i]];
|
2012-07-15 18:23:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
appDelegate.storiesCollection.activeFeedStories = [NSArray arrayWithArray:newActiveFeedStories];
|
2012-07-20 00:21:24 -07:00
|
|
|
|
2012-06-27 15:24:18 -07:00
|
|
|
self.commentField.text = nil;
|
2012-11-13 12:28:16 -08:00
|
|
|
[appDelegate.storyPageControl.currentPage refreshComments:replyId];
|
2012-11-28 15:46:11 -08:00
|
|
|
[appDelegate changeActiveFeedDetailRow];
|
2012-06-22 11:52:10 -07:00
|
|
|
}
|
|
|
|
|
2012-06-22 22:57:17 -07:00
|
|
|
|
2012-07-25 20:38:44 -07:00
|
|
|
- (NSString *)stringByStrippingHTML:(NSString *)s {
|
2012-07-23 16:17:49 -07:00
|
|
|
NSRange r;
|
|
|
|
while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
|
|
|
|
s = [s stringByReplacingCharactersInRange:r withString:@""];
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-08-08 13:48:10 -07:00
|
|
|
-(void)onTextChange:(NSNotification*)notification {
|
|
|
|
NSString *text = self.commentField.text;
|
2013-09-25 12:05:17 -07:00
|
|
|
if ([self.currentType isEqualToString: @"share"] ||
|
|
|
|
[self.currentType isEqualToString:@"edit-share"]) {
|
2012-08-08 13:48:10 -07:00
|
|
|
if (text.length) {
|
2012-08-13 19:46:47 -07:00
|
|
|
self.submitButton.title = @"Share with comments";
|
2012-08-08 13:48:10 -07:00
|
|
|
} else {
|
2012-08-13 18:45:06 -07:00
|
|
|
self.submitButton.title = @"Share this story";
|
2012-08-08 13:48:10 -07:00
|
|
|
}
|
2013-03-05 17:00:03 -08:00
|
|
|
} else if ([self.currentType isEqualToString: @"reply"] ||
|
|
|
|
[self.currentType isEqualToString:@"edit-reply"]) {
|
|
|
|
self.submitButton.enabled = [self.commentField.text length] > 0;
|
2012-08-08 13:48:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2012-06-21 11:53:48 -07:00
|
|
|
@end
|