From a9b71b1140e079d2ceac1b6b584ec8b555e1dce7 Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Wed, 28 Dec 2022 01:00:34 +0530 Subject: [PATCH] fixed issue where a well known key's about me ... .. name was appended with a tick if they edited their profile. --- lib/console_ui.dart | 10 +++++----- lib/event_ds.dart | 26 +++++++++++--------------- lib/tree_ds.dart | 8 ++++---- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 26a260d..42bd09a 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -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 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 menuOptions, String menuName, [String menuInfo = ""]) void printPubkeys(Set 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 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 != "") { diff --git a/lib/event_ds.dart b/lib/event_ds.dart index 7b787a1..329b0b1 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -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; } diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index b9c4b5f..9a7ed31 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -383,7 +383,7 @@ class DirectMessageRoom extends ScrollableMessages{ int createdAt; DirectMessageRoom(this.otherPubkey, List 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; }