@@ -1666,63 +1666,61 @@ - (void)request_Tweet_DoComment_WithObj:(Tweet *)tweet andBlock:(void (^)(id dat
1666
1666
}];
1667
1667
}
1668
1668
- (void)request_Tweet_DoTweet_WithObj:(Tweet *)tweet andBlock:(void (^)(id data, NSError *error))block{
1669
- if (tweet.tweetImages && tweet.tweetImages.count > 0) {
1670
- /**
1671
- * 冒泡多张一起发送,不显示进度条
1672
- */
1673
- [NSObject showStatusBarQueryStr:@"正在发送冒泡"];
1674
- for (int i=0; i < tweet.tweetImages.count; i++) {
1675
- TweetImage *imageItem = [tweet.tweetImages objectAtIndex:i];
1676
- if (imageItem.uploadState == TweetImageUploadStateInit) {
1677
- imageItem.uploadState = TweetImageUploadStateIng;
1678
- [self uploadTweetImage:imageItem.image doneBlock:^(NSString *imagePath, NSError *error) {
1679
- if (imagePath) {
1680
- imageItem.uploadState = TweetImageUploadStateSuccess;
1681
- imageItem.imageStr = [NSString stringWithFormat:@"  ", imagePath];
1682
- }else{
1683
- [NSObject showStatusBarError:error];
1684
- imageItem.uploadState = TweetImageUploadStateFail;
1685
- imageItem.imageStr = [NSString stringWithFormat:@" ![图片]() "];
1686
- block(nil, error);
1687
- return ;
1688
- }
1689
- if ([tweet isAllImagesHaveDone]) {
1690
- [[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/tweet" withParams:[tweet toDoTweetParams] withMethodType:Post andBlock:^(id data, NSError *error) {
1691
- if (data) {
1692
- [MobClick event:kUmeng_Event_Request_ActionOfServer label:@"冒泡_添加_有图"];
1693
-
1694
- id resultData = [data valueForKeyPath:@"data"];
1695
- Tweet *tweet = [NSObject objectOfClass:@"Tweet" fromJSON:resultData];
1696
- [NSObject showStatusBarSuccessStr:@"冒泡发送成功"];
1697
- block(tweet, nil);
1698
- }else{
1699
- [NSObject showStatusBarError:error];
1700
- block(nil, error);
1701
- }
1702
- }];
1703
- }
1704
- } progerssBlock:^(CGFloat progressValue) {
1705
- DebugLog(@"progressValue %d : %.2f", i, progressValue);
1706
- }];
1707
- }
1708
- }
1709
- // -----------------
1710
-
1711
- }else{
1712
- [NSObject showStatusBarQueryStr:@"正在发送冒泡"];
1669
+ //发送冒泡内容 block
1670
+ void (^sendTweetBlock)() = ^{
1713
1671
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/tweet" withParams:[tweet toDoTweetParams] withMethodType:Post andBlock:^(id data, NSError *error) {
1714
1672
if (data) {
1715
- [MobClick event:kUmeng_Event_Request_ActionOfServer label:@"冒泡_添加_无图"];
1716
-
1673
+ [MobClick event:kUmeng_Event_Request_ActionOfServer label:tweet.tweetImages.count > 0? @"冒泡_添加_有图": @"冒泡_添加_无图"];
1674
+
1717
1675
id resultData = [data valueForKeyPath:@"data"];
1718
- Tweet *tweet = [NSObject objectOfClass:@"Tweet" fromJSON:resultData];
1676
+ Tweet *result = [NSObject objectOfClass:@"Tweet" fromJSON:resultData];
1719
1677
[NSObject showStatusBarSuccessStr:@"冒泡发送成功"];
1720
- block(tweet , nil);
1678
+ block(result , nil);
1721
1679
}else{
1722
1680
[NSObject showStatusBarError:error];
1723
1681
block(nil, error);
1724
1682
}
1725
1683
}];
1684
+ };
1685
+ //开始发送
1686
+ [NSObject showStatusBarQueryStr:@"正在发送冒泡"];
1687
+ //无图片的冒泡,直接发送
1688
+ if (tweet.tweetImages.count <= 0) {
1689
+ sendTweetBlock();
1690
+ return;
1691
+ }
1692
+ //判断图片是否全部上传完毕,是的话就发送该冒泡 block
1693
+ BOOL (^whetherAllImagesUploadedAndSendTweetBlock)() = ^{
1694
+ if (tweet.isAllImagesDoneSucess) {
1695
+ sendTweetBlock();
1696
+ }
1697
+ return tweet.isAllImagesDoneSucess;
1698
+ };
1699
+ //图片均已上传,直接发送
1700
+ if (whetherAllImagesUploadedAndSendTweetBlock()) {
1701
+ return;
1702
+ }
1703
+ //遍历上传图片
1704
+ for (TweetImage *imageItem in tweet.tweetImages) {
1705
+ if (imageItem.imageStr.length > 0) {
1706
+ whetherAllImagesUploadedAndSendTweetBlock();
1707
+ }else{
1708
+ if (imageItem.uploadState != TweetImageUploadStateIng) {
1709
+ imageItem.uploadState = TweetImageUploadStateIng;
1710
+ [self uploadTweetImage:imageItem.image doneBlock:^(NSString *imagePath, NSError *error) {
1711
+ imageItem.uploadState = imagePath? TweetImageUploadStateSuccess: TweetImageUploadStateFail;
1712
+ if (!imagePath) {
1713
+ [NSObject showStatusBarError:error];
1714
+ block(nil, error);
1715
+ }else{
1716
+ imageItem.imageStr = [NSString stringWithFormat:@"", imagePath];
1717
+ whetherAllImagesUploadedAndSendTweetBlock();
1718
+ }
1719
+ } progerssBlock:^(CGFloat progressValue) {
1720
+ DebugLog(@"progressValue %@ : %.2f", imageItem.assetURL.query, progressValue);
1721
+ }];
1722
+ }
1723
+ }
1726
1724
}
1727
1725
}
1728
1726
0 commit comments