mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-04-28 03:46:29 +02:00
escaped " so it can be written in comment
This commit is contained in:
parent
0da2278ea3
commit
ba1edf7dbf
@ -36,6 +36,10 @@ int showMenu(List<String> menuOptions, String menuName) {
|
||||
}
|
||||
}
|
||||
|
||||
String addEscapeChars(String str) {
|
||||
return str.replaceAll("\"", "\\\"");
|
||||
}
|
||||
|
||||
String getShaId(String pubkey, int createdAt, String kind, String strTags, String content) {
|
||||
String buf = '[0,"$pubkey",$createdAt,$kind,[$strTags],"$content"]';
|
||||
if( gDebug > 0) print("In getShaId: for buf = $buf");
|
||||
@ -90,10 +94,9 @@ Future<void> otherMenuUi(Tree node, var contactList) async {
|
||||
}
|
||||
|
||||
Future<void> mainMenuUi(Tree node, var contactList) async {
|
||||
gDebug = 0;
|
||||
// at the very beginning, show the tree as it is the, and them show the options menu
|
||||
gDebug = 1;
|
||||
// at the very beginning, show the tree as it is, and them show the options menu
|
||||
node.printTree(0, true, DateTime.now().subtract(Duration(days:gNumLastDays)));
|
||||
//gDebug = 1;
|
||||
bool userContinue = true;
|
||||
while(userContinue) {
|
||||
// align the text again in case the window size has been changed
|
||||
@ -145,7 +148,8 @@ Future<void> mainMenuUi(Tree node, var contactList) async {
|
||||
if( content == "") {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
content = addEscapeChars(content);
|
||||
stdout.write("\nType id of event to reply to (leave blank to make a new post; type x to cancel): ");
|
||||
String? $replyToVar = stdin.readLineSync();
|
||||
String replyToId = $replyToVar??"";
|
||||
|
@ -248,7 +248,7 @@ class EventData {
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
// prints event data in the format that allows it to be shown in tree form by the Tree class
|
||||
void printEventData(int depth) {
|
||||
int n = 3;
|
||||
String maxN(String v) => v.length > n? v.substring(0,n) : v.substring(0, v.length);
|
||||
@ -284,6 +284,8 @@ class EventData {
|
||||
}
|
||||
}
|
||||
|
||||
// looks up global map of reactions, if this event has any reactions, and then prints the reactions
|
||||
// in appropriate color( in case one is a notification, which is stored in member variable)
|
||||
void printReaction(int depth) {
|
||||
if( gReactions.containsKey(id)) {
|
||||
String reactorNames = "|Likes : ";
|
||||
@ -324,6 +326,7 @@ class EventData {
|
||||
}
|
||||
}
|
||||
|
||||
// This is mostly a placeholder for EventData. TODO combine both?
|
||||
class Event {
|
||||
String event;
|
||||
String id;
|
||||
@ -398,16 +401,6 @@ String getAuthorName(String pubkey) {
|
||||
return name;
|
||||
}
|
||||
|
||||
void printUserInfo(List<Event> events, String pub) {
|
||||
int numUserEvents = 0;
|
||||
for(int i = 0; i < events.length; i++) {
|
||||
if( events[i].eventData.pubkey == pub && events[i].eventData.kind == 1) {
|
||||
numUserEvents++;
|
||||
}
|
||||
}
|
||||
print("Number of user events for user ${getAuthorName(pub)} : $numUserEvents");
|
||||
}
|
||||
|
||||
List<Event> readEventsFromFile(String filename) {
|
||||
List<Event> events = [];
|
||||
final File file = File(filename);
|
||||
|
@ -8,7 +8,7 @@ import 'package:web_socket_channel/io.dart';
|
||||
*/
|
||||
class Relays {
|
||||
Map<String, IOWebSocketChannel > relays;
|
||||
List<String> users; // is used so that duplicate requests aren't sent for same user
|
||||
List<String> users; // is used so that duplicate requests aren't sent for same user
|
||||
List<Event> rEvents = []; // current events received. can be used by others. Is flushed between consumption
|
||||
Set<String> uniqueIdsRecieved = {} ; // id of events received. only for internal usage, so that duplicate events are rejected
|
||||
Relays(this.relays, this.users, this.rEvents, this.uniqueIdsRecieved);
|
||||
|
@ -384,8 +384,8 @@ class Tree {
|
||||
children.add(node);
|
||||
}
|
||||
|
||||
// for any tree node, returns its top most parent
|
||||
Tree getTopTree(Tree t) {
|
||||
|
||||
while( true) {
|
||||
Tree? parent = allChildEventsMap[ t.e.eventData.getParent()];
|
||||
if( parent != null) {
|
||||
@ -397,33 +397,33 @@ class Tree {
|
||||
return t;
|
||||
}
|
||||
|
||||
Tree getMostRecent(int mostRecentTime) {
|
||||
if( children.isEmpty) {
|
||||
return this;
|
||||
}
|
||||
// returns the time of the most recent comment
|
||||
Tree getMostRecent(int mostRecentTime) {
|
||||
if( children.isEmpty) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if( e.eventData.createdAt > mostRecentTime) {
|
||||
mostRecentTime = e.eventData.createdAt;
|
||||
}
|
||||
if( e.eventData.createdAt > mostRecentTime) {
|
||||
mostRecentTime = e.eventData.createdAt;
|
||||
}
|
||||
|
||||
int mostRecentIndex = -1;
|
||||
for( int i = 0; i < children.length; i++) {
|
||||
int mostRecentChild = children[i].getMostRecent(mostRecentTime).e.eventData.createdAt;
|
||||
if( mostRecentTime <= mostRecentChild) {
|
||||
mostRecentTime = mostRecentChild;
|
||||
mostRecentIndex = i;
|
||||
int mostRecentIndex = -1;
|
||||
for( int i = 0; i < children.length; i++) {
|
||||
int mostRecentChild = children[i].getMostRecent(mostRecentTime).e.eventData.createdAt;
|
||||
if( mostRecentTime <= mostRecentChild) {
|
||||
mostRecentTime = mostRecentChild;
|
||||
mostRecentIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if( mostRecentIndex == -1) {
|
||||
// typically this should not happen. children can't be newer than parents
|
||||
return this;
|
||||
} else {
|
||||
return children[mostRecentIndex];
|
||||
}
|
||||
}
|
||||
|
||||
if( mostRecentIndex == -1) {
|
||||
// typically this should not happen. children can't be newer than parents
|
||||
return this;
|
||||
} else {
|
||||
return children[mostRecentIndex];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // end Tree
|
||||
|
||||
int ascendingTimeTree(Tree a, Tree b) {
|
||||
if(a.e.eventData.createdAt < b.e.eventData.createdAt) {
|
||||
@ -436,7 +436,7 @@ int ascendingTimeTree(Tree a, Tree b) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// sorter function that looks at the latest event in the whole tree including the/its children
|
||||
int sortTreeNewestReply(Tree a, Tree b) {
|
||||
int aMostRecent = a.getMostRecent(0).e.eventData.createdAt;
|
||||
int bMostRecent = b.getMostRecent(0).e.eventData.createdAt;
|
||||
@ -451,9 +451,9 @@ int sortTreeNewestReply(Tree a, Tree b) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// for the given reaction event of kind 7, will update the global gReactions appropriately, returns
|
||||
// the reactedTo event's id, blank if invalid reaction etc
|
||||
String processReaction(Event event) {
|
||||
|
||||
if( event.eventData.kind == 7 && event.eventData.eTagsRest.isNotEmpty) {
|
||||
if(gDebug > 1) ("Got event of type 7");
|
||||
String reactorId = event.eventData.pubkey;
|
||||
@ -474,8 +474,8 @@ String processReaction(Event event) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// will go over the list of events, and update the global gReactions appropriately
|
||||
void processReactions(List<Event> events) {
|
||||
|
||||
for (Event event in events) {
|
||||
processReaction(event);
|
||||
}
|
||||
@ -497,10 +497,6 @@ Tree getTree(List<Event> events) {
|
||||
// process NIP 25, or event reactions by adding them to a global map
|
||||
processReactions(events);
|
||||
|
||||
for(var reactedTo in gReactions.keys) {
|
||||
//print("Got a reaction for $reactedTo. Total number of reactions = ${gReactions[reactedTo]?.length}");
|
||||
}
|
||||
|
||||
// remove all events other than kind 0, 1, 3 and 7
|
||||
events.removeWhere( (item) => !Tree.typesInEventMap.contains(item.eventData.kind));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user