mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-06-27 17:21:30 +02:00
removed unused code in Tree::fromEvents() constructor. no functional change.
This commit is contained in:
parent
9b215038b5
commit
a3221ab0e4
@ -300,48 +300,26 @@ class Tree {
|
|||||||
Tree(this.e, this.children);
|
Tree(this.e, this.children);
|
||||||
|
|
||||||
// @method create top level Tree from events.
|
// @method create top level Tree from events.
|
||||||
// first create a map. then add all top trees to the final list/ChildTrees. then add children to it.
|
// first create a map. then process each element in the map by adding it to its parent ( if its a child tree)
|
||||||
factory Tree.fromEvents(List<Event> events) {
|
factory Tree.fromEvents(List<Event> events) {
|
||||||
if( events.isEmpty) {
|
if( events.isEmpty) {
|
||||||
return Tree(Event("","",EventData("non","", 0, 0, "", "", [], [], [], [[]]), [""], "[json]"), []);
|
return Tree(Event("","",EventData("non","", 0, 0, "", "", [], [], [], [[]]), [""], "[json]"), []);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a map from list of events, key is eventId and value is event itself
|
// create a map from list of events, key is eventId and value is event itself
|
||||||
Map<String, Tree> mAllEvents = {};
|
Map<String, Tree> mAllEvents = {};
|
||||||
events.forEach((element) { mAllEvents[element.eventData.id] = Tree(element, []); });
|
events.forEach((element) { mAllEvents[element.eventData.id] = Tree(element, []); });
|
||||||
|
|
||||||
|
|
||||||
List<String> parentNotFound = [];
|
|
||||||
List<String> processed = [];
|
|
||||||
|
|
||||||
mAllEvents.forEach((key, value) {
|
mAllEvents.forEach((key, value) {
|
||||||
bool alreadyProcessed = false;
|
|
||||||
for( int i = 0; i < processed.length; i++) {
|
|
||||||
if( processed[i] == key) {
|
|
||||||
alreadyProcessed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !alreadyProcessed) {
|
if( !value.e.eventData.eTagsRest.isNotEmpty ) {
|
||||||
if( !value.e.eventData.eTagsRest.isNotEmpty ) {
|
// in case this node is a parent, then move it to processed()
|
||||||
// in case this node is a parent, then move it to processed()
|
} else {
|
||||||
processed.add(key);
|
// is not a parent, find its parent and then add this element to that parent Tree
|
||||||
} else {
|
//stdout.write("added to parent a child\n");
|
||||||
// is not a parent, find its parent and then add this element to that parent Tree
|
String id = key;
|
||||||
//stdout.write("added to parent a child\n");
|
String parentId = value.e.eventData.getParent();
|
||||||
String id = key;
|
mAllEvents[parentId]?.addChildNode(value);
|
||||||
String parentId = value.e.eventData.getParent();
|
|
||||||
mAllEvents[parentId]?.addChildNode(value);
|
|
||||||
if( mAllEvents.containsKey(parentId)) {
|
|
||||||
processed.add(key);
|
|
||||||
} else {
|
|
||||||
parentNotFound.add(key);
|
|
||||||
//print("\nevent without parent found: ");
|
|
||||||
//value.e.printEvent(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // entry already exists
|
|
||||||
// do nothing
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user