diff --git a/lib/console_ui.dart b/lib/console_ui.dart index f5ac31b..f7bef22 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -16,12 +16,15 @@ Future processAnyIncomingEvents(Store node, [bool printNotifications = tru const int waitMilliSeconds = 200; Future.delayed(const Duration(milliseconds: waitMilliSeconds), () { - node.processIncomingEvent(getRecievedEvents()); + Set newEventIds = node.processIncomingEvent(getRecievedEvents()); clearEvents(); + Point numPrinted1 = Point(0,0); if( printNotifications) { - showAllNotifications(node); + numPrinted1 = node.printTreeNotifications(newEventIds); } + + showAllNotifications(node, numPrinted1.x.toInt(), numPrinted1.y.toInt()); }); @@ -1210,7 +1213,9 @@ Future socialMenuUi(Store node) async { } await sendReplyPostLike(node, replyToId, replyKind, content); - await processAnyIncomingEvents(node, false); + clearScreen(); + + await processAnyIncomingEvents(node, true); break; case 3: @@ -1387,12 +1392,12 @@ Future socialMenuUi(Store node) async { } // end while } // end socialMenuUi() -void showAllNotifications(Store node) { +void showAllNotifications(Store node, [int x = 0, int y = 0]) { - //printUnderlined("Notifications:"); + Point numPrinted = Point(x, y); bool hasNotifications (Tree t) => t.treeSelectorNotifications(); - Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), hasNotifications); + numPrinted += node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), hasNotifications); int numNotificationsPrinted = numPrinted.y.toInt(); bool showNotifications (ScrollableMessages room) => room.selectorNotifications(); @@ -1413,7 +1418,7 @@ Future mainMenuUi(Store node) async { clearScreen(); //Show only notifications - showAllNotifications(node); + await processAnyIncomingEvents(node); // this takes 300 ms bool mainMenuContinue = true; bool firstTime = true; diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index 003cf01..b056eed 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -1343,10 +1343,8 @@ class Store { * @printNotifications Add the given events to the Tree, and print the events as notifications * It should be ensured that these are only kind 1 events */ - void printNotifications(Set newEventIdsSet, String userName) { - if( gDebug > 0) print("Info: in printNotifications: num new evetns = ${newEventIdsSet.length}"); + Point printTreeNotifications(Set newEventIdsSet) { - String strToWrite = ""; int countNotificationEvents = 0; for( var newEventId in newEventIdsSet) { int k = (allChildEventsMap[newEventId]?.event.eventData.kind??-1); @@ -1361,18 +1359,11 @@ class Store { } } - if(gDebug > 0) print("Info: In printNotifications: newEventsId = $newEventIdsSet count17 = $countNotificationEvents"); - if( countNotificationEvents == 0) { - return; + return Point(0,0); } - // TODO call count() less - strToWrite += "Number of new replies/posts = ${newEventIdsSet.length}\n"; - stdout.write("${getNumDashes(strToWrite.length -1 )}\n$strToWrite"); - //stdout.write("Total posts : ${count()}\n"); - stdout.write("Signed in as : $userName\n"); - stdout.write("\nHere are the threads with new replies or new likes: \n\n"); - + + List topNotificationTree = []; // collect all top tress to display in this list. only unique tress will be displayed newEventIdsSet.forEach((eventID) { @@ -1422,14 +1413,16 @@ class Store { // remove duplicate top trees Set ids = {}; topNotificationTree.retainWhere((t) => ids.add(t.event.eventData.id)); - Store.reCalculateMarkerStr(); + Point retval = Point(0,0); topNotificationTree.forEach( (t) { - Store.printTopPost(t, 0, DateTime(0)); + retval += Store.printTopPost(t, 0, DateTime(0)); print("\n"); }); + + return retval; } static Point printTopPost(Tree topTree, int depth, DateTime newerThan) { @@ -1712,7 +1705,7 @@ class Store { if( iNotification++ > numNotificationRooms) { break; } - + DirectMessageRoom room = directRooms[j]; String id = room.otherPubkey.substring(0, 6); String name = getAuthorName(room.otherPubkey, 4); diff --git a/pubspec.yaml b/pubspec.yaml index 3482df9..71f7e52 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,6 +9,7 @@ homepage: https://github.com/vishalxl/nostr_console # chmod in actions # improved channel display # /help in enc groups +# still fixing notifications environment: