now getting kind 0, 3 event too

added + for top event
This commit is contained in:
Vishal 2022-09-07 02:10:32 +05:30
parent 9413873f6a
commit 8dafca67cd
5 changed files with 86 additions and 34 deletions

View File

@ -269,14 +269,16 @@ Future<void> otherMenuUi(Store node) async {
// if contact list was found, get user's feed, and keep the contact list for later use
String authorName = gKindONames[pubkey.first]?.name??"";
printUnderlined("\nProfile for User");
print("\nName : $authorName ( ${pubkey.first} ).");
print("\nName : $authorName ( ${pubkey.first} ).");
if (contactEvent != null ) {
String about = gKindONames[pubkey.first]?.about??"";
String picture = gKindONames[pubkey.first]?.picture??"";
int dateLastUpdated = gKindONames[pubkey.first]?.createdAt??0;
print("About : $about");
print("Picture: $picture");
print("About : $about");
print("Picture : $picture");
print("Last Updated: ${getPrintableDate(dateLastUpdated)}");
if( contactEvent.eventData.contactList.any((x) => (x.id == userPublicKey))) {
print("\n* They follow you");

View File

@ -463,6 +463,7 @@ class Event {
void printEvent(int depth) {
eventData.printEventData(depth);
//print("\n$seenOnRelays");
//stdout.write("\n$originalJson --------------------------------\n\n");
}

View File

@ -46,18 +46,26 @@ class Relays {
return Relays(mapRelay, {}, {});
}
void getKindEvents(List<int> kind, String relayUrl, int limit, int sinceWhen) {
kind.toString();
String subscriptionId = "kind_" + kind.toString() + "_" + relayUrl.substring(6);
String request = getKindRequest(subscriptionId, kind, limit, sinceWhen);
sendRequest(relayUrl, request);
}
/*
* @connect Connect to given relay and get all events for the given publicKey and insert the
* received events in the given List<Event>
*/
void getUserEvents(String relayUrl, String publicKey, int numEventsToGet, int sinceWhen) {
void getUserEvents(String relayUrl, String publicKey, int limit, int sinceWhen) {
for(int i = 0; i < gBots.length; i++) { // ignore bots
if( publicKey == gBots[i]) {
return;
}
}
String subscriptionId = "single_user" + (relays[relayUrl]?.numRequestsSent??"").toString();
String subscriptionId = "single_user" + (relays[relayUrl]?.numRequestsSent??"").toString() + "_" + relayUrl.substring(6);
if( relays.containsKey(relayUrl)) {
List<String>? users = relays[relayUrl]?.users;
if( users != null) { // get a user only if it has not already been requested
@ -71,7 +79,7 @@ class Relays {
}
}
String request = getUserRequest(subscriptionId, publicKey, numEventsToGet, sinceWhen);
String request = getUserRequest(subscriptionId, publicKey, limit, sinceWhen);
sendRequest(relayUrl, request);
}
@ -79,7 +87,7 @@ class Relays {
* @connect Connect to given relay and get all events for multiple users/publicKey and insert the
* received events in the given List<Event>
*/
void getMultiUserEvents(String relayUrl, List<String> publicKeys, int numEventsToGet, int sinceWhen) {
void getMultiUserEvents(String relayUrl, List<String> publicKeys, int limit, int sinceWhen) {
List<String> reqKeys = [];
if( relays.containsKey(relayUrl)) {
@ -99,9 +107,9 @@ class Relays {
}
} // if relay exists and has a user list
String subscriptionId = "multiple_user" + (relays[relayUrl]?.numRequestsSent??"").toString();
String subscriptionId = "multiple_user" + (relays[relayUrl]?.numRequestsSent??"").toString() + "_" + relayUrl.substring(6);
String request = getMultiUserRequest( subscriptionId, reqKeys, numEventsToGet, sinceWhen);
String request = getMultiUserRequest( subscriptionId, reqKeys, limit, sinceWhen);
sendRequest(relayUrl, request);
}
@ -168,7 +176,7 @@ class Relays {
return;
}
},
onError: (err) { print("\n${gWarningColor}Warning: In SendRequest creating connection onError. Kindly check your internet connection or change the relay by command line --relay=<relay wss url>"); print(gColorEndMarker); },
onError: (err) { print("\n${gWarningColor}Warning: In SendRequest creating connection to $relay. Kindly check your internet connection. Or maybe only this relay is down.>"); print(gColorEndMarker); },
onDone: () { if( gDebug != 0) print('Info: In onDone'); }
);
} on WebSocketException {
@ -203,6 +211,26 @@ class Relays {
Relays relays = Relays({}, {}, {});
String getKindRequest(String subscriptionId, List<int> kind, int limit, int sinceWhen) {
String strTime = "";
if( sinceWhen != 0) {
strTime = ', "since":${sinceWhen.toString()}';
}
var strSubscription1 = '["REQ","$subscriptionId",{"kinds":[';
var strSubscription2 ='], "limit":$limit$strTime } ]';
String strKind = "";
for(int i = 0; i < kind.length; i++) {
String comma = ",";
if( i == kind.length-1) {
comma = "";
}
strKind = strKind + kind[i].toString() + comma;
}
String strRequest = strSubscription1 + strKind + strSubscription2;
//print(strRequest);
return strRequest;
}
String getUserRequest(String subscriptionId, String publicKey, int numUserEvents, int sinceWhen) {
String strTime = "";
if( sinceWhen != 0) {
@ -232,35 +260,29 @@ String getMultiUserRequest(String subscriptionId, List<String> publicKeys, int n
return strSubscription1 + s + strSubscription2;
}
List<String> getContactFeed(List<String> relayUrls, List<Contact> contacts, int numEventsToGet, int sinceWhen) {
void getContactFeed(List<String> relayUrls, List<String> contacts, int numEventsToGet, int sinceWhen) {
// maps from relay url to list of users that it supplies events for
Map<String, List<String> > mContacts = {};
List<String> contactList = [];
for( int i = 0; i < contacts.length; i += gMaxAuthorsInOneRequest) {
// creat the mapping between relay and its hosted users
for( int i = 0; i < contacts.length; i++) {
if( mContacts.containsKey(contacts[i].relay) ) {
mContacts[contacts[i].relay]?.add(contacts[i].id);
} else {
mContacts[contacts[i].relay] = [contacts[i].id];
// for last iteration change upper limit
int upperLimit = (i + gMaxAuthorsInOneRequest) > contacts.length?
(contacts.length - i): gMaxAuthorsInOneRequest;
List<String> groupContacts = [];
for( int j = 0; j < i + upperLimit; j++) {
groupContacts.add(contacts[i + j]);
}
contactList.add(contacts[i].id);
//print( "i = $i upperLimit = $upperLimit") ;
relayUrls.forEach((relayUrl) {
relays.getMultiUserEvents(relayUrl, groupContacts, numEventsToGet, sinceWhen);
});
}
// send request for the users events to the relays
mContacts.forEach((key, value) {
//relays.getMultiUserEvents(key, value, numEventsToGet, sinceWhen);
relayUrls.forEach((relayUrl) {
relays.getMultiUserEvents(relayUrl, value, numEventsToGet, sinceWhen);
});
});
// return contact list for use by caller
return contactList;
return;
}
void getUserEvents(List<String> serverUrls, String publicKey, int numUserEvents, int sinceWhen) {
@ -269,6 +291,12 @@ void getUserEvents(List<String> serverUrls, String publicKey, int numUserEvents,
});
}
getKindEvents(List<int> kind, List<String> serverUrls, int limit, int sinceWhen) {
serverUrls.forEach((serverUrl) {
relays.getKindEvents(kind, serverUrl, limit, sinceWhen);
});
}
void getMultiUserEvents(List<String> serverUrls, List<String> publicKeys, int numUserEvents, int sinceWhen) {
if( gDebug > 0) print("Sending multi user request for ${publicKeys.length} users");

View File

@ -15,8 +15,8 @@ const int gDontSaveBeforeDays = 100; // dont save events older than this m
bool gOverWriteFile = false; // overwrite the file, and don't just append. Will write all events in memory.
const int gDaysToGetEventsFor = 100; // when getting events, this is the since field (unless a fully formed request is given in command line)
const int gLimitPerSubscription = 10000;
const int gDaysToGetEventsFor = 30; // when getting events, this is the since field (unless a fully formed request is given in command line)
const int gLimitPerSubscription = 5000;
// don't show notifications for events that are older than 5 days and come when program is running
// applicable only for notifications and not for search results. Search results set a flag in EventData and don't use this variable
@ -50,6 +50,23 @@ const String gDefaultPublicKey = "e8caa2028a7090ffa85f1afee67451b309ba2f9dee655
String userPrivateKey = gDefaultPrivateKey;
String userPublicKey = gDefaultPublicKey;
// default follows; taken from nostr.io/stats
List<String> gDefaultFollows = [
"3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681", //damus
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245", // jb55
"3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", // fiatjaf
"2ef93f01cd2493e04235a6b87b10d3c4a74e2a7eb7c3caf168268f6af73314b5", // unclebobmarting
"ed1d0e1f743a7d19aa2dfb0162df73bacdbc699f67cc55bb91a98c35f7deac69", // Melvincarvalho
"35d26e4690cbe1a898af61cc3515661eb5fa763b57bd0b42e45099c8b32fd50f", // scsibug
"9ec7a778167afb1d30c4833de9322da0c08ba71a69e1911d5578d3144bb56437", // balas
"46fcbe3065eaf1ae7811465924e48923363ff3f526bd6f73d7c184b16bd8ce4d", // Giszmo
"8c0da4862130283ff9e67d889df264177a508974e2feb96de139804ea66d6168", // monlovesmango
"3235036bd0957dfb27ccda02d452d7c763be40c91a1ac082ba6983b25238388c", // vishalxl
"c5072866b41d6b88ab2ffee16ad7cb648f940867371a7808aaa94cf7d01f4188", // randymcmillan
"2183e94758481d0f124fbd93c56ccaa45e7e545ceeb8d52848f98253f497b975", // Brill
"c7eda660a6bc8270530e82b4a7712acdea2e31dc0a56f8dc955ac009efd97c86" ]; // shawn
// dummy account pubkey
const String gDummyAccountPubkey = "Non";

View File

@ -789,6 +789,10 @@ class Store {
for( int i = 0; i < gapBetweenTopTrees; i++ ) {
stdout.write("\n");
}
String topPostLine = getDepthSpaces(depth+1);
topPostLine += ("+\n");
stdout.write(topPostLine);
numPrinted += topPosts[i].printTree(depth+1, newerThan);
}