From 7a3a2247c43a2135145effd1a765972c86a7599c Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:25:17 +0530 Subject: [PATCH] changed relays. saved group events too at end. changed relay variable --- bin/nostr_console.dart | 24 ++++++++++++------------ lib/console_ui.dart | 22 +++++++++++----------- lib/settings.dart | 27 ++++++++------------------- lib/tree_ds.dart | 12 +++++++++--- 4 files changed, 40 insertions(+), 45 deletions(-) diff --git a/bin/nostr_console.dart b/bin/nostr_console.dart index 29a7303..f0562bd 100644 --- a/bin/nostr_console.dart +++ b/bin/nostr_console.dart @@ -137,13 +137,13 @@ Future main(List arguments) async { // verify that there is at least one valid relay they provided, otherwise keep defaults if (parsedRelays.length > 0) { - gListRelayUrls1 = parsedRelays; - defaultServerUrl = gListRelayUrls1.first; + gListRelayUrls = parsedRelays; + defaultServerUrl = gListRelayUrls.first; } else { print("No valid relays were provided, using the default relay list"); } } - printSet( gListRelayUrls1, "Primary relays that will be used: ", ","); + printSet( gListRelayUrls, "Primary relays that will be used: ", ","); //print("From among them, default relay: $defaultServerUrl"); if( argResults[lastdaysArg] != null) { @@ -288,14 +288,14 @@ Future main(List arguments) async { if( argResults[requestArg] != "") { stdout.write('Sending request ${argResults[requestArg]} and waiting for events...'); - sendRequest(gListRelayUrls1, argResults[requestArg]); + sendRequest(gListRelayUrls, argResults[requestArg]); } else { numWaitSeconds = 0; gEventsFilename = ""; // so it wont write it back to keep it faster ( and since without internet no new event is there to be written ) } if( userPublicKey!= "") { - getIdAndMentionEvents(gListRelayUrls1, {userPublicKey}, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents), getSecondsDaysAgo(limitSelfEvents), "#p", "authors"); + getIdAndMentionEvents(gListRelayUrls, {userPublicKey}, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents), getSecondsDaysAgo(limitSelfEvents), "#p", "authors"); } Future.delayed(Duration(milliseconds: numWaitSeconds), () { @@ -325,8 +325,8 @@ Future main(List arguments) async { // get event for user if( userPublicKey!= "") { //getIdAndMentionEvents(gListRelayUrls2, {userPublicKey}, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents), getSecondsDaysAgo(limitSelfEvents), "#p", "authors"); - getUserEvents(gListRelayUrls1, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); - getMentionEvents(gListRelayUrls1, {userPublicKey}, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents), "#p"); + getUserEvents(gListRelayUrls, userPublicKey, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); + getMentionEvents(gListRelayUrls, {userPublicKey}, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents), "#p"); } @@ -350,8 +350,8 @@ Future main(List arguments) async { //printSet(userChannels, "user channels: \n", "\n"); //getIdAndMentionEvents(gListRelayUrls1, userChannels, limitPerSubscription, 0, getSecondsDaysAgo(limitOthersEvents), "#e", "ids"); - getKindEvents([40, 41], gListRelayUrls1, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); - getKindEvents([42], gListRelayUrls1, 3 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents)); + getKindEvents([40, 41], gListRelayUrls, limitPerSubscription, getSecondsDaysAgo(limitSelfEvents)); + getKindEvents([42], gListRelayUrls, 3 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents)); initialEvents.forEach((e) => processKind3Event(e)); // first process the kind 3 event ; basically populate the global structure that holds this info @@ -386,11 +386,11 @@ Future main(List arguments) async { contacts.retainWhere((element) => i++ < maxContactsFetched); // retain only first 200, whichever they may be } - getMultiUserEvents(gListRelayUrls1, contacts.union(gDefaultFollows).union(pTags).difference(usersFetched), 4 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents)); + getMultiUserEvents(gListRelayUrls, contacts.union(gDefaultFollows).union(pTags).difference(usersFetched), 4 * limitPerSubscription, getSecondsDaysAgo(limitOthersEvents)); usersFetched = usersFetched.union(gDefaultFollows).union(contacts).union(pTags); // get meta events of all users fetched - getMultiUserEvents(gListRelayUrls1, usersFetched, 10 * limitPerSubscription, getSecondsDaysAgo(limitSelfEvents*100), {0,3}); + getMultiUserEvents(gListRelayUrls, usersFetched, 10 * limitPerSubscription, getSecondsDaysAgo(limitSelfEvents*100), {0,3}); //print("fetched meta of ${usersFetched.length}"); @@ -419,7 +419,7 @@ Future main(List arguments) async { relays = Relays({}, {}, {}); // reset relay value String req = '["REQ","latest_live_all",{"limit":40000,"kinds":[0,1,3,4,5,6,7,40,41,42,104,140,141,142],"since":${getTimeSecondsAgo(gSecsLatestLive).toString()}}]'; - sendRequest(gListRelayUrls1, req); + sendRequest(gListRelayUrls, req); //getMultiUserEvents(gListRelayUrls1, usersFetched, 10 * limitPerSubscription, getSecondsDaysAgo(limitSelfEvents*100), {0,3}); // Create tree from all events that's have yet been received/accumulated diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 2a2596a..a1a27b9 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -109,7 +109,7 @@ Future sendReplyPostLike(Store node, String replyToId, String replyKind, S String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":$replyKind,"tags":[$vanityTag],"content":"$content","sig":"$sig"}]'; //print("sending $toSendMessage"); - sendRequest( gListRelayUrls1, toSendMessage); + sendRequest( gListRelayUrls, toSendMessage); await mySleep(200); } @@ -126,7 +126,7 @@ Future sendChannelMessage(Store node, Channel channel, String messageToSen String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":$replyKind,"tags":[$strTags],"content":"$messageToSend","sig":"$sig"}]'; //printInColor(toSendMessage, gCommentColor); - sendRequest( gListRelayUrls1, toSendMessage); + sendRequest( gListRelayUrls, toSendMessage); Future foo() async { await Future.delayed(Duration(milliseconds: 300)); @@ -148,7 +148,7 @@ Future sendChannelReply(Store node, Channel channel, String replyTo, Strin String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":$replyKind,"tags":[$strTags],"content":"$messageToSend","sig":"$sig"}]'; //printInColor(toSendMessage, gCommentColor); - sendRequest( gListRelayUrls1, toSendMessage); + sendRequest( gListRelayUrls, toSendMessage); Future foo() async { await Future.delayed(Duration(milliseconds: 300)); @@ -174,7 +174,7 @@ Future sendDirectMessage(Store node, String otherPubkey, String messageToS String sig = mySign(userPrivateKey, id); String eventStrToSend = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":$replyKind,"tags":[$strTags],"content":"$encryptedMessageToSend","sig":"$sig"}]'; //print("calling send for str : $eventStrToSend"); - sendRequest( gListRelayUrls1, eventStrToSend); + sendRequest( gListRelayUrls, eventStrToSend); Future foo() async { await Future.delayed(Duration(milliseconds: 300)); @@ -217,7 +217,7 @@ Future sendEvent(Store node, Event e, [int delayAfterSend = 500]) async String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":${e.eventData.kind.toString()},"tags":[$strTags],"content":"$content","sig":"$sig"}]'; //print("in send event: calling sendrequest for string \n $toSendMessage"); - sendRequest(gListRelayUrls1, toSendMessage); + sendRequest(gListRelayUrls, toSendMessage); Future foo() async { await Future.delayed(Duration(milliseconds: delayAfterSend)); @@ -237,7 +237,7 @@ Future sendEventWithTags(Store node, Event e, String tags) async { String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":${e.eventData.kind.toString()},"tags":[$strTags],"content":"$content","sig":"$sig"}]'; //print("in send event: calling sendrequest for string \n $toSendMessage"); - sendRequest(gListRelayUrls1, toSendMessage); + sendRequest(gListRelayUrls, toSendMessage); Future foo() async { await Future.delayed(Duration(milliseconds: 500)); @@ -263,7 +263,7 @@ bool sendDeleteEvent(Store node, String eventIdToDelete) { String sig = mySign(userPrivateKey, id); String toSendMessage = '["EVENT",{"id":"$id","pubkey":"$userPublicKey","created_at":$createdAt,"kind":$replyKind,"tags":[$strTags],"content":"$content","sig":"$sig"}]'; - sendRequest( gListRelayUrls1, toSendMessage); + sendRequest( gListRelayUrls, toSendMessage); print("sent event delete request with id = $id"); } else { print("${gWarningColor}The given id was not found and/or is not a valid id, or is not your event. Not deleted.$gColorEndMarker"); @@ -648,7 +648,7 @@ Future otherOptionsMenuUi(Store node) async { case 4: print("TODO"); break; - printSet(gListRelayUrls1, "Going to broadcast your contact list ( kind 3) and About me( kind 0) to all relays. The relays are: ", ","); + printSet(gListRelayUrls, "Going to broadcast your contact list ( kind 3) and About me( kind 0) to all relays. The relays are: ", ","); stdout.write("Hold on, sending events to relays ..."); int count = 0; @@ -1506,11 +1506,11 @@ Future socialMenuUi(Store node) async { print('Sending new contact event'); Contact newContact = Contact(pk, defaultServerUrl); newContactEvent.eventData.contactList.add(newContact); - getUserEvents(gListRelayUrls1, pk, gLimitPerSubscription, getSecondsDaysAgo(gLimitFollowPosts)); + getUserEvents(gListRelayUrls, pk, gLimitPerSubscription, getSecondsDaysAgo(gLimitFollowPosts)); sendEvent(node, newContactEvent); } else { print("The contact already exists in the contact list. Republishing the old contact list."); - getUserEvents(gListRelayUrls1, pk, gLimitPerSubscription, getSecondsDaysAgo(gLimitFollowPosts)); + getUserEvents(gListRelayUrls, pk, gLimitPerSubscription, getSecondsDaysAgo(gLimitFollowPosts)); sendEvent(node, contactEvent); } } else { @@ -1529,7 +1529,7 @@ Future socialMenuUi(Store node) async { EventData newEventData = EventData(newId, newPubkey, newCreatedAt, newKind, newContent, newEtags, newPtags, newContactList, newTags, newNewLikes,); Event newEvent = Event( "EVENT", newId, newEventData, [], ""); - getUserEvents(gListRelayUrls1, pk, gLimitPerSubscription, getSecondsDaysAgo(gLimitFollowPosts)); + getUserEvents(gListRelayUrls, pk, gLimitPerSubscription, getSecondsDaysAgo(gLimitFollowPosts)); sendEvent(node, newEvent); } } diff --git a/lib/settings.dart b/lib/settings.dart index dffb88a..f068f84 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -41,7 +41,7 @@ const int gDontHighlightEventsOlderThan = 4; int gDefaultNumWaitSeconds = 12000; // is used in main() const int gMaxAuthorsInOneRequest = 300; // number of author requests to send in one request -const int gMaxPtagsToGet = 100; // maximum number of p tags that are taken from the comments of feed ( the top most, most frequent) +const int gMaxPtagsToGet = 200; // maximum number of p tags that are taken from the comments of feed ( the top most, most frequent) const int gSecsLatestLive = 2 * 3600; // the lastst seconds for which to get the latest event in main int gHoursDefaultPrint = 6; // print latest given hours only @@ -49,25 +49,14 @@ int gHoursDefaultPrint = 6; // print latest given hours only // global counters of total events read or processed int numFileEvents = 0, numFilePosts = 0, numUserPosts = 0, numFeedPosts = 0, numOtherPosts = 0; -String defaultServerUrl = "wss://relay.snort.social"; -Set gListRelayUrls1 = { defaultServerUrl, - // edited on 4 march 2024 - "wss://relay.damus.io", - "wss://nostr.mom", - "wss://nostr.nodeofsven.com" - }; - -Set gListRelayUrls2 = { - "wss://offchain.pub", - "wss://nostr.zerofeerouting.com", - "wss://nostr-relay.trustbtc.org", - "wss://relay.stoner.com" - }; -Set gListRelayUrls3 = { - "wss://nostr.onsats.org", - "wss://relay.stoner.com", - "wss://nostr.openchain.fr" +// edited on 17 march 2024 +String defaultServerUrl = "wss://relay.damus.io"; +Set gListRelayUrls = { defaultServerUrl, + "wss://nostr-01.bolt.observer", + "wss://nostr.wine", + "wss://relay2.nostrchat.io", + "wss://nostr.swiss-enigma.ch" }; // well known disposable test private key diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index f3a0910..d9c1b14 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -1382,10 +1382,10 @@ class Store { if(gDebug != 0) print("In Tree FromEvents: number of events without parent in fromEvents = ${tempWithoutParent.length}"); // get dummy events and encryped channel create events - sendEventsRequest(gListRelayUrls1, eventIdsToFetch.union(usersEncryptedChannelIds)); + sendEventsRequest(gListRelayUrls, eventIdsToFetch.union(usersEncryptedChannelIds)); // get encrypted channel events, get 141/142 by their mention of channels to which user has been invited through kind 104. get 140 by its event id. - getMentionEvents(gListRelayUrls1, usersEncryptedChannelIds, gLimitFollowPosts, getSecondsDaysAgo(gDefaultNumLastDays), "#e"); // from relay group 2 + getMentionEvents(gListRelayUrls, usersEncryptedChannelIds, gLimitFollowPosts, getSecondsDaysAgo(gDefaultNumLastDays), "#e"); // from relay group 2 // create Store return Store( topLevelTrees, tempChildEventsMap, tempWithoutParent, channels, encryptedChannels, tempDirectRooms, allEncryptedGroupInviteIds); @@ -1565,7 +1565,7 @@ class Store { }); // get dummy events - sendEventsRequest(gListRelayUrls1, dummyEventIds); + sendEventsRequest(gListRelayUrls, dummyEventIds); int totalTreeSize = 0; topPosts.forEach((element) {totalTreeSize += element.count();}); @@ -2156,6 +2156,12 @@ class Store { return true; } + // save all group events for now + var kind = tree.event.eventData.kind; + if( kind == 40 || kind == 41 || kind == 42 ) { + return true; + } + return false; }