mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-07-12 21:32:17 +02:00
added mention of relay for an event, also printed it
This commit is contained in:
@ -21,14 +21,15 @@ Future<void> main() async {
|
||||
var e = events[i];
|
||||
if( e.eventData.kind == 3) {
|
||||
print('calling getfeed');
|
||||
getFeed(e.eventData.contactList, events, 3);
|
||||
getFeed(e.eventData.contactList, events, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print('waiting for feed to come in');
|
||||
Future.delayed(const Duration(milliseconds: 4000), () {
|
||||
events.sort(ascendingTime);
|
||||
//events.sort(ascendingTime);
|
||||
events.removeWhere( (item) => item.eventData.kind != 1 );
|
||||
print('====================all events =================');
|
||||
printEvents(events);
|
||||
print('number of all events: ${events.length}');
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
int keyLenPrinted = 6;
|
||||
String defaultServerUrl = 'wss://nostr-pub.wellorder.net';
|
||||
String defaultServerUrl = 'wss://nostr.onsats.org';
|
||||
|
||||
|
||||
class Contact {
|
||||
@ -38,6 +38,9 @@ class EventData {
|
||||
String server = defaultServerUrl;
|
||||
if( n >=3 ) {
|
||||
server = tag[2].toString();
|
||||
if( server == 'wss://nostr.rocks') {
|
||||
server = 'wss://nostr.onsats.org';
|
||||
}
|
||||
}
|
||||
Contact c = Contact(tag[1] as String, server, 3.toString());
|
||||
contactList.add(c);
|
||||
@ -61,8 +64,10 @@ class EventData {
|
||||
|
||||
String max3(String v) => v.length > 3? v.substring(0,3) : v.substring(0, v.length);
|
||||
DateTime dTime = DateTime.fromMillisecondsSinceEpoch(createdAt *1000);
|
||||
|
||||
return '-------+\nid : ${max3(id)} \nAuthor : ${max3(pubkey)}\nTime : $dTime\nKind : $kind\nMessage: $content\n';
|
||||
if( createdAt == 0) {
|
||||
print("createdAt == 0 for event $content");
|
||||
}
|
||||
return '\n-------+\nAuthor : ${max3(pubkey)}\nMessage: $content\n\nid : ${max3(id)} Time: $dTime Kind: $kind';
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,25 +76,29 @@ class Event {
|
||||
String event;
|
||||
String id;
|
||||
EventData eventData;
|
||||
Event(this.event, this.id, this.eventData);
|
||||
factory Event.fromJson(dynamic json) {
|
||||
Event(this.event, this.id, this.eventData, this.seenOnRelays);
|
||||
|
||||
List<String> seenOnRelays;
|
||||
|
||||
factory Event.fromJson(dynamic json, String relay) {
|
||||
if( json.length < 3) {
|
||||
String e = "";
|
||||
e = json.length > 1? json[0]: "";
|
||||
return Event(e,"",EventData("non","","", 0, 0, []));
|
||||
return Event(e,"",EventData("non","","", 0, 0, []), [relay]);
|
||||
}
|
||||
|
||||
return Event(json[0] as String, json[1] as String, EventData.fromJson(json[2]) );
|
||||
return Event(json[0] as String, json[1] as String, EventData.fromJson(json[2]), [relay] );
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$eventData';
|
||||
return '$eventData Seen on: ${seenOnRelays[0]}\n';
|
||||
}
|
||||
}
|
||||
|
||||
int ascendingTime(Event a, Event b) {
|
||||
if(a.eventData.createdAt < b.eventData.createdAt) {
|
||||
print( 'ascendingTime : comparing two ${a.eventData.createdAt} and ${b.eventData.createdAt}');
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,10 @@ String getSubscriptionRequest(String publicKey, int numUserEvents) {
|
||||
return strSubscription1 + publicKey + strSubscription2;
|
||||
}
|
||||
|
||||
void handleSocketError() {
|
||||
|
||||
}
|
||||
|
||||
class Relays {
|
||||
Map<String, Future<WebSocket> > relays;
|
||||
|
||||
@ -24,6 +28,7 @@ class Relays {
|
||||
return Relays(r);
|
||||
}
|
||||
|
||||
|
||||
void connect(String relay, String publicKey, List<Event> events, int numUserEvents) {
|
||||
Future<WebSocket>? fws;
|
||||
if(relays.containsKey(relay)) {
|
||||
@ -41,7 +46,7 @@ class Relays {
|
||||
print(d);
|
||||
Event e;
|
||||
try {
|
||||
e = Event.fromJson(jsonDecode(d));
|
||||
e = Event.fromJson(jsonDecode(d), relay);
|
||||
events.add(e);
|
||||
if( e.eventData.kind == 3) {
|
||||
|
||||
@ -52,9 +57,10 @@ class Relays {
|
||||
},
|
||||
onError: (e) { print("error"); print(e); },
|
||||
onDone: () { print('in onDone'); ws.close() ; }
|
||||
);});
|
||||
|
||||
|
||||
);}).catchError((err) {
|
||||
print('Error: Could not connect to $relay');
|
||||
//throw Exception('Some arbitrary error');
|
||||
});
|
||||
} on WebSocketException {
|
||||
print('WebSocketException exception');
|
||||
return;
|
||||
@ -64,7 +70,7 @@ class Relays {
|
||||
}
|
||||
}
|
||||
|
||||
print('sending request ${getSubscriptionRequest(publicKey, numUserEvents)}');
|
||||
print('sending request ${getSubscriptionRequest(publicKey, numUserEvents)} to $relay');
|
||||
fws?.then((WebSocket ws) { ws.add(getSubscriptionRequest(publicKey, numUserEvents)); });
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user