diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 6e23869..23306b3 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -5,6 +5,7 @@ import 'package:nostr_console/tree_ds.dart'; import 'package:nostr_console/relays.dart'; import 'package:nostr_console/settings.dart'; import 'package:bip340/bip340.dart'; +import 'package:qr/qr.dart'; Future processAnyIncomingEvents(Store node, [bool printNotifications = true]) async { reAdjustAlignment(); @@ -275,6 +276,32 @@ void reAdjustAlignment() { Store.reCalculateMarkerStr(); } +String getQrCodeAsString(String str) { + String output = ""; + + final qrCode = QrCode(4, QrErrorCorrectLevel.L) + ..addData('$str'); + final qrImage = QrImage(qrCode); + + //print("qrimage modulecount = ${qrImage.moduleCount}"); + String leftPadding = " "; + for (var x = 0; x < qrImage.moduleCount; x++) { + output += leftPadding; + for (var y = 0; y < qrImage.moduleCount; y++) { + if (qrImage.isDark(y, x)) { + // render a dark square on the canvas + output += "██"; + } + else { + output += " "; + } + } + output += "\n"; + } + + return output; +} + void printProfile(Store node, String profilePubkey) { bool onlyUserPostAndLike (Tree t) => t.treeSelectorUserPostAndLike(profilePubkey); node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), onlyUserPostAndLike); @@ -307,6 +334,13 @@ void printProfile(Store node, String profilePubkey) { print("Nip 05 : ${verified?"yes. ${nip05Id}":"no"}"); print("\nLast Updated: ${getPrintableDate(dateLastUpdated)}\n"); + // print QR code + print("The QR code for the public key:\n\n"); + try { + print(getQrCodeAsString(profilePubkey)); + } catch(e) { + print("Could not generate qr code.\n"); + } if( profilePubkey != userPublicKey) { if( profileContactEvent.eventData.contactList.any((x) => (x.id == userPublicKey))) { diff --git a/lib/event_ds.dart b/lib/event_ds.dart index cac223d..361a7d6 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -160,6 +160,7 @@ class EventData { int numRoot = 0, numReply = 0; + // first go over all tags and find out at least one reply and root tag, and count their numbers String rootId = "", replyId = ""; for( int i = 0; i < eTags.length; i++) { String eventId = eTags[i][0]; @@ -176,6 +177,7 @@ class EventData { } } + // then depending on the numbers and values ( of root and replyto) return the parent if( replyId.length > 0) { if( numReply == 1) { return replyId; @@ -197,7 +199,7 @@ class EventData { } - // if reply/root tags don't work, then try to look for parent tag with the deprecated logic from NIP-10 + // but if reply/root tags don't work, then try to look for parent tag with the deprecated logic from NIP-10 if( gDebug > 0) log.info("using deprecated logic of nip10 for event id : $id"); for( int i = tags.length - 1; i >= 0; i--) { if( tags[i][0] == "e") { @@ -1498,8 +1500,8 @@ extension StringX on String { bool isRomanceLanguage() { // https://www.thoughtco.com/most-common-french-words-1372759 - Set frenchWords = {"oui", "je", "le", "un", "de", "et", "merci", "une", "ce", "pas"}; - Set spanishWords = {"y", "se", "el", "uso", "que", "te", "los", "va", "ser", "si", "por", "lo", "es", "era", "un", "o"};; + Set frenchWords = {"oui", "je", "le", "un", "de", "merci", "une", "ce", "pas"}; // "et" is in 'et al' + Set spanishWords = {"y", "se", "el", "uso", "que", "te", "los", "va", "ser", "si", "por", "lo", "es", "era", "un", "o"}; Set romanceWords = frenchWords.union(spanishWords); for( String word in romanceWords) {