improved check mark display

names were cut where they didn't needed to be cut.
This commit is contained in:
Vishal 2022-12-25 02:07:31 +05:30
parent b58b722d80
commit 62d838edb5
3 changed files with 13 additions and 8 deletions

View File

@ -297,7 +297,7 @@ void printProfile(Store node, String profilePubkey) {
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), onlyUserPostAndLike);
// if contact list was found, get user's feed, and keep the contact list for later use
String authorName = getAuthorName(profilePubkey);
String authorName = getAuthorName(profilePubkey, 0);
String pronoun = "";
if( profilePubkey == userPublicKey) {
printUnderlined("\nYour profile - $authorName:");
@ -345,14 +345,14 @@ void printProfile(Store node, String profilePubkey) {
// print follow list
stdout.write("$pronoun follow ${profileContactEvent.eventData.contactList.length} accounts: ");
profileContactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.id)}, "));
profileContactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.id, 0)}, "));
print("\n");
}
// print followers
List<String> followers = node.getFollowers(profilePubkey);
stdout.write("$pronoun have ${followers.length} followers: ");
followers.forEach((x) => stdout.write("${getAuthorName(x)}, "));
followers.forEach((x) => stdout.write("${getAuthorName(x, 0)}, "));
print("");
print("");
}

View File

@ -1183,7 +1183,8 @@ String getNip05Name( String pubkey) {
}
// returns name by looking up global list gKindONames, which is populated by kind 0 events
String getAuthorName(String pubkey, [int pubkeyLenShown = 5]) {
// if maxDisplayLen is 0 it means the length can be any max length
String getAuthorName(String pubkey, [int maxDisplayLen = 12, int pubkeyLenShown = 5]) {
String maxLen(String pubkey) => pubkey.length > pubkeyLenShown? pubkey.substring(0,pubkeyLenShown) : pubkey.substring(0, pubkey.length);
String name = "";
@ -1196,10 +1197,14 @@ String getAuthorName(String pubkey, [int pubkeyLenShown = 5]) {
// first remove the check mark if its in any name
name = name.replaceAll(gValidCheckMark, "");
if( maxDisplayLen == 0) {
maxDisplayLen = name.length + 1;
}
// then add valid check mark in default follows
if( gDefaultFollows.contains(pubkey)) {
if( name.length >= gNameLenDisplayed ) {
name = name.substring(0, gNameLenDisplayed-1) + gValidCheckMark;
if( name.length >= maxDisplayLen ) {
name = name.substring(0, maxDisplayLen-1) + gValidCheckMark;
} else {
name = name + gValidCheckMark;
}

View File

@ -2230,7 +2230,7 @@ class Store {
// finds all your followers, and then finds which of them follow the otherPubkey
void printMutualFollows(Event contactEvent, String otherName) {
String otherPubkey = contactEvent.eventData.pubkey;
String otherName = getAuthorName(otherPubkey);
String otherName = getAuthorName(otherPubkey, 0);
bool isFollow = false;
@ -2256,7 +2256,7 @@ class Store {
followContactList = followContactEvent.eventData.contactList;
for(int j = 0; j < followContactList.length; j++) {
if( followContactList[j].id == otherPubkey) {
mutualFollows.add(getAuthorName(selfContacts[i].id));
mutualFollows.add(getAuthorName(selfContacts[i].id, 0));
numSecond++;
break;
}