mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-06-11 01:10:54 +02:00
no functional change. formatting
This commit is contained in:
parent
42111a7569
commit
32192ddf94
@ -17,7 +17,7 @@ const String testPublicKey = "e8caa2028a7090ffa85f1afee67451b309ba2f9dee655ec8f
|
||||
String userPrivateKey = testPrivateKey;
|
||||
String userPublicKey = testPublicKey;
|
||||
|
||||
// program arguments
|
||||
// program arguments1
|
||||
const String requestArg = "request";
|
||||
const String prikeyArg = "prikey";
|
||||
const String lastdaysArg = "days";
|
||||
@ -142,17 +142,12 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
|
||||
String sig = sign(userPrivateKey, id, "12345612345612345612345612345612");
|
||||
|
||||
String toSendMessage = '["EVENT", {"id": "$id","pubkey": "$userPublicKey","created_at": $createdAt,"kind": 1,"tags": [$strTags],"content": "$content","sig": "$sig"}]';
|
||||
//print(toSendMessage);
|
||||
relays.sendMessage(toSendMessage, defaultServerUrl);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
default:
|
||||
userContinue = false;
|
||||
//print("number of user events : $numUserEvents");
|
||||
//print("number of feed events : $numFeedEvents");
|
||||
//print("number of other events : $numOtherEvents");
|
||||
|
||||
String authorName = getAuthorName(userPublicKey);
|
||||
print("\nFinished fetching feed for user $userPublicKey ($authorName), whose contact list has ${contactList.length} profiles.\n ");
|
||||
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 {
|
||||
|
||||
final parser = ArgParser()..addOption(requestArg, abbr: 'q')
|
||||
..addOption(prikeyArg, abbr:"p")
|
||||
..addOption(lastdaysArg, abbr:"d")
|
||||
..addOption(relayArg, abbr:"r")
|
||||
..addFlag(helpArg, abbr:"h", defaultsTo: false)..allowsAnything;
|
||||
final parser = ArgParser()..addOption(requestArg, abbr: 'q') ..addOption(prikeyArg, abbr:"p")
|
||||
..addOption(lastdaysArg, abbr:"d") ..addOption(relayArg, abbr:"r")
|
||||
..addFlag(helpArg, abbr:"h", defaultsTo: false);
|
||||
|
||||
try {
|
||||
ArgResults argResults = parser.parse(arguments);
|
||||
@ -197,8 +190,6 @@ Future<void> main(List<String> arguments) async {
|
||||
sendRequest("wss://nostr-pub.wellorder.net", argResults[requestArg]);
|
||||
Future.delayed(const Duration(milliseconds: 6000), () {
|
||||
Tree node = getTree(getRecievedEvents());
|
||||
|
||||
// print all the events in tree form
|
||||
clearEvents();
|
||||
terminalMenuUi(node, []);
|
||||
});
|
||||
@ -264,8 +255,8 @@ Future<void> main(List<String> arguments) async {
|
||||
stdout.write("received $numOtherEvents other events\n");
|
||||
|
||||
Tree node = getTree(getRecievedEvents());
|
||||
// display the feed and then call Menu function
|
||||
clearEvents();
|
||||
// call the mein UI function
|
||||
terminalMenuUi(node, contactList);
|
||||
});
|
||||
});
|
||||
|
@ -8,6 +8,7 @@ const int spacesPerDepth = 8;
|
||||
const int maxDepthAllowed = 7;
|
||||
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 notificationColor = "\x1b[36m"; // cyan
|
||||
|
||||
|
@ -46,30 +46,34 @@ class Tree {
|
||||
List<String> insertEvents(List<Event> newEvents) {
|
||||
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
|
||||
// this condition also excludes any duplicate events sent as newEvents
|
||||
if( allEvents[element.eventData.id] != null) {
|
||||
if( allEvents[newEvent.eventData.id] != null) {
|
||||
return;
|
||||
}
|
||||
if( element.eventData.kind != 1) {
|
||||
return; // only kind 1 events are added to the tree
|
||||
// only kind 1 events are handled, return otherwise
|
||||
if( newEvent.eventData.kind != 1) {
|
||||
return;
|
||||
}
|
||||
allEvents[element.eventData.id] = Tree(element, [], {});
|
||||
newEventsId.add(element.eventData.id);
|
||||
allEvents[newEvent.eventData.id] = Tree(newEvent, [], {});
|
||||
newEventsId.add(newEvent.eventData.id);
|
||||
});
|
||||
|
||||
//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) {
|
||||
|
||||
Tree? t = allEvents[newId];
|
||||
if( t != null) {
|
||||
if( t.e.eventData.eTagsRest.isEmpty) {
|
||||
// is a parent event
|
||||
children.add(t);
|
||||
Tree? newTree = allEvents[newId]; // this should return true because we just inserted this event in the allEvents in block above
|
||||
// in case the event is already present in the current collection of events (main Tree)
|
||||
if( newTree != null) {
|
||||
if( newTree.e.eventData.eTagsRest.isEmpty) {
|
||||
// if its a is a new parent event, then add it to the main top parents ( this.children)
|
||||
children.add(newTree);
|
||||
} else {
|
||||
String parentId = t.e.eventData.getParent();
|
||||
allEvents[parentId]?.addChildNode(t);
|
||||
// if it has a parent , then add the newTree as the parent's child
|
||||
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");
|
||||
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user