fixed tag logic for client tag; other minor changes including basic test for French

This commit is contained in:
Vishal 2022-08-27 16:26:45 +05:30
parent b7348f8e9c
commit 2796930cb2
5 changed files with 30 additions and 11 deletions

View File

@ -149,7 +149,7 @@ Future<void> main(List<String> arguments) async {
List<Event> eventsFromFile = readEventsFromFile(gEventsFilename);
setRelaysIntialEvents(eventsFromFile);
eventsFromFile.forEach((element) { element.eventData.kind == 1? numFileEvents++: numFileEvents;});
print("read $numFileEvents posts from file \"$gEventsFilename\"");
print("read $numFileEvents posts from file $gEventsFilename");
}
if( argResults[requestArg] != null) {
stdout.write('Sending request and waiting for events...');

View File

@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:convert';
import 'package:nostr_console/event_ds.dart';
import 'package:nostr_console/tree_ds.dart';
import 'package:nostr_console/relays.dart';
@ -355,7 +356,7 @@ Future<void> channelMenuUI(Tree node, var contactList) async {
}
stdout.write("\nType message to send to this room; or type 'x' to exit the channel, or just press <enter> to refresh: ");
$tempUserInput = stdin.readLineSync();
$tempUserInput = stdin.readLineSync(encoding: utf8);
String messageToSend = $tempUserInput??"";
if( messageToSend != "") {

View File

@ -79,7 +79,28 @@ bool isWhitespace(String s) {
return s[0] == ' ' || s[0] == '\n' || s[0] == '\r' || s[0] == '\t';
}
extension StringX on String {
isEnglish( ) {
bool latin = isLatinAlphabet();
if( !latin)
return false;
bool french = isFrench();
return !french;
}
bool isFrench() {
List<String> frenchWords = ["oui", "je", "le" "un", "de", "et", "la"];
for( int i = 0; i < frenchWords.length; i++) {
if( this.toLowerCase().contains(" ${frenchWords[i]} ")) {
return true;
}
}
return false;
}
isLatinAlphabet({caseSensitive = false}) {
if( length < 6) { // since smaller words can be smileys can should not be translated
return true;
@ -253,7 +274,7 @@ class EventData {
if( evaluatedContent == "") {
evaluatedContent = expandMentions(content);
if( gTranslate && !evaluatedContent.isLatinAlphabet()) {
if( gTranslate && !evaluatedContent.isEnglish()) {
if( gDebug > 0) print("found that this comment is non-English: $evaluatedContent");
//final input = "Здравствуйте. Ты в порядке?";

View File

@ -46,7 +46,7 @@ const String defaultTextColor = "green";
const String greenColor = "\x1B[32m"; // green
const String cyanColor = "\x1b[36m"; // cyan
const String whiteColor = "\x1b[37m"; // white
const String whiteColor = "\x1b[97m"; // white
const String blackColor = "\x1b[30m"; // black
const String redColor = "\x1B[31m"; // red
const String blueColor = "\x1b[34m"; // blue

View File

@ -555,13 +555,13 @@ class Tree {
* @parameter replyToId First few letters of an event id for which reply is being made
*/
String getTagStr(String replyToId, String clientName) {
String strTags = "";
clientName = (clientName == "")? "nostr_console": clientName; // in case its empty
if( replyToId.isEmpty) {
return strTags;
return '["client","$clientName"]';
}
String strTags = "";
// find the latest event with the given id; needs to be done because we allow user to refer to events with as few as 3 or so first letters
// and only the event that's latest is considered as the intended recipient ( this is not perfect, but easy UI)
int latestEventTime = 0;
@ -599,13 +599,10 @@ class Tree {
strTags += '["e","$rootEventId"],';
}
}
strTags += '["e","$latestEventId","$relay"],';
}
if( strTags != "")
strTags += '["client","$clientName"]' ;
strTags += '["client","$clientName"]' ;
return strTags;
}