added 500 ms delay after kind 1 send

added ln to qr code but did not use it.
commented out re-broadcast section.
This commit is contained in:
Vishal 2022-12-22 18:42:54 +05:30
parent b883231223
commit 922377a4e4
4 changed files with 90 additions and 16 deletions

View File

@ -92,6 +92,8 @@ Future<void> sendReplyPostLike(Store node, String replyToId, String replyKind, S
}
}
await mySleep(500);
if( gDebug > 0) log.info("Ending pow numShaDone = $numShaDone id = $id");
}
@ -175,7 +177,7 @@ Future<void> sendDirectMessage(Store node, String otherPubkey, String messageToS
// sends event e; used to send kind 3 event; can send other kinds too like channel create kind 40, or kind 0
// does not honor tags mentioned in the Event, excpet if its kind 3, when it uses contact list to create tags
Future<String> sendEvent(Store node, Event e) async {
Future<String> sendEvent(Store node, Event e, [int delayAfterSend = 500]) async {
String strTags = "";
int createdAt = DateTime.now().millisecondsSinceEpoch ~/1000;
String content = addEscapeChars( e.eventData.content);
@ -210,7 +212,7 @@ Future<String> sendEvent(Store node, Event e) async {
sendRequest(gListRelayUrls1, toSendMessage);
Future<void> foo() async {
await Future.delayed(Duration(milliseconds: 500));
await Future.delayed(Duration(milliseconds: delayAfterSend));
return;
}
await foo();
@ -307,7 +309,7 @@ void printProfile(Store node, String profilePubkey) {
// print QR code
print("The QR code for public key:\n\n");
try {
print(getQrCodeAsString(profilePubkey));
print(getPubkeyAsQrString(profilePubkey));
} catch(e) {
print("Could not generate qr code. \n");
}
@ -487,9 +489,10 @@ Future<void> otherOptionsMenuUi(Store node) async {
'Search by client name', // 1
'Edit your profile', // 2
'Delete event', // 3
'Application stats', // 4
'Help and About', // 5
'E(x)it to main menu'], // 6
'Re-Broadcast contact list+', // 4
'Application stats', // 5
'Help and About', // 6
'E(x)it to main menu'], // 7
"Other Options Menu"); // menu name
switch(option) {
@ -555,10 +558,29 @@ Future<void> otherOptionsMenuUi(Store node) async {
}
break;
case 4: // application info
case 4:
print("TODO");
break;
printSet(gListRelayUrls1, "Going to broadcast your contact list ( kind 3) and About me( kind 0) to all relays. The relays are: ", ",");
stdout.write("Hold on, sending events to relays ...");
int count = 0;
Set<int> kindBroadcast = {};
node.allChildEventsMap.forEach((id, tree) {
if( tree.event.eventData.pubkey == userPublicKey && [0,3].contains(tree.event.eventData.kind)) {
sendEvent(node, tree.event, 100);
count++;
}
});
stdout.write("..done\n");
print("\nFinished re-broadcasting $count events to all the servers.");
break;
case 5: // application info
print("\n\n");
printUnderlined("Application stats");
print("\n");
//print("\n");
relays.printInfo();
print("\n");
printUnderlined("Event and User Info");
@ -567,6 +589,9 @@ Future<void> otherOptionsMenuUi(Store node) async {
print("\nEvent distribution by event kind:\n");
node.printEventInfo();
print("\nTotal number of all events: ${node.allChildEventsMap.length}");
print("\nTotal events translated for $gNumTranslateDays days: $numEventsTranslated");
print("Total number of user profiles: ${gKindONames.length}\n");
printUnderlined("Logged in user Info");
if( userPrivateKey.length == 64) {
@ -579,11 +604,11 @@ Future<void> otherOptionsMenuUi(Store node) async {
printVerifiedAccounts(node);
break;
case 5:
case 6:
print(helpAndAbout);
break;
case 6:
case 7:
continueOtherMenu = false;
break;

View File

@ -23,8 +23,9 @@ GoogleTranslator? translator; // initialized in main when argument given
const int gNumTranslateDays = 1;// translate for this number of days
bool gTranslate = false; // translate flag
int numEventsTranslated = 0;
List<String> nip08PlaceHolders = ["#[0]", "#[1]", "#[2]", "#[3]", "#[4]", "#[5]", "#[6]", "#[7]", "#[8]", "#[9]" ];
List<String> nip08PlaceHolders = ["#[0]", "#[1]", "#[2]", "#[3]", "#[4]", "#[5]", "#[6]", "#[7]", "#[8]", "#[9]", "#[10]", "#[11]", "#[12]"];
// Structure to store kind 0 event meta data, and kind 3 meta data for each user. Will have info from latest
// kind 0 event and/or kind 3 event, both with their own time stamps.
@ -383,6 +384,7 @@ class EventData {
case 1:
case 42:
evaluatedContent = expandMentions(content, tempChildEventsMap);
//evaluatedContent = expandLNInvoices(evaluatedContent);
if( translator != null && gTranslate && !evaluatedContent.isEnglish()) {
if( gDebug > 0) print("found that this comment is non-English: $evaluatedContent");
@ -391,6 +393,7 @@ class EventData {
if( gDebug > 0) print("Sending google request: translating $content");
if( translator != null) {
try {
numEventsTranslated++;
translator?.translate(content, to: 'en')
.then( (result) => { evaluatedContent = "$evaluatedContent\n\nTranslation: ${result.toString()}" , if( gDebug > 0) print("Google translate returned successfully for one call.")} )
.onError((error, stackTrace) {

View File

@ -250,16 +250,62 @@ int isInRange( int n, List<List<int>> ranges ) {
return 0;
}
String getQrCodeAsString(String str) {
List<int> getTypeAndModule(String str) {
int type = 14, module = 73;
if( str.length > 3688 /~ 8) {
type = 16;
module = 81;
}
if( str.length > 4712 /~ 8) {
type = 18;
module = 89;
}
return [type, module];
}
int gMaxStrLenForQrCode = 600; // in bytes, maximum acceptable length of string that is converted to qr code. for lnbc1 invoices
String expandLNInvoices(String content) {
String regexp1 = '(lnbc1[a-zA-Z0-9]+)';
RegExp httpRegExp = RegExp(regexp1);
for( var match in httpRegExp.allMatches(content) ) {
String lnInvoice = content.substring(match.start, match.end);
if( lnInvoice.length > gMaxStrLenForQrCode) {
continue;
}
//print(lnInvoice);
String qrStr = "";
List<int> typeAndModule = getTypeAndModule(lnInvoice);
//print(typeAndModule);
qrStr = getPubkeyAsQrString(lnInvoice, typeAndModule[0], typeAndModule[1], "");
//print(qrStr);
content = content.substring(0, match.start) + "\n\n" + qrStr + "\n\n" + content.substring(match.end);
}
return content;
}
// https://www.sproutqr.com/blog/qr-code-types
// default 4 and 33 work for pubkey
String getPubkeyAsQrString(String str, [int typeNumber = 4, moduleCount = 33, String leftPadding = " "]) {
String output = "";
final qrCode = QrCode(4, QrErrorCorrectLevel.L)
final qrCode = QrCode(typeNumber, QrErrorCorrectLevel.L)
..addData('$str');
final qrImage = QrImage(qrCode);
assert( qrImage.moduleCount == 33);
assert( qrImage.moduleCount == moduleCount);
//print("qrimage modulecount = ${qrImage.moduleCount}");
String leftPadding = " ";
var x = 0;
for (x = 0; x < qrImage.moduleCount -1 ; x += 2) {
output += leftPadding;

View File

@ -282,7 +282,7 @@ String expectedResult =
\n""";
String profilePubkey1 = "add06b88bd78c5cbb2cd990e873adfba3eaf8e0217d3208be2be770eb506d430";
expect (qrCodeResult1, getQrCodeAsString(profilePubkey1), reason: "testing qr code function");
expect (qrCodeResult1, getPubkeyAsQrString(profilePubkey1), reason: "testing qr code function");
});