added --translate flag, so translation is only done when its enabled. called expand/translate for new events too

This commit is contained in:
vishalxl 2022-08-23 16:47:24 +05:30
parent 6d97b4e29f
commit 3f80520c0c
3 changed files with 23 additions and 8 deletions

View File

@ -18,6 +18,7 @@ const String alignArg = "align"; // can be "left"
const String widthArg = "width";
const String maxDepthArg = "maxdepth";
const String eventFileArg = "file";
const String translateArg = "translate";
void printUsage() {
String usage = """$exename version $version
@ -37,6 +38,8 @@ usage: $exename [OPTIONS]
from a relay. If not provided, then events for default or given user are shown. Same as -q
--file <filename> Read from given file, if it is present, and at the end of the program execution, write
to it all the events (including the ones read, and any new received). Same as -f
--translate This flag, if present, will make the application translate some of the recent posts using
google translate. Save as -t
UI Options
--align <left> When "left" is given as option to this argument, then the text is aligned to left. By default
the posts or text is aligned to the center of the terminal. Same as -a
@ -57,7 +60,7 @@ Future<void> main(List<String> arguments) async {
..addOption(lastdaysArg, abbr:"d") ..addOption(relayArg, abbr:"r")
..addFlag(helpArg, abbr:"h", defaultsTo: false)..addOption(alignArg, abbr:"a")
..addOption(widthArg, abbr:"w")..addOption(maxDepthArg, abbr:"m")
..addOption(eventFileArg, abbr:"f");
..addOption(eventFileArg, abbr:"f")..addFlag(translateArg, abbr: "t", defaultsTo: false);
try {
ArgResults argResults = parser.parse(arguments);
@ -66,6 +69,11 @@ Future<void> main(List<String> arguments) async {
return;
}
if( argResults[translateArg]) {
gTranslate = true;
print("Going to translate comments in last $gNumTranslateDays days using Google translate service");
}
if( argResults[pubkeyArg] != null) {
userPublicKey = argResults[pubkeyArg];
userPrivateKey = "";

View File

@ -34,6 +34,10 @@ const String notificationColor = "\x1b[36m"; // cyan
const String warningColor = "\x1B[31m"; // red
const String colorEndMarker = "\x1B[0m";
// translate flag
const int gNumTranslateDays = 4;
bool gTranslate = false;
//String defaultServerUrl = 'wss://relay.damus.io';
String defaultServerUrl = 'wss://nostr-relay.untethr.me';
@ -298,7 +302,7 @@ class EventData {
if( evaluatedContent == "") {
evaluatedContent = expandMentions(content);
if( !evaluatedContent.isLatinAlphabet()) {
if( gTranslate && !evaluatedContent.isLatinAlphabet()) {
if( gDebug > 0) print("found that this comment is non-English: $evaluatedContent");
//final input = "Здравствуйте. Ты в порядке?";
@ -550,4 +554,4 @@ Set<String> getPublicKeyFromName(String userName) {
});
return pubkeys;
}
}

View File

@ -120,6 +120,11 @@ class Tree {
if( !typesInEventMap.contains(newEvent.eventData.kind) ) {
return;
}
// expand mentions ( and translate if flag is set)
newEvent.eventData.translateAndExpandMentions();
if( gDebug > 0) print("In insertEvents: adding event to main children map");
allChildEventsMap[newEvent.eventData.id] = Tree(newEvent, [], {}, [], false);
newEventsId.add(newEvent.eventData.id);
});
@ -230,14 +235,10 @@ 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: ";
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++;
}
@ -248,7 +249,9 @@ class Tree {
}
}
if(gDebug > 0) print("Info: In printNotifications: newEventsId len = $newEventsId count17 = $count17");
// TODO don't print notifications for events that are too old
if(gDebug > 0) print("Info: In printNotifications: newEventsId = $newEventsId count17 = $count17");
if( count17 == 0) {
strToWrite += "No new replies/posts.\n";