diff --git a/bin/nostr_console.dart b/bin/nostr_console.dart index ad204d8..061b8e6 100644 --- a/bin/nostr_console.dart +++ b/bin/nostr_console.dart @@ -263,7 +263,7 @@ Future main(List arguments) async { gContactLists[userPublicKey] = contactEvent.eventData.contactList; } } else { - if( gDebug >= 0) log.info( "Could not find contact list"); + if( gDebug > 0) log.info( "Could not find contact list"); } stdout.write('Waiting for feed to come in..............'); diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 0f9ee7b..a86ced0 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -455,21 +455,14 @@ Future channelMenuUI(Store node) async { while(continueChatMenu) { int option = showMenu([ 'Show public channels', // 1 'Enter a public channel', // 2 - 'See personal Inbox', - 'Reply or Send a direct message', - 'Go back to main menu'], // 5 - "Channel Menu"); // name of menu + 'Go back to main menu'], // 3 + "Public Channels Menu"); // name of menu print('You picked: $option'); switch(option) { case 1: node.printAllChannelsInfo(); break; case 2: - // in case the program was invoked with --pubkey, then user can't send messages - if( userPrivateKey == "") { - print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n"); - break; - } bool showChannelOption = true; stdout.write("\nType channel id or name, or their 1st few letters; or type 'x' to go to menu: "); @@ -499,9 +492,16 @@ Future channelMenuUI(Store node) async { if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) { pageNum = (int.tryParse(messageToSend))??1; } else { - // send message to the given room - await sendChatMessage(node, fullChannelId, messageToSend); - pageNum = 1; // reset it + + // in case the program was invoked with --pubkey, then user can't send messages + if( userPrivateKey == "") { + print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n"); + + } else { + // send message to the given room + await sendChatMessage(node, fullChannelId, messageToSend); + pageNum = 1; // reset it + } } } } else { @@ -513,11 +513,32 @@ Future channelMenuUI(Store node) async { break; case 3: + continueChatMenu = false; + break; + + default: + break; + } + } + return; +} + +Future PrivateMenuUI(Store node) async { + //gDebug = 0; + bool continueChatMenu = true; + while(continueChatMenu) { + int option = showMenu([ 'See personal Inbox', + 'Reply or Send a direct message', + 'Go back to main menu'], // 5 + "Private Message Menu"); // name of menu + print('You picked: $option'); + switch(option) { + case 1: //print("total direct rooms = ${node.directRooms.length}"); node.printDirectRoomInfo(); break; - case 4: + case 2: // in case the program was invoked with --pubkey, then user can't send messages if( userPrivateKey == "") { print("Since no private key has been supplied, messages and replies can't be sent. Invoke with --prikey \n"); @@ -552,9 +573,13 @@ Future channelMenuUI(Store node) async { if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) { pageNum = (int.tryParse(messageToSend))??1; } else { - // send message to the given room - await sendDirectMessage(node, fullChannelId, messageToSend); - pageNum = 1; // reset it + // in case the program was invoked with --pubkey, then user can't send messages + if( userPrivateKey == "") { + print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n"); + } + // send message to the given room + await sendDirectMessage(node, fullChannelId, messageToSend); + pageNum = 1; // reset it } } } else { @@ -566,7 +591,7 @@ Future channelMenuUI(Store node) async { break; - case 5: + case 3: continueChatMenu = false; break; @@ -577,15 +602,16 @@ Future channelMenuUI(Store node) async { return; } -Future mainMenuUi(Store node) async { - //gDebug = 0; - // at the very beginning, show the tree as it is, and then show the options menu +Future mainMenuUi(Store node) async { + + // at the very beginning, show the tree with re reply and likes, and then show the options menu bool hasRepliesAndLikes (Tree t) => t.hasRepliesAndLikes(userPublicKey); node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), hasRepliesAndLikes); bool userContinue = true; while(userContinue) { + // align the text again in case the window size has been changed if( gAlignment == "center") { try { @@ -600,14 +626,15 @@ Future mainMenuUi(Store node) async { } } - await processNotifications(node); + await processNotifications(node); // this takes 300 ms // the main menu int option = showMenu(['Display feed', // 1 'Post/Reply/Like', // 2 - 'Direct Messsage and Public Channels', // 3 - 'Other Options', // 4 - 'Quit'], // 5 + 'Public Channels', // 3 + 'Private Messages', // 4 + 'Other Options', // 5 + 'Quit'], // 6 "Main Menu"); print('You picked: $option'); switch(option) { @@ -650,10 +677,14 @@ Future mainMenuUi(Store node) async { break; case 4: - await otherMenuUi(node); + await PrivateMenuUI(node); break; case 5: + await otherMenuUi(node); + break; + + case 6: default: userContinue = false; String authorName = getAuthorName(userPublicKey); diff --git a/lib/event_ds.dart b/lib/event_ds.dart index 6616c77..14265bc 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -198,7 +198,10 @@ class EventData { break; case 4: - if( pubkey == userPublicKey) break; // crashes right now otherwise + if( userPrivateKey == ""){ // cant process if private key not given + break; + } + if( pubkey == userPublicKey ) break; // crashes right now otherwise if(!isUserDirectMessage(this)) { break; } @@ -540,7 +543,7 @@ String getAuthorName(String pubkey, [int len = 3]) { Set getPublicKeyFromName(String userName) { Set pubkeys = {}; - if(gDebug >= 0) print("In getPublicKeyFromName: doing lookup for $userName len of gKindONames= ${gKindONames.length}"); + //if(gDebug > 0) print("In getPublicKeyFromName: doing lookup for $userName len of gKindONames= ${gKindONames.length}"); gKindONames.forEach((pk, userInfo) { // check both the user name, and the pubkey to search for the user @@ -550,7 +553,7 @@ Set getPublicKeyFromName(String userName) { } if( userName.length <= pk.length) { - print("$pk $userName" ); + //print("$pk $userName" ); if( pk.substring(0, userName.length) == userName) { pubkeys.add(pk); } diff --git a/lib/settings.dart b/lib/settings.dart index 3b8fc57..c32166f 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -10,10 +10,11 @@ const int gDefaultNumWaitSeconds = 3000; // is used in main() const String gDefaultEventsFilename = "all_nostr_events.txt"; String gEventsFilename = ""; // is set in arguments, and if set, then file is read from and written to bool gDontWriteOldEvents = true; -const int gDontSaveBeforeDays = 100; // dont save events older than this many days if gDontWriteOldEvents flag is true +const int gDontSaveBeforeDays = 100; // dont save events older than this many days if gDontWriteOldEvents flag is true + const int gDaysToGetEventsFor = 100; // when getting events, this is the since field (unless a fully formed request is given in command line) -const int gLimitPerSubscription = 20000; +const int gLimitPerSubscription = 10000; // don't show notifications for events that are older than 5 days and come when program is running // applicable only for notifications and not for search results. Search results set a flag in EventData and don't use this variable diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index 7820e87..8fde14e 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -825,7 +825,7 @@ class Store { */ void printDirectRoomInfo() { print("\n\nDirect messages inbox:"); - printUnderlined(" From Num of Messages Latest Message "); + printUnderlined(" From Num of Messages Latest Message "); directRooms.forEach((key, value) { String name = getAuthorName(key, 4); @@ -849,7 +849,7 @@ class Store { // shows the given directRoomId, where directRoomId is prefix-id or pubkey of the other user. returns full id of other user. String showDirectRoom(String directRoomId, [int page = 1]) { - print("In show DirectRoom $directRoomId"); + //print("In show DirectRoom $directRoomId"); if( directRoomId.length > 64) { // TODO revisit cause if name is > 64 should not return return ""; } @@ -857,7 +857,7 @@ class Store { // TODO improve lookup logic. directRooms.forEach((roomId, directRoom) { - print("looking up $directRoomId in $roomId ${directRoom.otherPubkey}"); + //print("looking up $directRoomId in $roomId ${directRoom.otherPubkey}"); if( directRoomId == roomId) { lookedUpName.add(roomId); }