fixed issue where a well known key's about me ...

.. name was appended with a tick if they edited their profile.
This commit is contained in:
Vishal 2022-12-28 01:00:34 +05:30
parent 6ac26f37b2
commit a9b71b1140
3 changed files with 20 additions and 24 deletions

View File

@ -303,7 +303,7 @@ void printProfile(Store node, String profilePubkey) {
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyUserPostAndLike);
// if contact list was found, get user's feed, and keep the contact list for later use
String authorName = getAuthorName(profilePubkey, 0);
String authorName = getAuthorName(profilePubkey, addTickForWellKnown: false );
String pronoun = "";
if( profilePubkey == userPublicKey) {
printUnderlined("\nYour profile - $authorName:");
@ -382,7 +382,7 @@ void printProfile(Store node, String profilePubkey) {
// print follow list
stdout.write("$pronoun follow ${profileContactEvent.eventData.contactList.length} accounts: ");
profileContactEvent.eventData.contactList.sort();
profileContactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.contactPubkey, 0)}, "));
profileContactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.contactPubkey)}, "));
print("\n");
}
@ -390,7 +390,7 @@ void printProfile(Store node, String profilePubkey) {
List<String> followers = node.getFollowers(profilePubkey);
stdout.write("$pronoun have ${followers.length} followers: ");
followers.sort((a, b) => getAuthorName(a).compareTo(getAuthorName(b)));
followers.forEach((x) => stdout.write("${getAuthorName(x, 0)}, "));
followers.forEach((x) => stdout.write("${getAuthorName(x)}, "));
print("");
print("");
}
@ -508,7 +508,7 @@ int showMenu(List<String> menuOptions, String menuName, [String menuInfo = ""])
void printPubkeys(Set<String> pubkey) {
print("${myPadRight("pubkey",64)} ${myPadRight("name", 20)} ${myPadRight("about", 40)} ${myPadRight("Nip05", 30)}");
pubkey.forEach( (x) => print("$x ${myPadRight(getAuthorName(x), 20)} ${myPadRight(gKindONames[x]?.about??"", 40)} ${myPadRight(gKindONames[x]?.nip05Id??"No", 30)}"));
pubkey.forEach( (x) => print("$x ${myPadRight(getAuthorName(x), 20)} ${myPadRight(gKindONames[x]?.about??"", 40)} ${myPadRight(gKindONames[x]?.nip05Id??"No", 30)}"));
print("");
}
@ -1628,7 +1628,7 @@ Future<void> mainMenuUi(Store node) async {
case 7:
default:
mainMenuContinue = false;
String authorName = getAuthorName(userPublicKey, 0);
String authorName = getAuthorName(userPublicKey);
clearScreen();
print("\nFinished Nostr session for user: ${authorName} ($userPublicKey)");
if( gEventsFilename != "") {

View File

@ -1203,8 +1203,7 @@ String getNip05Name( String pubkey) {
}
// returns name by looking up global list gKindONames, which is populated by kind 0 events
// if maxDisplayLen is 0 it means the length can be any max length
String getAuthorName(String pubkey, [int maxDisplayLen = 12, int pubkeyLenShown = 5]) {
String getAuthorName(String pubkey, {bool addTickForWellKnown = true, int maxDisplayLen = gMaxInteger, int pubkeyLenShown = 5}) {
String maxLen(String pubkey) => pubkey.length > pubkeyLenShown? pubkey.substring(0,pubkeyLenShown) : pubkey.substring(0, pubkey.length);
String name = "";
@ -1214,22 +1213,19 @@ String getAuthorName(String pubkey, [int maxDisplayLen = 12, int pubkeyLenShown
name = (gKindONames[pubkey]?.name)??maxLen(pubkey);
}
// first remove the check mark if its in any name
name = name.replaceAll(gValidCheckMark, "");
if( addTickForWellKnown) {
// 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 >= maxDisplayLen ) {
name = name.substring(0, maxDisplayLen-1) + gValidCheckMark;
} else {
name = name + gValidCheckMark;
// then add valid check mark in default follows
if( gDefaultFollows.contains(pubkey)) {
if( name.length >= maxDisplayLen ) {
name = name.substring(0, maxDisplayLen-1) + gValidCheckMark;
} else {
name = name + gValidCheckMark;
}
}
}
return name;
}

View File

@ -383,7 +383,7 @@ class DirectMessageRoom extends ScrollableMessages{
int createdAt;
DirectMessageRoom(this.otherPubkey, List<String> messageIds, this.createdAt):
super ( "${getAuthorName(otherPubkey)} ($otherPubkey)", messageIds, createdAt, enumRoomType.kind4) {
super ( "${(otherPubkey)} ($otherPubkey)", messageIds, createdAt, enumRoomType.kind4) {
}
String getChannelId() {
@ -1950,7 +1950,7 @@ class Store {
DirectMessageRoom room = directRooms[j];
String id = room.otherPubkey.substring(0, 6);
String name = getAuthorName(room.otherPubkey, 4);
String name = getAuthorName(room.otherPubkey, maxDisplayLen: 4);
void markAllRead (Event e) => e.eventData.isNotification = false;
room.visitAllMessages(this, markAllRead);
@ -2347,7 +2347,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, 0);
String otherName = getAuthorName(otherPubkey);
bool isFollow = false;
@ -2374,7 +2374,7 @@ class Store {
followContactList = followContactEvent.eventData.contactList;
for(int j = 0; j < followContactList.length; j++) {
if( followContactList[j].contactPubkey == otherPubkey) {
mutualFollows.add(getAuthorName(selfContacts[i].contactPubkey, 0));
mutualFollows.add(getAuthorName(selfContacts[i].contactPubkey));
numSecond++;
break;
}