added flag userRelevant to improve event printing at end. now every event that's printed for user gets saved at end

This commit is contained in:
Vishal 2024-04-21 09:38:43 +05:30
parent f22851ed45
commit 151a00c22a
4 changed files with 27 additions and 16 deletions

View File

@ -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");
}

View File

@ -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;
@ -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 {
@ -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 {
@ -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 {
@ -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 {
@ -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");
}

View File

@ -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) {

View File

@ -411,7 +411,7 @@ 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) {
@ -419,6 +419,12 @@ class Tree {
}
countPrinted++;
// toggle flag which will save the event and program end
if( userRelevant == true) {
event.userRelevant = true;
}
event.printEvent(depth, topPost);
ret[1] = 1;
@ -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];
@ -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}");
@ -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);
@ -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];
@ -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)
@ -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;