@@ -552,6 +552,33 @@ $(() => {
552
552
}
553
553
}
554
554
555
+ const doUnfollow = ( usersList ) => {
556
+ const responseManger = ( o ) => {
557
+ if ( o ) {
558
+ setLoading ( true , null , message || "Unfollowing git users ..." ) ;
559
+ resolve ( o ) ;
560
+ }
561
+ }
562
+
563
+ console . log ( usersList ) ;
564
+ let targets = [ ] ;
565
+ if ( Array . isArray ( usersList ) && usersList . length > 0 ) {
566
+ targets = usersList . map ( user => user . username ) . filter ( username => ! ! username ) ;
567
+ }
568
+ if ( targets . length > 0 ) {
569
+
570
+ try {
571
+ responseHandler ( "UN_FOLLOW_FOLLOWINGS" , {
572
+ username : authorization . username ,
573
+ targets : targets
574
+ } , responseManger ) ;
575
+ } catch ( error ) {
576
+ console . error ( error ) ;
577
+ resolve ( false ) ;
578
+ }
579
+ }
580
+ }
581
+
555
582
/**
556
583
* This function is used to list followers
557
584
*/
@@ -571,7 +598,7 @@ $(() => {
571
598
/**
572
599
* This function is used to show report
573
600
*/
574
- const showReport = async ( ) => {
601
+ const showReport = async ( unfollow = false ) => {
575
602
if ( Array . isArray ( localFollowingList ) ) {
576
603
const currentCount = localFollowingList . length ;
577
604
if ( currentCount > 0 ) {
@@ -590,39 +617,34 @@ $(() => {
590
617
<span class="text-success">Unfollow these git profiles, <span class="pl-1 text-danger"> they are not following back</span></span>
591
618
` ) ;
592
619
593
- console . log ( {
594
- localFollowersList,
595
- localFollowingList,
596
- followersList
597
- } ) ;
598
-
599
620
const users = [ ] ;
600
621
const localList = localFollowingList . reverse ( ) ;
601
- let index = 0 ;
602
- for ( let o = 0 ; o < localList . length ; o ++ ) {
603
- const current = localList [ o ] ;
622
+ const unfollowersOnlyList = localList . filter (
623
+ current => ! followersList . includes ( current && current . username )
624
+ ) ;
625
+ for ( let o = 0 ; o < unfollowersOnlyList . length ; o ++ ) {
626
+ const current = unfollowersOnlyList [ o ] ;
604
627
const userImage = current ? current . image : null ;
605
628
const userUsername = current ? current . username : null
606
629
const userName = ( current && current . name ) || userUsername ;
607
- const hasFollowing = ! ! ( current && current . status ) ;
608
- const hasFollowBack = followersList . includes ( userUsername ) ;
609
- if ( ! hasFollowBack ) {
610
- index ++ ;
611
- users . push ( `<span class="pl-1 pb-1 d-flex">
630
+ users . push ( `<span class="pl-1 pb-1 d-flex">
612
631
<div class="media w-100 mr-1">` + ( userImage ?
613
- `<img src="${ userImage } " width="33px" height="33px" class="align-self-start mr-1" alt="${ userName } "> ` : "" ) +
614
- `<div class="media-body d-flex flex-column">
632
+ `<img src="${ userImage } " width="33px" height="33px" class="align-self-start mr-1" alt="${ userName } "> ` : "" ) +
633
+ `<div class="media-body d-flex flex-column">
615
634
<span class="pr-1 d-flex w-100 font-weight-bold text-danger">${ userName }
616
- <span class="ml-auto my-auto badge small badge-pill badge-danger">${ index } </span>
635
+ <span class="ml-auto my-auto badge small badge-pill badge-danger">${ o + 1 } </span>
617
636
</span>
618
637
<small><a href="${ rootUrl } /${ userUsername } " target="_blank">${ userUsername } </a></small>
619
638
</div>
620
639
</div>
621
640
</span>
622
- ` ) ;
623
- }
641
+ ` ) ;
624
642
}
643
+
625
644
setOutPut ( users . join ( "" ) ) ;
645
+ if ( unfollow ) {
646
+ await doUnfollow ( unfollowersOnlyList ) ;
647
+ }
626
648
} else {
627
649
setOutPut ( `Sorry you don't have any followers, or update followers list by running query 'followers list'` ) ;
628
650
}
@@ -715,6 +737,18 @@ $(() => {
715
737
}
716
738
717
739
740
+ const unFollowFollowings = ( payload , response ) => {
741
+ if ( payload && payload . success ) {
742
+ const { data } = payload ;
743
+ console . log ( data ) ;
744
+ setLoading ( ) ;
745
+ setOutPut ( `success` ) ;
746
+
747
+ }
748
+ }
749
+
750
+
751
+
718
752
/**
719
753
* This function is used to run followers commands
720
754
* @param {String } command
@@ -769,29 +803,27 @@ $(() => {
769
803
*/
770
804
const followActions = async ( command ) => {
771
805
const spitCommand = command . split ( " " ) ;
772
-
806
+
773
807
if (
774
808
! ( Array . isArray ( localFollowersList ) && localFollowersList . length > 0 )
775
- ) {
809
+ ) {
776
810
setOutPut ( "Please run command 'followers list' first" ) ;
777
811
return ;
778
- }
812
+ }
779
813
if (
780
814
! ( Array . isArray ( localFollowingList ) && localFollowingList . length > 0 )
781
- ) {
815
+ ) {
782
816
setOutPut ( "Please run command 'following list' first" ) ;
783
817
return ;
784
818
}
785
819
786
820
if ( command . indexOf ( " report" ) > - 1 || command . indexOf ( " -r" ) > - 1 ) {
787
- await showReport ( ) ;
821
+ await showReport ( ) ;
788
822
}
789
823
790
- // if (command.indexOf(" show") > -1 || command.indexOf(" -s") > -1) {
791
- // showFollowing();
792
- // }
793
-
794
- console . log ( loadFollowersResponse ) ;
824
+ if ( command . indexOf ( " action" ) > - 1 || command . indexOf ( " -a" ) > - 1 ) {
825
+ await showReport ( true ) ;
826
+ }
795
827
}
796
828
797
829
const doTheAction = ( command ) => {
@@ -826,7 +858,7 @@ $(() => {
826
858
break ;
827
859
case String ( command . match ( / ^ f o l l o w * / ) && command ) :
828
860
followActions ( command ) ;
829
- break ;
861
+ break ;
830
862
default :
831
863
output = `git: ${ command } : command not found`
832
864
}
@@ -952,9 +984,9 @@ $(() => {
952
984
case "LIST_FOLLOWING" :
953
985
isProgress . payload . callback ( true ) ;
954
986
break ;
955
-
956
-
957
-
987
+ case "UN_FOLLOW_FOLLOWING" :
988
+ isProgress . payload . callback ( true ) ;
989
+ break ;
958
990
}
959
991
}
960
992
}
@@ -973,8 +1005,12 @@ $(() => {
973
1005
case "LIST_FOLLOWERS" :
974
1006
listingFollowers ( payload , response ) ;
975
1007
break ;
976
- case "LIST_FOLLOWING" :
977
- listingFollowings ( payload , response ) ;
1008
+ case "LIST_FOLLOWING" :
1009
+ listingFollowings ( payload , response ) ;
1010
+ break ;
1011
+ case "UN_FOLLOW_FOLLOWING" :
1012
+ unFollowFollowings ( payload , response ) ;
1013
+ break ;
978
1014
default :
979
1015
console . log ( "no valid key match" ) ;
980
1016
}
0 commit comments