diff --git a/bin/nostr_console.dart b/bin/nostr_console.dart index 98b5b37..0b56b73 100644 --- a/bin/nostr_console.dart +++ b/bin/nostr_console.dart @@ -93,23 +93,23 @@ Future main(List arguments) async { return; } userPrivateKey = ""; - print("Going to use public key $userPublicKey. You will not be able to send posts/replies."); } + + // process private key argument, and it overrides what's given in pub key argument, if any pubkey is given if( argResults[prikeyArg] != null) { userPrivateKey = argResults[prikeyArg]; if( userPrivateKey.length != 64){ print("Length of provided private key should be 64. Exiting."); return; } - userPublicKey = myGetPublicKey(userPrivateKey); + userPublicKey = myGetPublicKey(userPrivateKey); print("Going to use the provided private key"); } - // write informative message in case user is using the default private key + // write informative message in case user is not using proper keys if( userPublicKey == gDefaultPublicKey) { - print("${gWarningColor}You seem to be using the default public key starting with e8c, which comes bundled with this $exename "); print("You should ideally create your own private key and use it with ${gWarningColor}--prikey$gColorEndMarker program argument. "); - print("You can create your own private key from ${gWarningColor}astral.ninja, branle.netlify.app$gColorEndMarker, or other such tools.\n"); + print("Create a private key from ${gWarningColor}astral.ninja, @damusapp or anigma.io, or even from command line using `openssl rand -hex 32`.$gColorEndMarker.\n"); } // handle relay related argument @@ -297,8 +297,10 @@ Future main(List arguments) async { } // get event for user - getUserEvents(gListRelayUrls1, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); - getMentionEvents(gListRelayUrls2, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); // from relay group 2 + if( userPublicKey!= "") { + getUserEvents(gListRelayUrls1, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); + getMentionEvents(gListRelayUrls2, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); // from relay group 2 + } // get other user events getMultiUserEvents(gListRelayUrls1, gDefaultFollows, limitPerSubscription, getSecondsDaysAgo(limitFollowPosts)); @@ -326,27 +328,27 @@ Future main(List arguments) async { if( gDebug > 0) log.info("Received user events."); initialEvents.forEach((e) => processKind3Event(e)); // first process the kind 3 event - // get the latest kind 3 event for the user, which lists his 'follows' list - Event? contactEvent = getContactEvent(userPublicKey); + + if( userPublicKey != "") { + // get the latest kind 3 event for the user, which lists his 'follows' list + Event? contactEvent = getContactEvent(userPublicKey); - // if contact list was found, get user's feed; also get some default contacts - Set contacts = {}; - //contacts.addAll(gDefaultFollows); - if (contactEvent != null ) { - if(gDebug > 0) print("In main: found contact list: \n ${contactEvent.originalJson}"); - contactEvent.eventData.contactList.forEach((contact) { - contacts.add(contact.id); - }); + // if contact list was found, get user's feed; also get some default contacts + Set contacts = {}; + //contacts.addAll(gDefaultFollows); + if (contactEvent != null ) { + if(gDebug > 0) print("In main: found contact list: \n ${contactEvent.originalJson}"); + contactEvent.eventData.contactList.forEach((contact) { + contacts.add(contact.id); + }); + } + getContactFeed(gListRelayUrls1, contacts, gLimitPerSubscription, getSecondsDaysAgo(2 * limitFollowPosts)); } - getContactFeed(gListRelayUrls1, contacts, gLimitPerSubscription, getSecondsDaysAgo(2 * limitFollowPosts)); // calculate top mentioned ptags, and then get the events for those users - //log.info('calling getpTags'); List pTags = getpTags(initialEvents, gMaxPtagsToGet); - //log.info('after getpTags\n'); getMultiUserEvents(gListRelayUrls1, pTags, gLimitPerSubscription, getSecondsDaysAgo(limitFollowPosts)); - stdout.write('Waiting for feed to come in..............'); Future.delayed(Duration(milliseconds: gDefaultNumWaitSeconds * 1), () { @@ -357,10 +359,7 @@ Future main(List arguments) async { if( gDebug > 0) log.info("Received ptag events events."); // Creat tree from all events read form file - //log.info("going to call getTree."); Store node = getTree(initialEvents); - //node.printEventInfo(); - //log.info("after getTree returned."); gStore = node; clearEvents(); diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 3985abf..6e23869 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -19,7 +19,7 @@ Future processAnyIncomingEvents(Store node, [bool printNotifications = tru String nameToDisplay = userPrivateKey.length == 64? "$gCommentColor${getAuthorName(userPublicKey)}$gColorEndMarker": - "${gWarningColor}You are not signed in$gColorEndMarker but are using public key $userPublicKey"; + "${gWarningColor}You are not signed in$gColorEndMarker"; if( printNotifications) { node.printNotifications(newEventIdsSet, nameToDisplay); @@ -414,11 +414,11 @@ int showMenu(List menuOptions, String menuName, [String menuInfo = ""]) print("\n"); printMenu(menuOptions); - String nameToDisplay = userPrivateKey.length == 64? - "$gCommentColor${getAuthorName(userPublicKey)}$gColorEndMarker": - "${gWarningColor}You are not signed in$gColorEndMarker but are using public key $userPublicKey"; + String promptWithName = userPrivateKey.length == 64? + "Signed in as $gCommentColor${getAuthorName(userPublicKey)}$gColorEndMarker": + "${gWarningColor}You are not signed in so can't send any messages$gColorEndMarker"; - stdout.write("Signed in as $nameToDisplay. "); + stdout.write("$promptWithName. "); stdout.write("Type option number: "); String? userOptionInput = stdin.readLineSync(); String userOption = userOptionInput??""; @@ -493,6 +493,11 @@ Future otherOptionsMenuUi(Store node) async { case 2: //edit your profile + if( userPublicKey == "" || userPrivateKey == "") { + printWarning("No private key provided so you can't edit your profile."); + break; + } + print("Your current name: ${getAuthorName(userPublicKey)}"); print("Your 'about me': ${gKindONames[userPublicKey]?.about}"); print("Your current profile picture: ${gKindONames[userPublicKey]?.picture}\n"); @@ -515,6 +520,11 @@ Future otherOptionsMenuUi(Store node) async { break; case 3: + if( userPublicKey == "" || userPrivateKey == "") { + printWarning("No private key provided so you can't delete any event."); + break; + } + stdout.write("Enter event id to delete: "); String? $tempEventId = stdin.readLineSync(); String userInputId = $tempEventId??""; diff --git a/lib/event_ds.dart b/lib/event_ds.dart index bc33a85..cac223d 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -1499,7 +1499,7 @@ extension StringX on String { // https://www.thoughtco.com/most-common-french-words-1372759 Set frenchWords = {"oui", "je", "le", "un", "de", "et", "merci", "une", "ce", "pas"}; - Set spanishWords = {"y", "se", "el", "uso", "que", "te", "los", "va", "ser", "si", "por", "lo", "es", "era", "un"};; + Set spanishWords = {"y", "se", "el", "uso", "que", "te", "los", "va", "ser", "si", "por", "lo", "es", "era", "un", "o"};; Set romanceWords = frenchWords.union(spanishWords); for( String word in romanceWords) { diff --git a/lib/settings.dart b/lib/settings.dart index d24b459..44a49b2 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -58,7 +58,7 @@ List gListRelayUrls2 = [ ]; // well known disposable test private key -const String gDefaultPublicKey = "e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f7e0a02c29388180"; +const String gDefaultPublicKey = ""; String userPrivateKey = ""; String userPublicKey = gDefaultPublicKey; diff --git a/pubspec.yaml b/pubspec.yaml index 323426b..3b8ce77 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ homepage: https://github.com/vishalxl/nostr_console # Release 0.1.9-beta # used kind 104 # fix for tag related test fail -# removed debug prints +# default without argument invocation now possible with no pubkey environment: sdk: '>=2.17.3 <3.0.0' diff --git a/test/nostr_console_test.dart b/test/nostr_console_test.dart index 3b2defd..1ecc7c0 100644 --- a/test/nostr_console_test.dart +++ b/test/nostr_console_test.dart @@ -251,7 +251,7 @@ String expectedResult = Store node = await getTree(initialEvents); //await node.printDirectRoomInfo(showAllRooms); - expect(7, node.getNumDirectRooms(), reason:'verify correct number of direct chat rooms created'); + expect(0, node.getNumDirectRooms(), reason:'verify correct number of direct chat rooms created'); expect(78, node.getNumChannels(), reason: 'verify correct number of public channels created'); expect(3046, node.getNumMessagesInChannel('25e5c82273a271cb1a840d0060391a0bf4965cafeb029d5ab55350b418953fbb'),