showed mutual follows in profile for self

This commit is contained in:
Vishal 2022-09-08 19:22:18 +05:30
parent cb8c74bef3
commit 438838af33
3 changed files with 77 additions and 48 deletions

View File

@ -193,6 +193,60 @@ void readjustAlignment() {
}
}
void printProfile(Store node, String profilePubkey) {
bool onlyUserPostAndLike (Tree t) => t.hasUserPostAndLike(profilePubkey);
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), onlyUserPostAndLike);
// get the latest kind 3 event for the user, which lists his 'follows' list
Event? contactEvent = getContactEvent(profilePubkey);
// if contact list was found, get user's feed, and keep the contact list for later use
String authorName = gKindONames[profilePubkey]?.name??"";
String pronoun = "";
if( profilePubkey == userPublicKey) {
printUnderlined("\nYour profile ($authorName):");
pronoun = "You";
} else {
printUnderlined("\nProfile for $authorName");
pronoun = "They";
}
print("\nName : $authorName ( ${profilePubkey} ).");
if (contactEvent != null ) {
String about = gKindONames[profilePubkey]?.about??"";
String picture = gKindONames[profilePubkey]?.picture??"";
int dateLastUpdated = gKindONames[profilePubkey]?.createdAt??0;
print("About : $about");
print("Picture : $picture");
print("Last Updated: ${getPrintableDate(dateLastUpdated)}\n");
if( profilePubkey != userPublicKey) {
if( contactEvent.eventData.contactList.any((x) => (x.id == userPublicKey))) {
print("* They follow you");
} else {
print("* They don't follow you");
}
}
// print social distance info.
node.printSocialDistance(profilePubkey, authorName);
print("");
stdout.write("$pronoun follow ${contactEvent.eventData.contactList.length} accounts: ");
contactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.id)}, "));
print("\n");
}
List<String> followers = node.getFollowers(profilePubkey);
stdout.write("$pronoun have ${followers.length} followers: ");
followers.forEach((x) => stdout.write("${getAuthorName(x)}, "));
print("");
print("");
}
int showMenu(List<String> menuOptions, String menuName) {
print("\n$menuName\n${getNumDashes(menuName.length)}");
print('Pick an option:');
@ -259,47 +313,7 @@ Future<void> otherMenuUi(Store node) async {
print("Could not find the user with that id or username.");
}
else {
String pk = pubkey.first;
bool onlyUserPostAndLike (Tree t) => t.hasUserPostAndLike(pk);
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), onlyUserPostAndLike);
// get the latest kind 3 event for the user, which lists his 'follows' list
Event? contactEvent = getContactEvent(pubkey.first);
// if contact list was found, get user's feed, and keep the contact list for later use
String authorName = gKindONames[pubkey.first]?.name??"";
printUnderlined("\nProfile for User");
print("\nName : $authorName ( ${pubkey.first} ).");
if (contactEvent != null ) {
String about = gKindONames[pubkey.first]?.about??"";
String picture = gKindONames[pubkey.first]?.picture??"";
int dateLastUpdated = gKindONames[pubkey.first]?.createdAt??0;
print("About : $about");
print("Picture : $picture");
print("Last Updated: ${getPrintableDate(dateLastUpdated)}");
if( contactEvent.eventData.contactList.any((x) => (x.id == userPublicKey))) {
print("\n* They follow you");
} else {
print("\n* They don't follow you");
}
// print social distance info.
node.printSocialDistance(pubkey.first, authorName);
print("");
stdout.write("They follow ${contactEvent.eventData.contactList.length} accounts: ");
contactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.id)}, "));
print("\n");
}
List<String> followers = node.getFollowers(pubkey.first);
stdout.write("They have ${followers.length} followers: ");
followers.forEach((x) => stdout.write("${getAuthorName(x)}, "));
print("");
print("");
printProfile(node, pubkey.first);
}
}
}
@ -721,3 +735,5 @@ Future<void> mainMenuUi(Store node) async {
} // end menu switch
} // end while
} // end mainMenuUi()

View File

@ -1300,12 +1300,15 @@ class Store {
// finds all your followers, and then finds which of them follow the otherPubkey
void printSocialDistance(String otherPubkey, String otherName) {
String otherName = getAuthorName(otherPubkey);
Event? contactEvent = getContactEvent(userPublicKey);
bool isFollow = false;
int numSecond = 0; // number of your follows who follow the other
List<String> mutualFollows = [];
int numContacts = 0;
if( contactEvent != null) {
List<Contact> contacts = contactEvent.eventData.contactList;
@ -1322,19 +1325,29 @@ class Store {
followContactList = followContactEvent.eventData.contactList;
for(int j = 0; j < followContactList.length; j++) {
if( followContactList[j].id == otherPubkey) {
mutualFollows.add(getAuthorName(contacts[i].id));
numSecond++;
break;
}
}
}
}// end for loop through users contacts
if( isFollow) {
print("* You follow $otherName ");
} else {
print("* You don't follow $otherName");
}
print("* Of the $numContacts people you follow, $numSecond follow $otherName");
//print("");
if( otherPubkey != userPublicKey) {
if( isFollow) {
print("* You follow $otherName ");
} else {
print("* You don't follow $otherName");
}
stdout.write("* Of the $numContacts people you follow, $numSecond follow $otherName.");
} else {
stdout.write("* Of the $numContacts people you follow, $numSecond follow you back. Their names are: ");
mutualFollows.forEach((name) { stdout.write("$name, ");});
}
print("");
} // end if contact event was found
}

View File

@ -4,7 +4,7 @@ version: 0.0.7-beta
homepage: https://github.com/vishalxl/nostr_console
# got all 40 and 42 events too
# mutual follows
environment:
sdk: '>=2.17.3 <3.0.0'