Skip to content

Commit 03f6174

Browse files
committed
文件 - 添加/删除 评论
1 parent 00b95ef commit 03f6174

4 files changed

Lines changed: 64 additions & 40 deletions

File tree

Coding_iOS/Controllers/FileActivitiesViewController.m

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
@interface FileActivitiesViewController ()<UITableViewDataSource, UITableViewDelegate, TTTAttributedLabelDelegate, EaseToolBarDelegate>
2424
@property (strong, nonatomic) ProjectFile *curFile;
25-
@property (strong, nonatomic) Project *curProject;
2625
@property (strong, nonatomic) NSMutableArray *activityList;
2726

2827
@property (strong, nonatomic) UITableView *myTableView;
@@ -39,17 +38,6 @@ + (instancetype)vcWithFile:(ProjectFile *)file{
3938
return vc;
4039
}
4140

42-
- (void)setCurFile:(ProjectFile *)curFile{
43-
_curFile = curFile;
44-
if (!_curProject) {
45-
NSString *project_id_str = [[[[_curFile.owner_preview componentsSeparatedByString:@"project/"] lastObject] componentsSeparatedByString:@"/"] firstObject];
46-
if (project_id_str.length > 0 && [project_id_str isPureInt]) {
47-
_curProject = [Project new];
48-
_curProject.id = [NSNumber numberWithInteger:project_id_str.integerValue];
49-
}
50-
}
51-
}
52-
5341
- (void)viewDidLoad
5442
{
5543
[super viewDidLoad];
@@ -194,52 +182,59 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
194182
}else if ([title isEqualToString:@"删除"]){
195183
[weakSelf deleteCommentOfActivity:curActivity];
196184
}else if ([title isEqualToString:@"回复"]){
197-
[weakSelf goToAddCommentVCToUser:curActivity.projectFileComment.owner.name];
185+
[weakSelf goToAddCommentVCToActivity:curActivity];
198186
}
199187
}];
200188
}
201189

202190

