Skip to content

Commit 8b9b65a

Browse files
committed
unfollow list management
1 parent ea44d14 commit 8b9b65a

File tree

2 files changed

+91
-37
lines changed

2 files changed

+91
-37
lines changed

src/content/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,21 @@ $(() => {
343343
}
344344
}
345345
}
346-
346+
347+
/**
348+
* This function is sued to un follow following uses
349+
* @param {Object} payload
350+
*/
351+
const unFollowFollowing = (payload, response, key) => {
352+
const currentUrl = window.location.href;
353+
console.log({payload});
354+
if (payload) {
355+
if (typeof response === "function") {
356+
response(true, currentUrl);
357+
// startsListingFollowingUsers(key);
358+
}
359+
}
360+
}
347361

348362

349363

@@ -372,6 +386,7 @@ $(() => {
372386
break;
373387
case "GOTO_FOLLOWERS":
374388
openFollowersPage(payload, response);
389+
break;
375390
case "GOTO_FOLLOWING":
376391
openFollowingPage(payload, response);
377392
break;
@@ -381,6 +396,9 @@ $(() => {
381396
case "LIST_FOLLOWING":
382397
listFollowing(payload, response, key);
383398
break;
399+
case "UN_FOLLOW_FOLLOWING":
400+
unFollowFollowing(payload, response, key);
401+
break;
384402

385403

386404
default:

src/popup/terminal/index.js

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,33 @@ $(() => {
552552
}
553553
}
554554

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+
555582
/**
556583
* This function is used to list followers
557584
*/
@@ -571,7 +598,7 @@ $(() => {
571598
/**
572599
* This function is used to show report
573600
*/
574-
const showReport = async () => {
601+
const showReport = async (unfollow = false) => {
575602
if (Array.isArray(localFollowingList)) {
576603
const currentCount = localFollowingList.length;
577604
if (currentCount > 0) {
@@ -590,39 +617,34 @@ $(() => {
590617
<span class="text-success">Unfollow these git profiles, <span class="pl-1 text-danger"> they are not following back</span></span>
591618
`);
592619

593-
console.log({
594-
localFollowersList,
595-
localFollowingList,
596-
followersList
597-
});
598-
599620
const users = [];
600621
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];
604627
const userImage = current ? current.image : null;
605628
const userUsername = current ? current.username : null
606629
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">
612631
<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">
615634
<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>
617636
</span>
618637
<small><a href="${rootUrl}/${userUsername}" target="_blank">${userUsername}</a></small>
619638
</div>
620639
</div>
621640
</span>
622-
`);
623-
}
641+
`);
624642
}
643+
625644
setOutPut(users.join(""));
645+
if( unfollow) {
646+
await doUnfollow(unfollowersOnlyList);
647+
}
626648
} else {
627649
setOutPut(`Sorry you don't have any followers, or update followers list by running query 'followers list'`);
628650
}
@@ -715,6 +737,18 @@ $(() => {
715737
}
716738

717739

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+
718752
/**
719753
* This function is used to run followers commands
720754
* @param {String} command
@@ -769,29 +803,27 @@ $(() => {
769803
*/
770804
const followActions = async (command) => {
771805
const spitCommand = command.split(" ");
772-
806+
773807
if (
774808
!(Array.isArray(localFollowersList) && localFollowersList.length > 0)
775-
) {
809+
) {
776810
setOutPut("Please run command 'followers list' first");
777811
return;
778-
}
812+
}
779813
if (
780814
!(Array.isArray(localFollowingList) && localFollowingList.length > 0)
781-
) {
815+
) {
782816
setOutPut("Please run command 'following list' first");
783817
return;
784818
}
785819

786820
if (command.indexOf(" report") > -1 || command.indexOf(" -r") > -1) {
787-
await showReport();
821+
await showReport();
788822
}
789823

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+
}
795827
}
796828

797829
const doTheAction = (command) => {
@@ -826,7 +858,7 @@ $(() => {
826858
break;
827859
case String(command.match(/^follow*/) && command):
828860
followActions(command);
829-
break;
861+
break;
830862
default:
831863
output = `git: ${command}: command not found`
832864
}
@@ -952,9 +984,9 @@ $(() => {
952984
case "LIST_FOLLOWING":
953985
isProgress.payload.callback(true);
954986
break;
955-
956-
957-
987+
case "UN_FOLLOW_FOLLOWING":
988+
isProgress.payload.callback(true);
989+
break;
958990
}
959991
}
960992
}
@@ -973,8 +1005,12 @@ $(() => {
9731005
case "LIST_FOLLOWERS":
9741006
listingFollowers(payload, response);
9751007
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;
9781014
default:
9791015
console.log("no valid key match");
9801016
}

0 commit comments

Comments
 (0)