formatting changes

This commit is contained in:
vishalxl
2022-08-08 14:30:06 +05:30
parent db1ca73dd5
commit 900913743f

View File

@@ -47,10 +47,9 @@ void printDepth(int d) {
String rightShiftContent(String s, int numSpaces) { String rightShiftContent(String s, int numSpaces) {
String newString = ""; String newString = "";
int newlineCounter = 0;
int newlineCounter = 0;
String spacesString = ""; String spacesString = "";
for( int i = 0; i < numSpaces ; i++) { for( int i = 0; i < numSpaces ; i++) {
spacesString += " "; spacesString += " ";
} }
@@ -66,10 +65,8 @@ String rightShiftContent(String s, int numSpaces) {
newString += spacesString; newString += spacesString;
newlineCounter = 0; newlineCounter = 0;
} }
newString += s[i]; newString += s[i];
} }
newlineCounter++; newlineCounter++;
} }
return newString; return newString;
@@ -104,7 +101,6 @@ class EventData {
if( eTagsRest.length > 0) { if( eTagsRest.length > 0) {
return eTagsRest[eTagsRest.length - 1]; return eTagsRest[eTagsRest.length - 1];
} }
return ""; return "";
} }
@@ -117,9 +113,7 @@ class EventData {
List<String> pTagsRead = []; List<String> pTagsRead = [];
String eTagParentRead = ""; String eTagParentRead = "";
var jsonTags = json['tags']; var jsonTags = json['tags'];
//stdout.write("In fromJson: jsonTags = $jsonTags");
var numTags = jsonTags.length; var numTags = jsonTags.length;
// NIP 02: if the event is a contact list type, then populate contactList // NIP 02: if the event is a contact list type, then populate contactList
@@ -150,20 +144,14 @@ class EventData {
pTagsRead.add(tag[1]); pTagsRead.add(tag[1]);
} }
} }
// TODO add other tags // TODO add other tags
} }
} }
} }
return EventData(json['id'] as String, json['pubkey'] as String,
return EventData(json['id'] as String, json['created_at'] as int, json['kind'] as int,
json['pubkey'] as String, json['content'] as String, eTagParentRead,
json['created_at'] as int, eTagsRead, pTagsRead,
json['kind'] as int,
json['content'] as String,
eTagParentRead,
eTagsRead,
pTagsRead,
contactList); contactList);
} }
@@ -188,7 +176,6 @@ class EventData {
stdout.write("|\n"); stdout.write("|\n");
printDepth(depth); printDepth(depth);
stdout.write("|id : ${max3(id)} Time: $dTime"); stdout.write("|id : ${max3(id)} Time: $dTime");
//stdout.write("\n$eTagsRest\n");
} }
@override @override
@@ -206,16 +193,15 @@ class EventData {
} }
} }
class Event { class Event {
String event; String event;
String id; String id;
EventData eventData; EventData eventData;
String originalJson; String originalJson;
Event(this.event, this.id, this.eventData, this.seenOnRelays, this.originalJson);
List<String> seenOnRelays; List<String> seenOnRelays;
Event(this.event, this.id, this.eventData, this.seenOnRelays, this.originalJson);
factory Event.fromJson(String d, String relay) { factory Event.fromJson(String d, String relay) {
dynamic json = jsonDecode(d); dynamic json = jsonDecode(d);
if( json.length < 3) { if( json.length < 3) {
@@ -247,12 +233,10 @@ class Tree {
factory Tree.fromEvents(List<Event> events) { factory Tree.fromEvents(List<Event> events) {
stdout.write("in factory fromEvents list. number of events: ${events.length}\n"); stdout.write("in factory fromEvents list. number of events: ${events.length}\n");
List<Tree> childTrees = []; // create a map from list of events
Map<String, Tree> m = {}; Map<String, Tree> m = {};
events.forEach((element) { m[element.eventData.id] = Tree(element, []); }); events.forEach((element) { m[element.eventData.id] = Tree(element, []); });
//stdout.write(m);
List<String> processed = []; List<String> processed = [];
m.forEach((key, value) { m.forEach((key, value) {
@@ -282,6 +266,7 @@ class Tree {
}); });
// add parent trees as top level child trees of this tree // add parent trees as top level child trees of this tree
List<Tree> childTrees = [];
for( var value in m.values) { for( var value in m.values) {
if( !value.e.eventData.eTagsRest.isNotEmpty) { // if its a parent if( !value.e.eventData.eTagsRest.isNotEmpty) { // if its a parent
childTrees.add(value); childTrees.add(value);
@@ -320,7 +305,6 @@ class Tree {
} }
children[i].printTree(depth+1, false); children[i].printTree(depth+1, false);
} }
//stdout.write("\nTotal number of tree children printed: ${children.length}\n");
} }
} }