203191
#pragma mark Comment
204-
- (void)goToAddCommentVCToUser:(NSString *)userName{
205-
DebugLog(@"%@", userName);
192+
- (void)goToAddCommentVCToActivity:(ProjectActivity *)curActivity{
193+
Project *curProject;
194+
if (curActivity.project) {
195+
curProject = curActivity.project;
196+
}
197+
if (!curProject && _activityList.count > 0) {
198+
curProject = [(ProjectActivity *)[_activityList firstObject] project];
199+
}
200+
if (!curProject) {
201+
curProject = [Project new];
202+
}
203+
curProject.id = _curFile.project_id;
204+
206205
AddMDCommentViewController *vc = [AddMDCommentViewController new];
206+
207+
vc.curProject = curProject;
207208

208-
// vc.curProject = _curProject;
209-
// vc.requestPath = [NSString stringWithFormat:@"api/user/%@/project/%@/git/line_notes", _curMRPR.des_owner_name, _curMRPR.des_project_name];
210-
// vc.requestParams = [@{
211-
// @"noteable_type" : [self.curMRPRInfo.mrpr isMR]? @"MergeRequestBean" : @"PullRequestBean",
212-
// @"noteable_id" : _curMRPRInfo.mrpr.id,
213-
// } mutableCopy];
214-
// vc.contentStr = userName.length > 0? [NSString stringWithFormat:@"@%@ ", userName]: nil;
215-
// @weakify(self);
216-
// vc.completeBlock = ^(id data){
217-
// @strongify(self);
218-
// if (data && [data isKindOfClass:[ProjectLineNote class]]) {
219-
// [self.curMRPRInfo.discussions addObject:@[data]];
220-
// [self.myTableView reloadData];
221-
// }
222-
// };
209+
vc.requestPath = [NSString stringWithFormat:@"api/project/%@/files/%@/comment", _curFile.project_id.stringValue, _curFile.file_id.stringValue];
210+
vc.requestParams = [@{} mutableCopy];
211+
vc.contentStr = curActivity? [NSString stringWithFormat:@"@%@ ", curActivity.user.name]: nil;
223212

213+
@weakify(self);
214+
vc.completeBlock = ^(id data){
215+
@strongify(self);
216+
if (data) {
217+
[self refresh];
218+
}
219+
};
224220
[self.navigationController pushViewController:vc animated:YES];
225221
}
226222

227223

228-
- (void)deleteCommentOfActivity:(ProjectActivity *)lineNote{
229-
// __weak typeof(self) weakSelf = self;
230-
// [[Coding_NetAPIManager sharedManager] request_DeleteLineNote:lineNote.id inProject:_curMRPRInfo.mrpr.des_project_name ofUser:_curMRPRInfo.mrpr.des_owner_name andBlock:^(id data, NSError *error) {
231-
// if (data) {
232-
// [weakSelf.curMRPRInfo.discussions removeObject:@[lineNote]];
233-
// [weakSelf.myTableView reloadData];
234-
// }
235-
// }];
224+
- (void)deleteCommentOfActivity:(ProjectActivity *)curActivity{
225+
__weak typeof(self) weakSelf = self;
226+
[[Coding_NetAPIManager sharedManager] request_DeleteComment:curActivity.projectFileComment.id inFile:_curFile andBlock:^(id data, NSError *error) {
227+
if (data) {
228+
[weakSelf.activityList removeObject:curActivity];
229+
[weakSelf.myTableView reloadData];
230+
}
231+
}];
236232
}
237233

238-
239234
#pragma mark EaseToolBarDelegate
240235
- (void)easeToolBar:(EaseToolBar *)toolBar didClickedIndex:(NSInteger)index{
241236
//去添加评论
242-
237+
[self goToAddCommentVCToActivity:nil];
243238
}
244239

245240
@end

Coding_iOS/Models/Project.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ - (instancetype)init
1919
}
2020
return self;
2121
}
22+
23+
- (void)setFull_name:(NSString *)full_name{
24+
_full_name = full_name;
25+
NSArray *components = [_full_name componentsSeparatedByString:@"/"];
26+
if (components.count == 2) {
27+
if (!_owner_user_name) {
28+
_owner_user_name = components[0];
29+
}
30+
if (_name) {
31+
_name = components[1];
32+
}
33+
}
34+
}
35+
2236
+(Project *)project_All{
2337
Project *pro = [[Project alloc] init];
2438
pro.id = [NSNumber numberWithInteger:-1];

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ typedef NS_ENUM(NSUInteger, VerifyType){
101101
- (void)request_FileDetail:(ProjectFile *)file andBlock:(void (^)(id data, NSError *error))block;
102102
- (void)request_ActivityListOfFile:(ProjectFile *)file andBlock:(void (^)(id data, NSError *error))block;
103103
- (void)request_VersionListOfFile:(ProjectFile *)file andBlock:(void (^)(id data, NSError *error))block;
104+
- (void)request_DeleteComment:(NSNumber *)comment_id inFile:(ProjectFile *)file andBlock:(void (^)(id data, NSError *error))block;
105+
104106
//Code
105107
- (void)request_CodeTree:(CodeTree *)codeTree withPro:(Project *)project codeTreeBlock:(void (^)(id codeTreeData, NSError *codeTreeError))block;
106108
- (void)request_CodeFile:(CodeFile *)codeFile withPro:(Project *)project andBlock:(void (^)(id data, NSError *error))block;

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,19 @@ - (void)request_VersionListOfFile:(ProjectFile *)file andBlock:(void (^)(id data
789789
}
790790
}];
791791
}
792+
793+
- (void)request_DeleteComment:(NSNumber *)comment_id inFile:(ProjectFile *)file andBlock:(void (^)(id data, NSError *error))block{
794+
[MobClick event:kUmeng_Event_Request label:@"文件删除评论"];
795+
NSString *path = [NSString stringWithFormat:@"api/project/%@/files/%@/comment/%@", file.project_id.stringValue, file.file_id.stringValue, comment_id.stringValue];
796+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:nil withMethodType:Delete andBlock:^(id data, NSError *error) {
797+
if (data) {
798+
block(data, nil);
799+
}else{
800+
block(nil, error);
801+
}
802+
}];
803+
}
804+
792805
#pragma mark Code
793806
- (void)request_CodeTree:(CodeTree *)codeTree withPro:(Project *)project codeTreeBlock:(void (^)(id codeTreeData, NSError *codeTreeError))block{
794807
[MobClick event:kUmeng_Event_Request label:@"代码目录"];

0 commit comments

Comments
 (0)