no functional change. formatting

This commit is contained in:
vishalxl 2022-08-18 05:42:22 +05:30
parent 42111a7569
commit 32192ddf94
3 changed files with 26 additions and 30 deletions

View File

@ -17,7 +17,7 @@ const String testPublicKey = "e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f
String userPrivateKey = testPrivateKey; String userPrivateKey = testPrivateKey;
String userPublicKey = testPublicKey; String userPublicKey = testPublicKey;
// program arguments // program arguments1
const String requestArg = "request"; const String requestArg = "request";
const String prikeyArg = "prikey"; const String prikeyArg = "prikey";
const String lastdaysArg = "days"; const String lastdaysArg = "days";
@ -142,17 +142,12 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
String sig = sign(userPrivateKey, id, "12345612345612345612345612345612"); String sig = sign(userPrivateKey, id, "12345612345612345612345612345612");
String toSendMessage = '["EVENT", {"id": "$id","pubkey": "$userPublicKey","created_at": $createdAt,"kind": 1,"tags": [$strTags],"content": "$content","sig": "$sig"}]'; String toSendMessage = '["EVENT", {"id": "$id","pubkey": "$userPublicKey","created_at": $createdAt,"kind": 1,"tags": [$strTags],"content": "$content","sig": "$sig"}]';
//print(toSendMessage);
relays.sendMessage(toSendMessage, defaultServerUrl); relays.sendMessage(toSendMessage, defaultServerUrl);
break; break;
case 3: case 3:
default: default:
userContinue = false; userContinue = false;
//print("number of user events : $numUserEvents");
//print("number of feed events : $numFeedEvents");
//print("number of other events : $numOtherEvents");
String authorName = getAuthorName(userPublicKey); String authorName = getAuthorName(userPublicKey);
print("\nFinished fetching feed for user $userPublicKey ($authorName), whose contact list has ${contactList.length} profiles.\n "); print("\nFinished fetching feed for user $userPublicKey ($authorName), whose contact list has ${contactList.length} profiles.\n ");
contactList.forEach((x) => stdout.write("${getAuthorName(x)}, ")); contactList.forEach((x) => stdout.write("${getAuthorName(x)}, "));
@ -164,11 +159,9 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
Future<void> main(List<String> arguments) async { Future<void> main(List<String> arguments) async {
final parser = ArgParser()..addOption(requestArg, abbr: 'q') final parser = ArgParser()..addOption(requestArg, abbr: 'q') ..addOption(prikeyArg, abbr:"p")
..addOption(prikeyArg, abbr:"p") ..addOption(lastdaysArg, abbr:"d") ..addOption(relayArg, abbr:"r")
..addOption(lastdaysArg, abbr:"d") ..addFlag(helpArg, abbr:"h", defaultsTo: false);
..addOption(relayArg, abbr:"r")
..addFlag(helpArg, abbr:"h", defaultsTo: false)..allowsAnything;
try { try {
ArgResults argResults = parser.parse(arguments); ArgResults argResults = parser.parse(arguments);
@ -197,8 +190,6 @@ Future<void> main(List<String> arguments) async {
sendRequest("wss://nostr-pub.wellorder.net", argResults[requestArg]); sendRequest("wss://nostr-pub.wellorder.net", argResults[requestArg]);
Future.delayed(const Duration(milliseconds: 6000), () { Future.delayed(const Duration(milliseconds: 6000), () {
Tree node = getTree(getRecievedEvents()); Tree node = getTree(getRecievedEvents());
// print all the events in tree form
clearEvents(); clearEvents();
terminalMenuUi(node, []); terminalMenuUi(node, []);
}); });
@ -264,8 +255,8 @@ Future<void> main(List<String> arguments) async {
stdout.write("received $numOtherEvents other events\n"); stdout.write("received $numOtherEvents other events\n");
Tree node = getTree(getRecievedEvents()); Tree node = getTree(getRecievedEvents());
// display the feed and then call Menu function
clearEvents(); clearEvents();
// call the mein UI function
terminalMenuUi(node, contactList); terminalMenuUi(node, contactList);
}); });
}); });

View File

@ -8,6 +8,7 @@ const int spacesPerDepth = 8;
const int maxDepthAllowed = 7; const int maxDepthAllowed = 7;
const int leftShiftThreadsBy = 3; const int leftShiftThreadsBy = 3;
// 33 yellow, 31 red, 34 blue, 35 magenta. Add 60 for bright versions.
const String commentColor = "\x1B[32m"; // green const String commentColor = "\x1B[32m"; // green
const String notificationColor = "\x1b[36m"; // cyan const String notificationColor = "\x1b[36m"; // cyan

View File

@ -45,31 +45,35 @@ class Tree {
*/ */
List<String> insertEvents(List<Event> newEvents) { List<String> insertEvents(List<Event> newEvents) {
List<String> newEventsId = []; List<String> newEventsId = [];
newEvents.forEach((element) { // add the event to the Tree
newEvents.forEach((newEvent) {
// don't process if the event is already present in the map // don't process if the event is already present in the map
// this condition also excludes any duplicate events sent as newEvents // this condition also excludes any duplicate events sent as newEvents
if( allEvents[element.eventData.id] != null) { if( allEvents[newEvent.eventData.id] != null) {
return; return;
} }
if( element.eventData.kind != 1) { // only kind 1 events are handled, return otherwise
return; // only kind 1 events are added to the tree if( newEvent.eventData.kind != 1) {
return;
} }
allEvents[element.eventData.id] = Tree(element, [], {}); allEvents[newEvent.eventData.id] = Tree(newEvent, [], {});
newEventsId.add(element.eventData.id); newEventsId.add(newEvent.eventData.id);
}); });
//print("In insertEvents num eventsId: ${newEventsId.length}"); //print("In insertEvents num eventsId: ${newEventsId.length}");
// now go over the newly inserted event, and then find its parent, or if its a top tree
newEventsId.forEach((newId) { newEventsId.forEach((newId) {
Tree? newTree = allEvents[newId]; // this should return true because we just inserted this event in the allEvents in block above
Tree? t = allEvents[newId]; // in case the event is already present in the current collection of events (main Tree)
if( t != null) { if( newTree != null) {
if( t.e.eventData.eTagsRest.isEmpty) { if( newTree.e.eventData.eTagsRest.isEmpty) {
// is a parent event // if its a is a new parent event, then add it to the main top parents ( this.children)
children.add(t); children.add(newTree);
} else { } else {
String parentId = t.e.eventData.getParent(); // if it has a parent , then add the newTree as the parent's child
allEvents[parentId]?.addChildNode(t); String parentId = newTree.e.eventData.getParent();
allEvents[parentId]?.addChildNode(newTree);
} }
} }
}); });
@ -159,7 +163,7 @@ class Tree {
stdout.write("\nHere are the threads with new replies: \n\n"); stdout.write("\nHere are the threads with new replies: \n\n");
newEventsId.forEach((eventID) { newEventsId.forEach((eventID) {
// ignore if not in Tree // ignore if not in Tree. Should ideally not happen. TODO write warning otherwise
if( allEvents[eventID] == null) { if( allEvents[eventID] == null) {
return; return;
} }