only searched comments smaller than 1000, otherwise it was taking too much time. corrected selector logic in printNotifications

This commit is contained in:
vishalxl 2022-08-23 09:04:16 +05:30
parent dc1afeabba
commit 951bb2cc65
3 changed files with 48 additions and 9 deletions

View File

@ -114,7 +114,7 @@ Future<void> otherMenuUi(Tree node, var contactList) async {
String words = $tempWords??"";
if( words != "") {
bool onlyWords (Tree t) => t.hasWords(words.toLowerCase());
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), onlyWords);
node.printTree(0, DateTime.now().subtract(Duration(days:1000)), onlyWords); // search all the trees, hence 1000 days
}
break;
@ -130,7 +130,7 @@ Future<void> otherMenuUi(Tree node, var contactList) async {
}
Future<void> mainMenuUi(Tree node, var contactList) async {
gDebug = 0;
gDebug = 1;
// at the very beginning, show the tree as it is, and them show the options menu
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), selectAll);
bool userContinue = true;

View File

@ -59,7 +59,8 @@ Map< String, List<Contact>> gContactLists = {};
// bots ignored to reduce spam
List<String> gBots = [ "3b57518d02e6acfd5eb7198530b2e351e5a52278fb2499d14b66db2b5791c512", // robosats orderbook
"887645fef0ce0c3c1218d2f5d8e6132a19304cdc57cd20281d082f38cfea0072", // bestofhn
"f4161c88558700d23af18d8a6386eb7d7fed769048e1297811dcc34e86858fb2" // bitcoin_bot
"f4161c88558700d23af18d8a6386eb7d7fed769048e1297811dcc34e86858fb2", // bitcoin_bot
"105dfb7467b6286f573cae17146c55133d0dcc8d65e5239844214412218a6c36" // zerohedge
];
//const String gDefaultEventsFilename = "events_store_nostr.txt";
@ -307,7 +308,7 @@ class EventData {
try {
translator
.translate(content, to: 'en')
.then( (result) => { evaluatedContent = "$evaluatedContent\n\nTranslation: ${result.toString()}" , if( gDebug > 0) print("In google translate then")},
.then( (result) => { evaluatedContent = "$evaluatedContent\n\nTranslation: ${result.toString()}" , if( gDebug > 0) print("Google translate returned successfully for one call.")},
onError : (error, stackTrace) => "error in google translate");
} on Exception catch(err) {
if( gDebug > 0) print("Error in trying to use google translate: $err");
@ -524,7 +525,7 @@ String getRelayOfUser(String userPubkey, String contactPubkey) {
if( gDebug > 0) print( contacts[i].toString() );
if( contacts[i].id == contactPubkey) {
relay = contacts[i].relay;
if(gDebug > 0) print("In getRelayOfUser: found relay $relay for contact $contactPubkey" );
//if(gDebug > 0) print("In getRelayOfUser: found relay $relay for contact $contactPubkey" );
return relay;
}
}

View File

@ -166,6 +166,7 @@ class Tree {
bool leftShifted = false;
for( int i = 0; i < children.length; i++) {
// continue if this children isn't going to get printed anyway
//if( gDebug > 0) print("going to call tree selector");
if( !treeSelector(children[i])) {
continue;
}
@ -200,6 +201,7 @@ class Tree {
}
numPrinted += children[i].printTree(depth+1, newerThan, treeSelector);
//if( gDebug > 0) print("at end for loop iteraion: numPrinted = $numPrinted");
}
if( leftShifted) {
@ -225,8 +227,27 @@ class Tree {
Set temp = {};
newEventsId.retainWhere((event) => temp.add(newEventsId));
(allChildEventsMap[""]?.e.eventData.id??-1) == 7 || (allChildEventsMap[""]?.e.eventData.id??-1) == 1;
String strToWrite = "Notifications: ";
if( newEventsId.isEmpty) {
int count17 = 0;
//newEventsId.forEach((element) { (allChildEventsMap[element]?.e.eventData.id??-1) == 7 || (allChildEventsMap[element]?.e.eventData.id??-1) == 1 ? count17++:count17; });
for( int i =0 ; i < newEventsId.length; i++) {
if( (allChildEventsMap[newEventsId[i]]?.e.eventData.kind??-1) == 7 || (allChildEventsMap[newEventsId[i]]?.e.eventData.kind??-1) == 1) {
count17++;
}
if( allChildEventsMap.containsKey(newEventsId[i])) {
if( gDebug > 0) print( "id = ${ (allChildEventsMap[newEventsId[i]]?.e.eventData.id??-1)}");
} else {
if( gDebug > 0) print( "could not find event id in map");
}
}
if(gDebug > 0) print("Info: In printNotifications: newEventsId len = $newEventsId count17 = $count17");
if( count17 == 0) {
strToWrite += "No new replies/posts.\n";
stdout.write("${getNumDashes(strToWrite.length - 1)}\n$strToWrite");
stdout.write("Total posts : ${count()}\n");
@ -239,7 +260,7 @@ class Tree {
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<Tree> topTrees = []; // collect all top tress to display in this list. only unique tress will be displayed
newEventsId.forEach((eventID) {
@ -268,11 +289,16 @@ class Tree {
reactedToTree.e.eventData.newLikes.add( reactorId);
Tree topTree = getTopTree(reactedToTree);
topTrees.add(topTree);
} else {
if(gDebug > 0) print("Could not find reactedTo tree");
}
}
} else {
if(gDebug > 0) print("Could not find reactedTo event");
}
break;
default:
break;
if(gDebug > 0) print("got an event thats not 1 or 7(reaction). its id = ${t.e.eventData.kind} count17 = $count17");
break;
}
}
});
@ -451,10 +477,22 @@ class Tree {
// returns true if the given words exists in it or its children
bool hasWords(String word) {
//if(gDebug > 0) print("In tree selector hasWords: this id = ${e.eventData.id} word = $word");
if( e.eventData.content.length > 1000) {
return false;
}
if( e.eventData.content.toLowerCase().contains(word)) {
return true;
}
for( int i = 0; i < children.length; i++ ) {
//if(gDebug > 0) print("this id = ${e.eventData.id} word = $word i = $i ");
// ignore too large comments
if( children[i].e.eventData.content.length > 1000) {
continue;
}
if( children[i].e.eventData.content.toLowerCase().contains(word)) {
return true;
}