Skip to content

Commit

Permalink
added flag userRelevant to improve event printing at end. now every e…
Browse files Browse the repository at this point in the history
…vent that's printed for user gets saved at end
  • Loading branch information
vishalxl committed Apr 21, 2024
1 parent f22851e commit 151a00c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bin/nostr_console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Future<void> main(List<String> arguments) async {
initialEvents = readEventsFromFile(gEventsFilename);

// count events
for (var element in initialEvents) { numFileEvents++;}
numFileEvents += initialEvents.length;
print("read $numFileEvents events from file $gEventsFilename");
}

Expand Down
12 changes: 6 additions & 6 deletions lib/console_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ Future<void> socialMenuUi(Store node) async {
switch(option) {
case 1:
bool selectorTrees_followActionsNoNotifications (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey).union(gDefaultFollows).union({userPublicKey}), enableNotifications: false);
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActionsNoNotifications);
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActionsNoNotifications, true);
await processAnyIncomingEvents(node, true);
break;

Expand Down Expand Up @@ -1398,7 +1398,7 @@ Future<void> socialMenuUi(Store node) async {
clearScreen();
bool selectorTrees_userNotifications (Tree t) => t.treeSelectorotificationsFor({userPublicKey});
int notificationHours = gHoursDefaultPrint>24? gHoursDefaultPrint: 24; // minimum 24
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications, true);
if( numPrinted[2] > 0) {
print("Showed ${numPrinted[2]} replies/likes that were made to your posts.\n");
} else {
Expand All @@ -1409,7 +1409,7 @@ Future<void> socialMenuUi(Store node) async {
break;
case 4:
clearScreen();
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_selfPosts);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_selfPosts, true);
if( numPrinted[0] > 0) {
print("Showed ${numPrinted[0]} posts made by you in last $gHoursDefaultPrint hours.\n");
} else {
Expand All @@ -1421,7 +1421,7 @@ Future<void> socialMenuUi(Store node) async {
case 5:
clearScreen();
bool selectorTrees_userActions (Tree t) => t.treeSelectorUserPostAndLike({userPublicKey});
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userActions);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userActions, true);
if( numPrinted[0] > 0) {
print("Showed ${numPrinted[0]} thread where you replied or liked in in last $gHoursDefaultPrint hours.\n");
} else {
Expand All @@ -1433,7 +1433,7 @@ Future<void> socialMenuUi(Store node) async {
case 6:
clearScreen();
bool selectorTrees_followActionsWithNotifications (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey), enableNotifications: true);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActionsWithNotifications);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActionsWithNotifications, true);
if( numPrinted[0] > 0) {
print("Showed ${numPrinted[0]} threads where your follows participated.\n");
} else {
Expand All @@ -1449,7 +1449,7 @@ Future<void> socialMenuUi(Store node) async {
String words = $tempWords??"";
if( words != "") {
bool onlyWords (Tree t) => t.treeSelectorHasWords(words.toLowerCase());
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyWords, gMaxInteger); // search for last default hours only
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyWords, false, gMaxInteger); // search for last default hours only
if( numPrinted[0] == 0) {
print("\nNot found in the last $gHoursDefaultPrint hours. Try increasing the number of days printed, from social network options to search further back into history.\n");
}
Expand Down
3 changes: 2 additions & 1 deletion lib/event_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,9 @@ class Event {
String originalJson;
List<String> seenOnRelays;
bool readFromFile;
bool userRelevant; // is made true if the event has been printed for the user ( and its relevant to user, which will later be saved in file)

Event(this.event, this.id, this.eventData, this.seenOnRelays, this.originalJson, [this.readFromFile = false]);
Event(this.event, this.id, this.eventData, this.seenOnRelays, this.originalJson, [this.readFromFile = false, this.userRelevant = false]);

@override
bool operator ==( other) {
Expand Down
26 changes: 18 additions & 8 deletions lib/tree_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,20 @@ class Tree {
* returns Point , where first int is total Threads ( or top trees) printed, and second is notifications printed
* returns list< total top threads printed, total events printed, total notifications printed>
*/
List<int> printTree(int depth, DateTime newerThan, bool topPost, [int countPrinted = 0, int maxToPrint = gMaxEventsInThreadPrinted]) {
List<int> printTree(int depth, DateTime newerThan, bool topPost, [int countPrinted = 0, int maxToPrint = gMaxEventsInThreadPrinted, bool userRelevant = false]) {
List<int> ret = [0,0,0];

if(event.eventData.isNotification || event.eventData.newLikes.isNotEmpty) {
ret[2] = 1;
}

countPrinted++;

// toggle flag which will save the event and program end
if( userRelevant == true) {
event.userRelevant = true;
}

event.printEvent(depth, topPost);
ret[1] = 1;

Expand Down Expand Up @@ -452,7 +458,7 @@ class Tree {
leftShifted = true;
}

List<int> temp = children[i].printTree(depth+1, newerThan, false, countPrinted, maxToPrint);
List<int> temp = children[i].printTree(depth+1, newerThan, false, countPrinted, maxToPrint, userRelevant);
ret[1] += temp[1];
ret[2] += temp[2];
countPrinted += temp[1];
Expand Down Expand Up @@ -1677,12 +1683,12 @@ class Store {
}

// returns list , where first int is total Threads ( or top trees) printed, second is total events printed, and third is notifications printed
static List<int> printTopPost(Tree topTree, int depth, DateTime newerThan, [int maxToPrint = gMaxEventsInThreadPrinted]) {
static List<int> printTopPost(Tree topTree, int depth, DateTime newerThan, [int maxToPrint = gMaxEventsInThreadPrinted, bool userRelevant = false]) {
stdout.write(Store.startMarkerStr);

//if(topTree.event.eventData.isNotification) print('is notification');

List<int> counts = topTree.printTree(depth, newerThan, true, 0, maxToPrint);
List<int> counts = topTree.printTree(depth, newerThan, true, 0, maxToPrint, userRelevant);
counts[0] += 1; // for this top post
stdout.write(endMarkerStr);
//print("In node printTopPost: ret =${counts}");
Expand All @@ -1701,7 +1707,7 @@ class Store {
/// ********************************************************************************************************************************
/* The main print tree function. Calls the treeSelector() for every node and prints it( and its children), only if it returns true.
*/
List<int> printStoreTrees(int depth, DateTime newerThan, fTreeSelector treeSelector, [int maxToPrint = gMaxEventsInThreadPrinted]) {
List<int> printStoreTrees(int depth, DateTime newerThan, fTreeSelector treeSelector, [bool userRelevant = false, int maxToPrint = gMaxEventsInThreadPrinted]) {

// update this list, because it is internally used by printEvent
gFollowList = getFollows(userPublicKey);
Expand Down Expand Up @@ -1738,7 +1744,7 @@ class Store {
stdout.write("\n");
}

List<int> temp = printTopPost(topPosts[i], depth, newerThan, maxToPrint);
List<int> temp = printTopPost(topPosts[i], depth, newerThan, maxToPrint, userRelevant);
ret[0] += temp[0];
ret[1] += temp[1];
ret[2] += temp[2];
Expand Down Expand Up @@ -2151,8 +2157,13 @@ class Store {
}


// threads where the user and follows have involved themselves are returnes as true ( relevant)
// returns true if the given event should be saved in file
bool isRelevantForFileSave(Tree tree) {
if( tree.event.userRelevant == true) {
return true;
}

// threads where the user and follows have involved themselves are returnes as true ( relevant)
if( tree.treeSelectorUserPostAndLike(gFollowList.union(gDefaultFollows).union({userPublicKey}), enableNotifications: false)
|| tree.treeSelectorDMtoFromUser({userPublicKey}, enableNotifications: false)
|| tree.treeSelectorUserReplies(gFollowList)
Expand Down Expand Up @@ -2186,7 +2197,6 @@ class Store {
await file.writeAsString("", mode: FileMode.write).then( (file) => file);
}

//await file.writeAsString("", mode: FileMode.append).then( (file) => file);
int eventCounter = 0;
String nLinesStr = "";
int countPosts = 0;
Expand Down

0 comments on commit 151a00c

Please sign in to comment.