improved on logic of printing fewer events per thread

This commit is contained in:
Vishal 2022-12-26 23:47:07 +05:30
parent f8074d9d2a
commit 536c412173
4 changed files with 17 additions and 21 deletions

View File

@ -294,7 +294,7 @@ void reAdjustAlignment() {
void printProfile(Store node, String profilePubkey) {
bool onlyUserPostAndLike (Tree t) => t.treeSelectorUserPostAndLike({profilePubkey});
node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyUserPostAndLike);
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyUserPostAndLike);
// if contact list was found, get user's feed, and keep the contact list for later use
String authorName = getAuthorName(profilePubkey, 0);
@ -529,7 +529,7 @@ Future<void> otherOptionsMenuUi(Store node) async {
String clientName = $tempWords??"";
if( clientName != "") {
bool fromClient (Tree t) => t.treeSelectorClientName(clientName);
node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), fromClient); // search for last gHoursDefaultPrint hours only
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), fromClient); // search for last gHoursDefaultPrint hours only
}
break;
@ -1266,7 +1266,7 @@ Future<void> socialMenuUi(Store node) async {
switch(option) {
case 1:
node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_all);
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_all);
break;
case 2:
@ -1309,7 +1309,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.printTree(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications);
if( numPrinted[2] > 0) {
print("Showed ${numPrinted[2]} notifications.\n");
} else {
@ -1318,7 +1318,7 @@ Future<void> socialMenuUi(Store node) async {
break;
case 4:
clearScreen();
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_selfPosts);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_selfPosts);
if( numPrinted[2] > 0) {
print("Showed ${numPrinted[2]} posts made by you in last $gHoursDefaultPrint hours.\n");
} else {
@ -1328,7 +1328,7 @@ Future<void> socialMenuUi(Store node) async {
case 5:
clearScreen();
bool selectorTrees_userActions (Tree t) => t.treeSelectorUserPostAndLike({userPublicKey});
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userActions);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userActions);
if( numPrinted[0] > 0) {
print("Showed ${numPrinted[0]} thread where you replied or liked in in last $gHoursDefaultPrint hours.\n");
} else {
@ -1338,7 +1338,7 @@ Future<void> socialMenuUi(Store node) async {
case 6:
clearScreen();
bool selectorTrees_followActions (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey));
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActions);
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActions);
if( numPrinted[0] > 0) {
print("Showed ${numPrinted[0]} threads where your follows participated.\n");
} else {
@ -1352,7 +1352,7 @@ Future<void> socialMenuUi(Store node) async {
String words = $tempWords??"";
if( words != "") {
bool onlyWords (Tree t) => t.treeSelectorHasWords(words.toLowerCase());
List<int> numPrinted = node.printTree(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, 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");
}
@ -1507,7 +1507,7 @@ void showAllNotifications(Store node, [int x = 0, int y = 0]) {
List<int> numPrinted = [x, 0, y];
bool hasNotifications (Tree t) => t.treeSelectorNotifications();
List<int> temp = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), hasNotifications);
List<int> temp = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), hasNotifications);
numPrinted[0] = temp[0];
numPrinted[1] = temp[1];
numPrinted[2] = temp[2];
@ -1557,7 +1557,7 @@ Future<void> mainMenuUi(Store node) async {
switch(option) {
case 1:
node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_all);
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_all);
break;
case 2:

View File

@ -196,7 +196,7 @@ const int gMinLud06AddressLength = 10; // used in printProfile
const int gMaxEventsInThreadPrinted = 20;
const int gMaxInteger = 100000000000; // used in printTree
String gWarning_TOO_MANY_TREES = "Note: This thread has more replies than are being printed. Search for top post by id to see full thread.";
String gWarning_TOO_MANY_TREES = "Note: This thread has more replies than those printed. Search for top post by id to see it fully.";
// https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors
// Color related settings

View File

@ -422,8 +422,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 = gMaxInteger]) {
//Point numPrinted = Point(0,0);
List<int> printTree(int depth, DateTime newerThan, bool topPost, [int countPrinted = 0, int maxToPrint = gMaxEventsInThreadPrinted]) {
List<int> ret = [0,0,0];
if(event.eventData.isNotification) {
@ -435,13 +434,13 @@ class Tree {
ret[1] = 1;
if( countPrinted > maxToPrint) {
//print("$countPrinted > $maxToPrint");
print("");
printDepth(0);
print(gWarning_TOO_MANY_TREES);
return ret;
}
// sort children by time
if( children.length > 1) {
children.sort(sortTreeByItsTime);
@ -451,9 +450,6 @@ class Tree {
for( int i = 0; i < children.length; i++) {
if( countPrinted > maxToPrint) {
//print("");
//printDepth(depth+1);
//print(gWarning_TOO_MANY_TREES);
break;
}
@ -470,9 +466,9 @@ class Tree {
List<int> temp = children[i].printTree(depth+1, newerThan, false, countPrinted, maxToPrint);
ret[1] += temp[1];
ret[2] += temp[2];
countPrinted += ret[1];
countPrinted += temp[1];
}
// https://gist.github.com/dsample/79a97f38bf956f37a0f99ace9df367b9
if( leftShifted) {
stdout.write("\n");
@ -1606,7 +1602,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> printTree(int depth, DateTime newerThan, fTreeSelector treeSelector, [int maxToPrint = gMaxEventsInThreadPrinted]) {
List<int> printStoreTrees(int depth, DateTime newerThan, fTreeSelector treeSelector, [int maxToPrint = gMaxEventsInThreadPrinted]) {
topPosts.sort(sortTreeNewestReply); // sorting done only for top most threads. Lower threads aren't sorted so save cpu etc TODO improve top sorting

View File

@ -32,7 +32,7 @@ void main() {
tree.children.add(treeChild);
store.printTree(0, DateTime.now().subtract(Duration(days:1)), selectorTrees_all);
store.printStoreTrees(0, DateTime.now().subtract(Duration(days:1)), selectorTrees_all);
});