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