mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-04-25 16:00:43 +02:00
fix for getParent function
which should return the last e tag, which is a type 1 event for social network. wasn't doing the check for kind 1, previously which has been fixed now, precipitated by event c185bb5473912f2ad74d7d0d25464af0ddeaab0261af32d4de66709b99928ac0 which refers to a kind 42 event at end, which was being taken as parent id.
This commit is contained in:
parent
a3d27ada84
commit
ea250f8b72
@ -252,7 +252,7 @@ Future<void> main(List<String> arguments) async {
|
||||
// then display them all
|
||||
|
||||
gDefaultFollows.add(userPublicKey);
|
||||
getUserEvents(gListRelayUrls1, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor));
|
||||
//getUserEvents(gListRelayUrls1, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor));
|
||||
getMultiUserEvents(gListRelayUrls1, gDefaultFollows, 1000, getSecondsDaysAgo(gDaysToGetEventsFor));
|
||||
getMentionEvents(gListRelayUrls2, userPublicKey, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor)); // from relay group 2
|
||||
getKindEvents([0, 3, 40, 42], gListRelayUrls1, gLimitPerSubscription, getSecondsDaysAgo(gDaysToGetEventsFor* 10));
|
||||
|
@ -65,9 +65,17 @@ class EventData {
|
||||
bool isHidden; // hidden by sending a reaction kind 7 event to this event, by the logged in user
|
||||
bool isDeleted; // deleted by kind 5 event
|
||||
|
||||
String getParent() {
|
||||
String getParent(Map<String, Tree> allEventsMap) {
|
||||
if( eTags.isNotEmpty) {
|
||||
return eTags[eTags.length - 1];
|
||||
for( int i = eTags.length - 1; i >= 0; i--) {
|
||||
String eventId = eTags[i];
|
||||
if( allEventsMap[eventId]?.event.eventData.kind == 1) {
|
||||
String? parentId = allEventsMap[eventId]?.event.eventData.id;
|
||||
if( parentId != null) {
|
||||
return parentId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@ -496,7 +504,7 @@ class EventData {
|
||||
return reactorNames;
|
||||
}
|
||||
|
||||
// returns the last e tag as reply to event
|
||||
// returns the last e tag as reply to event for kind 42 events
|
||||
Event? getReplyToEvent() {
|
||||
for(int i = tags.length - 1; i >= 0; i--) {
|
||||
List tag = tags[i];
|
||||
|
@ -6,7 +6,7 @@ import 'package:logging/logging.dart';
|
||||
final log = Logger('ExampleLogger');
|
||||
|
||||
// for debugging
|
||||
String gCheckEventId = "";
|
||||
String gCheckEventId = "zzzz";
|
||||
|
||||
const int gDefaultNumWaitSeconds = 2000; // is used in main()
|
||||
|
||||
|
@ -668,20 +668,36 @@ class Store {
|
||||
return;
|
||||
}
|
||||
|
||||
if( tree.event.eventData.id == gCheckEventId) {
|
||||
print("In fromEvent: got evnet id $gCheckEventId");
|
||||
}
|
||||
|
||||
if(tree.event.eventData.eTags.isNotEmpty ) {
|
||||
// is not a parent, find its parent and then add this element to that parent Tree
|
||||
String parentId = tree.event.eventData.getParent();
|
||||
String parentId = tree.event.eventData.getParent(tempChildEventsMap);
|
||||
|
||||
if( tree.event.eventData.id == gCheckEventId) {
|
||||
if(gDebug >= 0) print("In Tree FromEvents: got id: $gCheckEventId");
|
||||
if(gDebug >= 0) print("In Tree FromEvents: e tag not empty. its parent id = $parentId for id: $gCheckEventId");
|
||||
}
|
||||
|
||||
if(tempChildEventsMap.containsKey( parentId)) {
|
||||
if( tree.event.eventData.id == gCheckEventId) {
|
||||
if(gDebug >= 0) print("In Tree FromEvents: found its parent $parentId : for id: $gCheckEventId");
|
||||
}
|
||||
|
||||
if( tempChildEventsMap[parentId]?.event.eventData.kind != 1) { // since parent can only be a kind 1 event
|
||||
if( gDebug > 1) log.info("In Tree.fromEvents: Not adding: got a kind 1 event whose parent is not a type 1 post: $newEventId . parent kind: ${tempChildEventsMap[parentId]?.event.eventData.kind}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
tempChildEventsMap[parentId]?.children.add(tree);
|
||||
} else {
|
||||
|
||||
if( tree.event.eventData.id == gCheckEventId) {
|
||||
if(gDebug >= 0) print("In Tree FromEvents: parent not found : for id: $gCheckEventId");
|
||||
}
|
||||
|
||||
// in case where the parent of the new event is not in the pool of all events,
|
||||
// then we create a dummy event and put it at top ( or make this a top event?) TODO handle so that this can be replied to, and is fetched
|
||||
Event dummy = Event("","", EventData(parentId,gDummyAccountPubkey, tree.event.eventData.createdAt, 1, "Event not loaded", [], [], [], [[]], {}), [""], "[json]");
|
||||
@ -815,7 +831,7 @@ class Store {
|
||||
topPosts.add(newTree);
|
||||
} else {
|
||||
// if it has a parent , then add the newTree as the parent's child
|
||||
String parentId = newTree.event.eventData.getParent();
|
||||
String parentId = newTree.event.eventData.getParent(allChildEventsMap);
|
||||
if( allChildEventsMap.containsKey(parentId)) {
|
||||
allChildEventsMap[parentId]?.children.add(newTree);
|
||||
} else {
|
||||
@ -1388,7 +1404,7 @@ class Store {
|
||||
// for any tree node, returns its top most parent
|
||||
Tree getTopTree(Tree tree) {
|
||||
while( true) {
|
||||
Tree? parent = allChildEventsMap[ tree.event.eventData.getParent()];
|
||||
Tree? parent = allChildEventsMap[ tree.event.eventData.getParent(allChildEventsMap)];
|
||||
if( parent != null) {
|
||||
tree = parent;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user