-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathBaseViewController.m
More file actions
executable file
·1065 lines (996 loc) · 52.6 KB
/
Copy pathBaseViewController.m
File metadata and controls
executable file
·1065 lines (996 loc) · 52.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// BaseViewController.m
// Coding_iOS
//
// Created by 王 原闯 on 14-7-29.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "BaseViewController.h"
#import "ConversationViewController.h"
#import "MRDetailViewController.h"
#import "Login.h"
#import <RegexKitLite-NoWarning/RegexKitLite.h>
#import "UserInfoViewController.h"
#import "TweetDetailViewController.h"
#import "TopicDetailViewController.h"
#import "EditTaskViewController.h"
#import "ProjectViewController.h"
#import "NProjectViewController.h"
#import "UserOrProjectTweetsViewController.h"
#import "Coding_NetAPIManager.h"
#import "AppDelegate.h"
#import "WebViewController.h"
#import "RootTabViewController.h"
#import "Message_RootViewController.h"
#import "WikiViewController.h"
#import "ProjectCommitsViewController.h"
#import "PRDetailViewController.h"
#import "CommitFilesViewController.h"
#import "FileViewController.h"
#import "CSTopicDetailVC.h"
#import "CodeViewController.h"
#import "EACodeReleaseViewController.h"
#import "Ease_2FA.h"
#import "Project_RootViewController.h"
#import "MyTask_RootViewController.h"
#import "Tweet_RootViewController.h"
#import "Message_RootViewController.h"
#import "Me_RootViewController.h"
#import "ProjectViewController.h"
#import "EACodeReleaseListViewController.h"
#import "EACodeBranchListViewController.h"
#import "MRPRListViewController.h"
#import "ProjectSettingViewController.h"
#import "CodeListViewController.h"
#import "NFileListViewController.h"
#import "TeamViewController.h"
#import "UnReadManager.h"
typedef NS_ENUM(NSInteger, AnalyseMethodType) {
AnalyseMethodTypeJustRefresh = 0,
AnalyseMethodTypeLazyCreate,
AnalyseMethodTypeForceCreate
};
#pragma mark - UIViewController (Dismiss)
@interface UIViewController (Dismiss)
- (void)dismissModalVC;
@end
@implementation UIViewController (Dismiss)
- (void)dismissModalVC{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
#pragma mark - BaseViewController
@interface BaseViewController ()
@property (nonatomic ,strong) NSUserActivity *userActivity;
@end
@implementation BaseViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[MobClick beginLogPageView:[NSString stringWithUTF8String:object_getClassName(self)]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
if (UIApplication.sharedApplication.statusBarOrientation != UIInterfaceOrientationPortrait
&& !([self supportedInterfaceOrientations] & UIInterfaceOrientationMaskLandscapeLeft)) {
[self forceChangeToOrientation:UIInterfaceOrientationPortrait];
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[MobClick endLogPageView:[NSString stringWithUTF8String:object_getClassName(self)]];
[_userActivity resignCurrent];
}
- (void)viewDidLoad{
[super viewDidLoad];
// self.view.backgroundColor = kColorTableBG;
self.view.backgroundColor = kColorTableSectionBg;
if (UIApplication.sharedApplication.statusBarOrientation != UIInterfaceOrientationPortrait
&& !([self supportedInterfaceOrientations] & UIInterfaceOrientationMaskLandscapeLeft)) {
[self forceChangeToOrientation:UIInterfaceOrientationPortrait];
}
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//Handoff
[self p_setupUserActivity];
}
- (void)tabBarItemClicked{
DebugLog(@"\ntabBarItemClicked : %@", NSStringFromClass([self class]));
}
#pragma mark - Orientations
- (BOOL)shouldAutorotate{
return UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication.statusBarOrientation);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (void)forceChangeToOrientation:(UIInterfaceOrientation)interfaceOrientation{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:interfaceOrientation] forKey:@"orientation"];
}
#pragma mark Notification
+ (void)handleNotificationInfo:(NSDictionary *)userInfo applicationState:(UIApplicationState)applicationState{
if (applicationState == UIApplicationStateInactive) {
//If the application state was inactive, this means the user pressed an action button from a notification.
//标记为已读
NSString *notification_id = [userInfo objectForKey:@"notification_id"];
if (notification_id) {
[[Coding_NetAPIManager sharedManager] request_markReadWithCodingTipIdStr:notification_id andBlock:^(id data, NSError *error) {
}];
}
//弹出临时会话
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
DebugLog(@"handleNotificationInfo : %@", userInfo);
NSString *param_url = [userInfo objectForKey:@"param_url"];
[self presentLinkStr:param_url];
});
}else if (applicationState == UIApplicationStateActive){
NSString *param_url = [userInfo objectForKey:@"param_url"];
[self analyseVCFromLinkStr:param_url analyseMethod:AnalyseMethodTypeJustRefresh isNewVC:nil];//AnalyseMethodTypeJustRefresh
//标记未读
UIViewController *presentingVC = [BaseViewController presentingVC];
if ([presentingVC isKindOfClass:[Message_RootViewController class]]) {
[(Message_RootViewController *)presentingVC refresh];
}
[[UnReadManager shareManager] updateUnRead];
}
}
+ (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr{
return [self analyseVCFromLinkStr:linkStr analyseMethod:AnalyseMethodTypeForceCreate isNewVC:nil];
}
+ (void)presentLinkStr:(NSString *)linkStr{
if (!linkStr || linkStr.length == 0) {
return;
}
BOOL isNewVC = YES;
UIViewController *vc = [self analyseVCFromLinkStr:linkStr analyseMethod:AnalyseMethodTypeLazyCreate isNewVC:&isNewVC];
if (vc && isNewVC) {
[self presentVC:vc];
}else if (!vc){
if (![linkStr hasPrefix:kCodingAppScheme]) {
//网页
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
[self presentVC:webVc];
}
}
}
+ (UIViewController *)presentingVC{
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
UIViewController *result = window.rootViewController;
while (result.presentedViewController) {
result = result.presentedViewController;
}
if ([result isKindOfClass:[RootTabViewController class]]) {
result = [(RootTabViewController *)result selectedViewController];
}
if ([result isKindOfClass:[UINavigationController class]]) {
result = [(UINavigationController *)result topViewController];
}
return result;
}
+ (void)presentVC:(UIViewController *)viewController{
if (!viewController) {
return;
}
UINavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:viewController];
if (!viewController.navigationItem.leftBarButtonItem) {
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:viewController action:@selector(dismissModalVC)];
}
[[self presentingVC] presentViewController:nav animated:YES completion:nil];
}
+ (void)goToVC:(UIViewController *)viewController{
if (!viewController) {
return;
}
UINavigationController *nav = [self presentingVC].navigationController;
if (nav) {
[nav pushViewController:viewController animated:YES];
}
}
#pragma mark Login
- (void)loginOutToLoginVC{
[Login doLogout];
[((AppDelegate *)[UIApplication sharedApplication].delegate) setupLoginViewController];
}
#pragma mark (URL - ViewController) 特么,放在这里放瞎了
#ifdef Target_Enterprise
- (void)p_setupUserActivity{
NSString *webStr = nil;
// 主 Tab
if ([self isKindOfClass:Project_RootViewController.class]) {//Project
webStr = @"/user/projects";
}else if ([self isKindOfClass:MyTask_RootViewController.class]){//Task
webStr = [NSString stringWithFormat:@"/user/tasks?owner=%@&status=1", [Login curLoginUser].id];
}else if ([self isKindOfClass:Message_RootViewController.class]){//Message
webStr = @"/user/messages/basic";
}else if ([self isKindOfClass:Me_RootViewController.class]){//User
webStr = @"/user/account/setting/basic";
// Project
}else if ([self isKindOfClass:NProjectViewController.class]){
Project *curPro = ((NProjectViewController *)self).myProject;
webStr = [NSString stringWithFormat:@"/p/%@", curPro.name];
}else if ([self isKindOfClass:ProjectViewController.class]){
Project *curPro = ((ProjectViewController *)self).myProject;
ProjectViewType type = ((ProjectViewController *)self).curType;
NSString *sufStr = (type == ProjectViewTypeTasks? @"/tasks":
type == ProjectViewTypeFiles? @"/attachment":
type == ProjectViewTypeCodes? @"/git":
type == ProjectViewTypeMembers? @"/setting/member":
type == ProjectViewTypeActivities? @"":@"");
webStr = [NSString stringWithFormat:@"/p/%@%@", curPro.name, sufStr];
}else if ([self isKindOfClass:EACodeBranchListViewController.class]){
Project *curPro = ((EACodeBranchListViewController *)self).myProject;
webStr = [NSString stringWithFormat:@"/p/%@/git/branches", curPro.name];
}else if ([self isKindOfClass:EACodeReleaseListViewController.class]){
Project *curPro = ((EACodeReleaseListViewController *)self).myProject;
webStr = [NSString stringWithFormat:@"/p/%@/git/releases", curPro.name];
}else if ([self isKindOfClass:MRPRListViewController.class]){
Project *curPro = ((MRPRListViewController *)self).curProject;
BOOL isMR = ((MRPRListViewController *)self).isMR;
webStr = [NSString stringWithFormat:@"/p/%@/git/%@", curPro.name, isMR? @"merges": @"pulls/open"];
}else if ([self isKindOfClass:UserOrProjectTweetsViewController.class]){
Tweets *curTweets = ((UserOrProjectTweetsViewController *)self).curTweets;
if (curTweets.tweetType == TweetTypeProject) {
webStr = [NSString stringWithFormat:@"/p/%@/setting/notice", curTweets.curPro.name];
}else if (curTweets.tweetType == TweetTypeUserSingle){
webStr = [NSString stringWithFormat:@"/u/%@/bubble", curTweets.curUser.global_key];
}
}else if ([self isKindOfClass:ProjectSettingViewController.class]){
Project *curPro = ((ProjectSettingViewController *)self).project;
webStr = [NSString stringWithFormat:@"/p/%@/setting", curPro.name];
// Task
}else if ([self isKindOfClass:EditTaskViewController.class]){
Task *curTask = ((EditTaskViewController *)self).myTask;
NSString *project_name = [curTask.backend_project_path componentsSeparatedByString:@"/"].lastObject;
webStr = [NSString stringWithFormat:@"/p/%@/task/%@", project_name, curTask.id];
// Tweet
}else if ([self isKindOfClass:TweetDetailViewController.class]){
Tweet *curTweet = ((TweetDetailViewController *)self).curTweet;
if (curTweet.isProjectTweet) {
webStr = [NSString stringWithFormat:@"/p/%@/setting/notice/%@", curTweet.project.name, curTweet.id];
}else{
webStr = [NSString stringWithFormat:@"/u/%@/pp/%@", curTweet.user_global_key ?: curTweet.owner.global_key, curTweet.id];
}
// Message
}else if ([self isKindOfClass:ConversationViewController.class]){
PrivateMessages *curPriMs = ((ConversationViewController *)self).myPriMsgs;
webStr = [NSString stringWithFormat:@"/user/messages/history/%@", curPriMs.curFriend.global_key];
// User
}else if ([self isKindOfClass:UserInfoViewController.class]){
User *curU = ((UserInfoViewController *)self).curUser;
webStr = [NSString stringWithFormat:@"/u/%@", curU.global_key];
// Topic/File/MR/Code/Wiki/Release
}else if ([self isKindOfClass:FileViewController.class]){
ProjectFile *curFile = ((FileViewController *)self).curFile;
if (curFile.project_owner_name && curFile.project_name) {
webStr = curFile.owner_preview;
}else if (curFile.owner_preview){
webStr = [NSString stringWithFormat:@"/p/%@/attachment/default/preview/%@", curFile.project_name, curFile.file_id];
}
}else if ([self isKindOfClass:MRDetailViewController.class] || [self isKindOfClass:PRDetailViewController.class]){
MRPR *curMRPR = [self valueForKey:@"curMRPR"];
NSString *path = curMRPR.path;
NSRange range = [path rangeOfString:@"/p/"];
webStr = range.location == NSNotFound? path: [path substringFromIndex:range.location];
}else if ([self isKindOfClass:CodeViewController.class]){
Project *curPro = ((CodeViewController *) self).myProject;
CodeFile *curCF = ((CodeViewController *) self).myCodeFile;
webStr = [NSString stringWithFormat:@"/p/%@/git/blob/%@/%@", curPro.name, curCF.ref, curCF.path];
}else if ([self isKindOfClass:WikiViewController.class]){
WikiViewController *vc = (WikiViewController *)self;
webStr = [NSString stringWithFormat:@"/p/%@/wiki", vc.myProject.name];
if (vc.iid) {
webStr = [webStr stringByAppendingFormat:@"/%@", vc.iid];
if (vc.version.integerValue > 0) {
webStr = [webStr stringByAppendingFormat:@"?version=%@", vc.version];
}
}
}else if ([self isKindOfClass:EACodeReleaseViewController.class]){
EACodeRelease *curR = ((EACodeReleaseViewController *)self).curRelease;
webStr = [NSString stringWithFormat:@"/p/%@/git/releases/%@", curR.project.name, curR.tag_name];
// CodeList/FileList/Webview
}else if ([self isKindOfClass:CodeListViewController.class]){
Project *curPro = ((CodeListViewController *) self).myProject;
CodeTree *curCT = ((CodeListViewController *) self).myCodeTree;
webStr = [NSString stringWithFormat:@"/p/%@/git/tree/%@/%@", curPro.name, curCT.ref, curCT.path];
}else if ([self isKindOfClass:NFileListViewController.class]){
Project *curPro = ((NFileListViewController *) self).curProject;
ProjectFile *curPF = ((NFileListViewController *) self).curFolder;
webStr = [NSString stringWithFormat:@"/p/%@/attachment/%@", curPro.name, curPF.file_id];
}else if ([self isKindOfClass:WebViewController.class]){
webStr = ((WebViewController *)self).request.URL.absoluteString;
}
if (webStr) {
NSURL *webURL = nil;
if (![webStr hasPrefix:@"http"]) {
webURL = [NSURL URLWithString:webStr relativeToURL:[NSURL URLWithString:[NSObject baseURLStr]]];
}else{
webURL = [NSURL URLWithString:webStr];
}
if (!_userActivity) {
_userActivity = [[NSUserActivity alloc]initWithActivityType:@"com.alex.handoffdemo"];
_userActivity.title = @"CODING_ENTERPRISE";
}
[_userActivity setWebpageURL:webURL];
[_userActivity becomeCurrent];
}
}
+ (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr analyseMethod:(AnalyseMethodType)methodType isNewVC:(BOOL *)isNewVC{
DebugLog(@"\n analyseVCFromLinkStr : %@", linkStr);
NSString *lowerLinkStr = linkStr.lowercaseString;
if (!linkStr || linkStr.length <= 0) {
return nil;
}else if (!([linkStr hasPrefix:@"/"] ||
[lowerLinkStr hasPrefix:kCodingAppScheme] ||
[lowerLinkStr hasPrefix:kBaseUrlStr_Phone] ||
[lowerLinkStr hasPrefix:[NSObject baseURLStr].lowercaseString] ||
[lowerLinkStr hasPrefix:@"https://coding.net"])){//兼容一下先
return nil;
}
NSRange pRange = [linkStr rangeOfString:@"/p/"];
if (pRange.location != NSNotFound &&
[linkStr rangeOfString:@"/u/"].location == NSNotFound &&
[linkStr rangeOfString:@"/t/"].location == NSNotFound) {//强填 u
NSString *defaultTeamStr = [NSString stringWithFormat:@"/u/%@", [Login curLoginCompany].global_key ?: [NSObject baseCompany]];
linkStr = [linkStr stringByReplacingCharactersInRange:NSMakeRange(pRange.location, 0) withString:defaultTeamStr];
}
UIViewController *analyseVC = nil;
UIViewController *presentingVC = nil;
BOOL analyseVCIsNew = YES;
if (methodType != AnalyseMethodTypeForceCreate) {
presentingVC = [BaseViewController presentingVC];
}
NSString *teamRegexStr = @"/t/([^/]+)$";//AT某人
NSString *userRegexStr = @"/u/([^/]+)$";//AT某人
// NSString *userTweetRegexStr = @"/u/([^/]+)/bubble$";//某人的冒泡
// NSString *ppRegexStr = @"/u/([^/]+)/pp/([0-9]+)";//冒泡
NSString *pp_projectRegexStr = @"/[ut]/([^/]+)/p/([^\?]+)[\?]pp=([0-9]+)$";//项目内冒泡(含团队项目)
NSString *topicRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/topic/(\\d+)";//讨论(含团队项目)
NSString *taskRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/task/(\\d+)";//任务(含团队项目)
NSString *fileRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/attachment/([^/]+)/preview/(\\d+)";//文件(含团队项目)
NSString *gitMRPRCommitRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/git/(merge|pull|commit)/([^/#]+)";//MR(含团队项目)
NSString *conversionRegexStr = @"/user/messages/history/([^/]+)$";//私信
// NSString *pp_topicRegexStr = @"/pp/topic/([0-9]+)$";//话题
NSString *codeRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/git/blob/([^/]+)[/]?([^?]*)";//代码(含团队项目)
NSString *twoFARegexStr = @"/app_intercept/show_2fa";//两步验证
NSString *projectRegexStr = @"/[ut]/([^/]+)/p/([^/]+)";//项目(含团队项目)
NSString *noticeRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/setting/notice/(\\d+)";//项目公告
NSString *wikiRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/wiki/(\\d+)";//Wiki
NSString *releaseRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/git/releases/([^/]+)[/]?([^?]*)";//Release
NSArray *matchedCaptures = nil;
if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:teamRegexStr]).count > 0) {
//团队
TeamViewController *vc = [TeamViewController new];
NSString *team_global_key = matchedCaptures[1];
vc.curTeam = [Team teamWithGK:team_global_key];
analyseVC = vc;
}else if ([linkStr hasSuffix:@"/admin"]){
//企业
TeamViewController *vc = [TeamViewController new];
NSString *team_global_key = [NSObject baseCompany];
vc.curTeam = [Team teamWithGK:team_global_key];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:noticeRegexStr]).count > 0){
//项目公告
NSString *owner_user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *pp_id = matchedCaptures[3];
Project *curPro = [Project new];
curPro.owner_user_name = owner_user_global_key;
curPro.name = project_name;
TweetDetailViewController *vc = [[TweetDetailViewController alloc] init];
vc.curTweet = [Tweet tweetInProject:curPro andPPID:pp_id];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:wikiRegexStr]).count > 0){
WikiViewController *vc = [WikiViewController new];
Project *curPro = [Project new];
curPro.owner_user_name = matchedCaptures[1];
curPro.name = matchedCaptures[2];
NSString *iid = matchedCaptures[3];
vc.myProject = curPro;
[vc setWikiIid:@(iid.integerValue) version:nil];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:releaseRegexStr]).count > 0){
EACodeReleaseViewController *vc = [EACodeReleaseViewController new];
Project *curPro = [Project new];
curPro.owner_user_name = matchedCaptures[1];
curPro.name = matchedCaptures[2];
EACodeRelease *curR = [EACodeRelease new];
curR.project = curPro;
curR.tag_name = matchedCaptures[3];
vc.curRelease = curR;
analyseVC = vc;
// }else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:ppRegexStr]).count > 0){
// //冒泡
// NSString *user_global_key = matchedCaptures[1];
// NSString *pp_id = matchedCaptures[2];
// if ([presentingVC isKindOfClass:[TweetDetailViewController class]]) {
// TweetDetailViewController *vc = (TweetDetailViewController *)presentingVC;
// if ([vc.curTweet.id.stringValue isEqualToString:pp_id]
// && [vc.curTweet.owner.global_key isEqualToString:user_global_key]) {
// [vc refreshTweet];
// analyseVCIsNew = NO;
// analyseVC = vc;
// }
// }
// if (!analyseVC) {
// TweetDetailViewController *vc = [[TweetDetailViewController alloc] init];
// vc.curTweet = [Tweet tweetWithGlobalKey:user_global_key andPPID:pp_id];
// analyseVC = vc;
// }
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:pp_projectRegexStr]).count > 0){
//项目内冒泡
NSString *owner_user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *pp_id = matchedCaptures[3];
Project *curPro = [Project new];
curPro.owner_user_name = owner_user_global_key;
curPro.name = project_name;
TweetDetailViewController *vc = [[TweetDetailViewController alloc] init];
vc.curTweet = [Tweet tweetInProject:curPro andPPID:pp_id];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:gitMRPRCommitRegexStr]).count > 0){
//MR
NSString *path = [matchedCaptures[0] stringByReplacingOccurrencesOfString:@"https://coding.net" withString:@""];
// NSString *defaultTeamStr = [NSString stringWithFormat:@"/u/%@", [Login curLoginCompany].global_key ?: [NSObject baseCompany]];
// linkStr = [linkStr stringByReplacingCharactersInRange:NSMakeRange(pRange.location, 0) withString:defaultTeamStr];
if ([matchedCaptures[3] isEqualToString:@"commit"]) {
if ([presentingVC isKindOfClass:[CommitFilesViewController class]]) {
CommitFilesViewController *vc = (CommitFilesViewController *)presentingVC;
if ([vc.commitId isEqualToString:matchedCaptures[3]] &&
[vc.projectName isEqualToString:matchedCaptures[2]] &&
[vc.ownerGK isEqualToString:matchedCaptures[1]]) {
[vc refresh];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
analyseVC = [CommitFilesViewController vcWithPath:path];
}
}else{
if ([presentingVC isKindOfClass:[PRDetailViewController class]]) {
PRDetailViewController *vc = (PRDetailViewController *)presentingVC;
if ([vc.curMRPR.path isEqualToString:path]) {
[vc refresh];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
if([path rangeOfString:@"merge"].location == NSNotFound) {
analyseVC = [PRDetailViewController vcWithPath:path];
} else {
analyseVC = [MRDetailViewController vcWithPath:path];
}
}
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:topicRegexStr]).count > 0){
//讨论
NSString *topic_id = matchedCaptures[3];
if ([presentingVC isKindOfClass:[TopicDetailViewController class]]) {
TopicDetailViewController *vc = (TopicDetailViewController *)presentingVC;
if ([vc.curTopic.id.stringValue isEqualToString:topic_id]) {
[vc refreshTopic];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
TopicDetailViewController *vc = [[TopicDetailViewController alloc] init];
vc.curTopic = [ProjectTopic topicWithId:[NSNumber numberWithInteger:topic_id.integerValue]];
analyseVC = vc;
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:taskRegexStr]).count > 0){
//任务
NSString *user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *taskId = matchedCaptures[3];
NSString *backend_project_path = [NSString stringWithFormat:@"/user/%@/project/%@", user_global_key, project_name];
if ([presentingVC isKindOfClass:[EditTaskViewController class]]) {
EditTaskViewController *vc = (EditTaskViewController *)presentingVC;
if ([vc.myTask.backend_project_path isEqualToString:backend_project_path]
&& [vc.myTask.id.stringValue isEqualToString:taskId]) {
[vc queryToRefreshTaskDetail];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
EditTaskViewController *vc = [[EditTaskViewController alloc] init];
vc.myTask = [Task taskWithBackend_project_path:[NSString stringWithFormat:@"/user/%@/project/%@", user_global_key, project_name] andId:taskId];
@weakify(vc);
vc.taskChangedBlock = ^(){
@strongify(vc);
[vc dismissViewControllerAnimated:YES completion:nil];
};
analyseVC = vc;
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:fileRegexStr]).count > 0){
//文件
NSString *user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *fileId = matchedCaptures[4];
if ([presentingVC isKindOfClass:[FileViewController class]]) {
FileViewController *vc = (FileViewController *)presentingVC;
if (vc.curFile.file_id.integerValue == fileId.integerValue) {
[vc requestFileData];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
ProjectFile *curFile = [[ProjectFile alloc] initWithFileId:@(fileId.integerValue) inProject:project_name ofUser:user_global_key];
FileViewController *vc = [FileViewController vcWithFile:curFile andVersion:nil];
analyseVC = vc;
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:conversionRegexStr]).count > 0) {
//私信
NSString *user_global_key = matchedCaptures[1];
if ([presentingVC isKindOfClass:[ConversationViewController class]]) {
ConversationViewController *vc = (ConversationViewController *)presentingVC;
if ([vc.myPriMsgs.curFriend.global_key isEqualToString:user_global_key]) {
[vc doPoll];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
ConversationViewController *vc = [[ConversationViewController alloc] init];
vc.myPriMsgs = [PrivateMessages priMsgsWithUser:[User userWithGlobalKey:user_global_key]];
analyseVC = vc;
}
}else if (methodType != AnalyseMethodTypeJustRefresh){
if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:userRegexStr]).count > 0) {
//AT某人
NSString *user_global_key = matchedCaptures[1];
UserInfoDetailViewController *vc = [UserInfoDetailViewController new];
vc.curUser = [User userWithGlobalKey:user_global_key];
analyseVC = vc;
// }else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:userTweetRegexStr]).count > 0){
// //某人的冒泡
// UserOrProjectTweetsViewController *vc = [[UserOrProjectTweetsViewController alloc] init];
// NSString *user_global_key = matchedCaptures[1];
// vc.curTweets = [Tweets tweetsWithUser:[User userWithGlobalKey:user_global_key]];
// analyseVC = vc;
// }else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:pp_topicRegexStr]).count > 0){
// //话题
// NSString *pp_topic_id = matchedCaptures[1];
// CSTopicDetailVC *vc = [CSTopicDetailVC new];
// vc.topicID = pp_topic_id.integerValue;
// analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:codeRegexStr]).count > 0){
//代码
NSString *user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *ref = matchedCaptures[3];
NSString *path = matchedCaptures.count >= 5? matchedCaptures[4]: @"";
Project *curPro = [[Project alloc] init];
curPro.owner_user_name = user_global_key;
curPro.name = project_name;
CodeFile *codeFile = [CodeFile codeFileWithRef:ref andPath:path];
CodeViewController *vc = [CodeViewController codeVCWithProject:curPro andCodeFile:codeFile];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:twoFARegexStr]).count > 0){
//两步验证
analyseVC = [OTPListViewController new];
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:projectRegexStr]).count > 0){
//项目
NSString *user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
Project *curPro = [[Project alloc] init];
curPro.owner_user_name = user_global_key;
curPro.name = project_name;
NProjectViewController *vc = [[NProjectViewController alloc] init];
vc.myProject = curPro;
analyseVC = vc;
}
}
if (isNewVC) {
*isNewVC = analyseVCIsNew;
}
return analyseVC;
}
#else
- (void)p_setupUserActivity{
NSString *webStr = nil;
// 主 Tab
if ([self isKindOfClass:Project_RootViewController.class]) {//Project
webStr = @"/user/projects";
}else if ([self isKindOfClass:MyTask_RootViewController.class]){//Task
webStr = [NSString stringWithFormat:@"/user/tasks?owner=%@&status=1", [Login curLoginUser].id];
}else if ([self isKindOfClass:Tweet_RootViewController.class]){//Tweet
Tweet_RootViewControllerType type = ((Tweet_RootViewController *)self).type;
webStr = [NSString stringWithFormat:@"/pp%@", (type == Tweet_RootViewControllerTypeHot? @"/hot":
type == Tweet_RootViewControllerTypeFriend? @"/friends":
@"")];
}else if ([self isKindOfClass:Message_RootViewController.class]){//Message
webStr = @"/user/messages/basic";
}else if ([self isKindOfClass:Me_RootViewController.class]){//User
webStr = @"/user/account";
// Project
}else if ([self isKindOfClass:NProjectViewController.class]){
Project *curPro = ((NProjectViewController *)self).myProject;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@", curPro.owner_user_name, curPro.name];
}else if ([self isKindOfClass:ProjectViewController.class]){
Project *curPro = ((ProjectViewController *)self).myProject;
ProjectViewType type = ((ProjectViewController *)self).curType;
NSString *sufStr = (type == ProjectViewTypeTasks? @"/tasks":
type == ProjectViewTypeFiles? @"/attachment":
type == ProjectViewTypeTopics? @"/topics":
type == ProjectViewTypeCodes? @"/git":
type == ProjectViewTypeMembers? @"/setting/member":
type == ProjectViewTypeActivities? @"":@"");
webStr = [NSString stringWithFormat:@"/u/%@/p/%@%@", curPro.owner_user_name, curPro.name, sufStr];
}else if ([self isKindOfClass:EACodeBranchListViewController.class]){
Project *curPro = ((EACodeBranchListViewController *)self).myProject;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/git/branches", curPro.owner_user_name, curPro.name];
}else if ([self isKindOfClass:EACodeReleaseListViewController.class]){
Project *curPro = ((EACodeReleaseListViewController *)self).myProject;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/git/releases", curPro.owner_user_name, curPro.name];
}else if ([self isKindOfClass:MRPRListViewController.class]){
Project *curPro = ((MRPRListViewController *)self).curProject;
BOOL isMR = ((MRPRListViewController *)self).isMR;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/git/%@", curPro.owner_user_name, curPro.name, isMR? @"merges": @"pulls/open"];
}else if ([self isKindOfClass:UserOrProjectTweetsViewController.class]){
Tweets *curTweets = ((UserOrProjectTweetsViewController *)self).curTweets;
if (curTweets.tweetType == TweetTypeProject) {
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/setting/notice", curTweets.curPro.owner_user_name, curTweets.curPro.name];
}else if (curTweets.tweetType == TweetTypeUserSingle){
webStr = [NSString stringWithFormat:@"/u/%@/bubble", curTweets.curUser.global_key];
}
}else if ([self isKindOfClass:ProjectSettingViewController.class]){
Project *curPro = ((ProjectSettingViewController *)self).project;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/setting", curPro.owner_user_name, curPro.name];
// Task
}else if ([self isKindOfClass:EditTaskViewController.class]){
Task *curTask = ((EditTaskViewController *)self).myTask;
NSString *project_path = curTask.backend_project_path.copy;
project_path = [[project_path stringByReplacingOccurrencesOfString:@"/user/" withString:@"/u/"] stringByReplacingOccurrencesOfString:@"/project/" withString:@"/p/"];
webStr = [NSString stringWithFormat:@"%@/task/%@", project_path, curTask.id];
// Tweet
}else if ([self isKindOfClass:TweetDetailViewController.class]){
Tweet *curTweet = ((TweetDetailViewController *)self).curTweet;
if (curTweet.isProjectTweet) {
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/setting/notice/%@", curTweet.project.owner_user_name, curTweet.project.name, curTweet.id];
}else{
webStr = [NSString stringWithFormat:@"/u/%@/pp/%@", curTweet.user_global_key ?: curTweet.owner.global_key, curTweet.id];
}
// Message
}else if ([self isKindOfClass:ConversationViewController.class]){
PrivateMessages *curPriMs = ((ConversationViewController *)self).myPriMsgs;
webStr = [NSString stringWithFormat:@"/user/messages/history/%@", curPriMs.curFriend.global_key];
// User
}else if ([self isKindOfClass:UserInfoViewController.class]){
User *curU = ((UserInfoViewController *)self).curUser;
webStr = [NSString stringWithFormat:@"/u/%@", curU.global_key];
// Topic/File/MR/Code/Wiki/Release
}else if ([self isKindOfClass:TopicDetailViewController.class]){
ProjectTopic *curTopic = ((TopicDetailViewController *)self).curTopic;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/topic/%@", curTopic.project.owner_user_name, curTopic.project.name, curTopic.id];
}else if ([self isKindOfClass:FileViewController.class]){
ProjectFile *curFile = ((FileViewController *)self).curFile;
if (curFile.project_owner_name && curFile.project_name) {
webStr = curFile.owner_preview;
}else if (curFile.owner_preview){
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/attachment/default/preview/%@", curFile.project_owner_name, curFile.project_name, curFile.file_id];
}
}else if ([self isKindOfClass:MRDetailViewController.class] || [self isKindOfClass:PRDetailViewController.class]){
MRPR *curMRPR = [self valueForKey:@"curMRPR"];
webStr = curMRPR.path;
}else if ([self isKindOfClass:CodeViewController.class]){
Project *curPro = ((CodeViewController *) self).myProject;
CodeFile *curCF = ((CodeViewController *) self).myCodeFile;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/git/blob/%@/%@", curPro.owner_user_name, curPro.name, curCF.ref, curCF.path];
}else if ([self isKindOfClass:WikiViewController.class]){
WikiViewController *vc = (WikiViewController *)self;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/wiki", vc.myProject.owner_user_name, vc.myProject.name];
if (vc.iid) {
webStr = [webStr stringByAppendingFormat:@"/%@", vc.iid];
if (vc.version.integerValue > 0) {
webStr = [webStr stringByAppendingFormat:@"?version=%@", vc.version];
}
}
}else if ([self isKindOfClass:EACodeReleaseViewController.class]){
EACodeRelease *curR = ((EACodeReleaseViewController *)self).curRelease;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/git/releases/%@", curR.project.owner_user_name, curR.project.name, curR.tag_name];
// CodeList/FileList/Webview
}else if ([self isKindOfClass:CodeListViewController.class]){
Project *curPro = ((CodeListViewController *) self).myProject;
CodeTree *curCT = ((CodeListViewController *) self).myCodeTree;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/git/tree/%@/%@", curPro.owner_user_name, curPro.name, curCT.ref, curCT.path];
}else if ([self isKindOfClass:NFileListViewController.class]){
Project *curPro = ((NFileListViewController *) self).curProject;
ProjectFile *curPF = ((NFileListViewController *) self).curFolder;
webStr = [NSString stringWithFormat:@"/u/%@/p/%@/attachment/%@", curPro.owner_user_name, curPro.name, curPF.file_id];
}else if ([self isKindOfClass:WebViewController.class]){
webStr = ((WebViewController *)self).request.URL.absoluteString;
}
if (webStr) {
NSURL *webURL = nil;
if (![webStr hasPrefix:@"http"]) {
webURL = [NSURL URLWithString:webStr relativeToURL:[NSURL URLWithString:[NSObject baseURLStr]]];
}else{
webURL = [NSURL URLWithString:webStr];
}
if (!_userActivity) {
_userActivity = [[NSUserActivity alloc]initWithActivityType:@"com.alex.handoffdemo"];
_userActivity.title = @"CODING";
}
[_userActivity setWebpageURL:webURL];
[_userActivity becomeCurrent];
}
}
+ (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr analyseMethod:(AnalyseMethodType)methodType isNewVC:(BOOL *)isNewVC{
DebugLog(@"\n analyseVCFromLinkStr : %@", linkStr);
if (!linkStr || linkStr.length <= 0) {
return nil;
}else if (!([linkStr hasPrefix:@"/"] ||
[linkStr hasPrefix:kCodingAppScheme] ||
[linkStr hasPrefix:kBaseUrlStr_Phone] ||
[linkStr hasPrefix:[NSObject baseURLStr]])){
return nil;
}
UIViewController *analyseVC = nil;
UIViewController *presentingVC = nil;
BOOL analyseVCIsNew = YES;
if (methodType != AnalyseMethodTypeForceCreate) {
presentingVC = [BaseViewController presentingVC];
}
NSString *userRegexStr = @"/u/([^/]+)$";//AT某人
NSString *userTweetRegexStr = @"/u/([^/]+)/bubble$";//某人的冒泡
NSString *ppRegexStr = @"/u/([^/]+)/pp/([0-9]+)";//冒泡
NSString *pp_projectRegexStr = @"/[ut]/([^/]+)/p/([^\?]+)[\?]pp=([0-9]+)$";//项目内冒泡(含团队项目)
NSString *topicRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/topic/(\\d+)";//讨论(含团队项目)
NSString *taskRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/task/(\\d+)";//任务(含团队项目)
NSString *fileRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/attachment/([^/]+)/preview/(\\d+)";//文件(含团队项目)
NSString *gitMRPRCommitRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/git/(merge|pull|commit)/([^/#]+)";//MR(含团队项目)
NSString *conversionRegexStr = @"/user/messages/history/([^/]+)$";//私信
NSString *pp_topicRegexStr = @"/pp/topic/([0-9]+)$";//话题
NSString *codeRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/git/blob/([^/]+)[/]?([^?]*)";//代码(含团队项目)
NSString *twoFARegexStr = @"/app_intercept/show_2fa";//两步验证
NSString *projectRegexStr = @"/[ut]/([^/]+)/p/([^/]+)";//项目(含团队项目)
NSString *noticeRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/setting/notice/(\\d+)";//项目公告
NSString *wikiRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/wiki/(\\d+)";//Wiki
NSString *releaseRegexStr = @"/[ut]/([^/]+)/p/([^/]+)/git/releases/([^/]+)[/]?([^?]*)";//Release
NSArray *matchedCaptures = nil;
if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:ppRegexStr]).count > 0){
//冒泡
NSString *user_global_key = matchedCaptures[1];
NSString *pp_id = matchedCaptures[2];
if ([presentingVC isKindOfClass:[TweetDetailViewController class]]) {
TweetDetailViewController *vc = (TweetDetailViewController *)presentingVC;
if ([vc.curTweet.id.stringValue isEqualToString:pp_id]
&& [vc.curTweet.owner.global_key isEqualToString:user_global_key]) {
[vc refreshTweet];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
TweetDetailViewController *vc = [[TweetDetailViewController alloc] init];
vc.curTweet = [Tweet tweetWithGlobalKey:user_global_key andPPID:pp_id];
analyseVC = vc;
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:noticeRegexStr]).count > 0){
//项目公告
NSString *owner_user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *pp_id = matchedCaptures[3];
Project *curPro = [Project new];
curPro.owner_user_name = owner_user_global_key;
curPro.name = project_name;
TweetDetailViewController *vc = [[TweetDetailViewController alloc] init];
vc.curTweet = [Tweet tweetInProject:curPro andPPID:pp_id];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:wikiRegexStr]).count > 0){
WikiViewController *vc = [WikiViewController new];
Project *curPro = [Project new];
curPro.owner_user_name = matchedCaptures[1];
curPro.name = matchedCaptures[2];
NSString *iid = matchedCaptures[3];
vc.myProject = curPro;
[vc setWikiIid:@(iid.integerValue) version:nil];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:releaseRegexStr]).count > 0){
EACodeReleaseViewController *vc = [EACodeReleaseViewController new];
Project *curPro = [Project new];
curPro.owner_user_name = matchedCaptures[1];
curPro.name = matchedCaptures[2];
EACodeRelease *curR = [EACodeRelease new];
curR.project = curPro;
curR.tag_name = matchedCaptures[3];
vc.curRelease = curR;
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:pp_projectRegexStr]).count > 0){
//项目内冒泡
NSString *owner_user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *pp_id = matchedCaptures[3];
Project *curPro = [Project new];
curPro.owner_user_name = owner_user_global_key;
curPro.name = project_name;
TweetDetailViewController *vc = [[TweetDetailViewController alloc] init];
vc.curTweet = [Tweet tweetInProject:curPro andPPID:pp_id];
analyseVC = vc;
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:gitMRPRCommitRegexStr]).count > 0){
//MR
NSString *path = [matchedCaptures[0] stringByReplacingOccurrencesOfString:@"https://coding.net" withString:@""];
if ([matchedCaptures[3] isEqualToString:@"commit"]) {
if ([presentingVC isKindOfClass:[CommitFilesViewController class]]) {
CommitFilesViewController *vc = (CommitFilesViewController *)presentingVC;
if ([vc.commitId isEqualToString:matchedCaptures[3]] &&
[vc.projectName isEqualToString:matchedCaptures[2]] &&
[vc.ownerGK isEqualToString:matchedCaptures[1]]) {
[vc refresh];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
analyseVC = [CommitFilesViewController vcWithPath:path];
}
}else{
if ([presentingVC isKindOfClass:[PRDetailViewController class]]) {
PRDetailViewController *vc = (PRDetailViewController *)presentingVC;
if ([vc.curMRPR.path isEqualToString:path]) {
[vc refresh];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
if([path rangeOfString:@"merge"].location == NSNotFound) {
analyseVC = [PRDetailViewController vcWithPath:path];
} else {
analyseVC = [MRDetailViewController vcWithPath:path];
}
}
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:topicRegexStr]).count > 0){
//讨论
NSString *topic_id = matchedCaptures[3];
if ([presentingVC isKindOfClass:[TopicDetailViewController class]]) {
TopicDetailViewController *vc = (TopicDetailViewController *)presentingVC;
if ([vc.curTopic.id.stringValue isEqualToString:topic_id]) {
[vc refreshTopic];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
TopicDetailViewController *vc = [[TopicDetailViewController alloc] init];
ProjectTopic *curTopic = [ProjectTopic topicWithId:[NSNumber numberWithInteger:topic_id.integerValue]];
Project *curPro = [[Project alloc] init];
curPro.owner_user_name = matchedCaptures[1];
curPro.name = matchedCaptures[2];
curTopic.project = curPro;
vc.curTopic = curTopic;
analyseVC = vc;
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:taskRegexStr]).count > 0){
//任务
NSString *user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *taskId = matchedCaptures[3];
NSString *backend_project_path = [NSString stringWithFormat:@"/user/%@/project/%@", user_global_key, project_name];
if ([presentingVC isKindOfClass:[EditTaskViewController class]]) {
EditTaskViewController *vc = (EditTaskViewController *)presentingVC;
if ([vc.myTask.backend_project_path isEqualToString:backend_project_path]
&& [vc.myTask.id.stringValue isEqualToString:taskId]) {
[vc queryToRefreshTaskDetail];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
EditTaskViewController *vc = [[EditTaskViewController alloc] init];
vc.myTask = [Task taskWithBackend_project_path:[NSString stringWithFormat:@"/user/%@/project/%@", user_global_key, project_name] andId:taskId];
@weakify(vc);
vc.taskChangedBlock = ^(){
@strongify(vc);
[vc dismissViewControllerAnimated:YES completion:nil];
};
analyseVC = vc;
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:fileRegexStr]).count > 0){
//文件
NSString *user_global_key = matchedCaptures[1];
NSString *project_name = matchedCaptures[2];
NSString *fileId = matchedCaptures[4];
if ([presentingVC isKindOfClass:[FileViewController class]]) {
FileViewController *vc = (FileViewController *)presentingVC;
if (vc.curFile.file_id.integerValue == fileId.integerValue) {
[vc requestFileData];
analyseVCIsNew = NO;
analyseVC = vc;
}
}
if (!analyseVC) {
ProjectFile *curFile = [[ProjectFile alloc] initWithFileId:@(fileId.integerValue) inProject:project_name ofUser:user_global_key];
FileViewController *vc = [FileViewController vcWithFile:curFile andVersion:nil];
analyseVC = vc;
}
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:conversionRegexStr]).count > 0) {
//私信
NSString *user_global_key = matchedCaptures[1];
if ([presentingVC isKindOfClass:[ConversationViewController class]]) {
ConversationViewController *vc = (ConversationViewController *)presentingVC;
if ([vc.myPriMsgs.curFriend.global_key isEqualToString:user_global_key]) {
[vc doPoll];