mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-06-28 17:53:16 +02:00
added notification in color cyan for the event by adding a flag and using it in EventData
This commit is contained in:
parent
dd5b80e2ab
commit
ee35160fec
@ -87,7 +87,7 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
|
|||||||
|
|
||||||
// at the very beginning, show the tree as it is the, and them show the options menu
|
// at the very beginning, show the tree as it is the, and them show the options menu
|
||||||
node.printTree(0, true, DateTime.now().subtract(Duration(days:numLastDays)));
|
node.printTree(0, true, DateTime.now().subtract(Duration(days:numLastDays)));
|
||||||
|
//gDebug = 1;
|
||||||
bool userContinue = true;
|
bool userContinue = true;
|
||||||
while(userContinue) {
|
while(userContinue) {
|
||||||
// need a bit of wait to give other events to execute, so do a delay, which allows
|
// need a bit of wait to give other events to execute, so do a delay, which allows
|
||||||
@ -96,7 +96,7 @@ Future<void> terminalMenuUi(Tree node, var contactList) async {
|
|||||||
Future.delayed(const Duration(milliseconds: waitMilliSeconds), () {
|
Future.delayed(const Duration(milliseconds: waitMilliSeconds), () {
|
||||||
|
|
||||||
node.insertEvents(getRecievedEvents());
|
node.insertEvents(getRecievedEvents());
|
||||||
node.printThreads(getRecievedEvents());
|
node.printNotifications(getRecievedEvents());
|
||||||
clearEvents();
|
clearEvents();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -219,25 +219,22 @@ Future<void> main(List<String> arguments) async {
|
|||||||
Future.delayed(const Duration(milliseconds: numWaitSeconds), () {
|
Future.delayed(const Duration(milliseconds: numWaitSeconds), () {
|
||||||
// count user events
|
// count user events
|
||||||
getRecievedEvents().forEach((element) { element.eventData.kind == 1? numUserEvents++: numUserEvents;});
|
getRecievedEvents().forEach((element) { element.eventData.kind == 1? numUserEvents++: numUserEvents;});
|
||||||
stdout.write(".. received ${getRecievedEvents().length} events made by the user\n");
|
stdout.write("...received ${getRecievedEvents().length} events made by the user\n");
|
||||||
|
|
||||||
// get user's feed ( from follows by looking at kind 3 event)
|
// get the latest kind 3 event for the user, which lists his 'follows' list
|
||||||
List<String> contactList = [];
|
List<String> contactList = [];
|
||||||
int latestContactsTime = 0;
|
int latestContactsTime = 0, latestContactIndex = -1;
|
||||||
int latestContactIndex = -1;
|
|
||||||
for( int i = 0; i < getRecievedEvents().length; i++) {
|
for( int i = 0; i < getRecievedEvents().length; i++) {
|
||||||
var e = getRecievedEvents()[i];
|
var e = getRecievedEvents()[i];
|
||||||
if( e.eventData.kind == 3 && latestContactsTime < e.eventData.createdAt) {
|
if( e.eventData.kind == 3 && latestContactsTime < e.eventData.createdAt) {
|
||||||
latestContactIndex = i;
|
latestContactIndex = i;
|
||||||
latestContactsTime = e.eventData.createdAt;
|
latestContactsTime = e.eventData.createdAt;
|
||||||
//print("${DateTime.now().millisecondsSinceEpoch ~/ 1000} latestContactsTime = $latestContactsTime");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if contact list was found, get user's feed
|
||||||
if (latestContactIndex != -1) {
|
if (latestContactIndex != -1) {
|
||||||
contactList = getContactFeed(getRecievedEvents()[latestContactIndex].eventData.contactList, 300);
|
contactList = getContactFeed(getRecievedEvents()[latestContactIndex].eventData.contactList, 300);
|
||||||
//print("number of contacts = ${contactList.length}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.write('waiting for feed to come in...............');
|
stdout.write('waiting for feed to come in...............');
|
||||||
|
@ -10,6 +10,9 @@ const int keyLenPrinted = 6;
|
|||||||
const int max_depth_allowed = 7;
|
const int max_depth_allowed = 7;
|
||||||
const int leftShiftDeepThreadsBy = 3;
|
const int leftShiftDeepThreadsBy = 3;
|
||||||
|
|
||||||
|
const String commentColor = "\x1B[32m"; // green
|
||||||
|
const String notificationColor = "\x1b[36m"; // cyan
|
||||||
|
|
||||||
//String defaultServerUrl = 'wss://relay.damus.io';
|
//String defaultServerUrl = 'wss://relay.damus.io';
|
||||||
String defaultServerUrl = 'wss://nostr-relay.untethr.me';
|
String defaultServerUrl = 'wss://nostr-relay.untethr.me';
|
||||||
|
|
||||||
@ -78,6 +81,7 @@ class EventData {
|
|||||||
List<String> eTagsRest;// rest of e tags
|
List<String> eTagsRest;// rest of e tags
|
||||||
List<String> pTags;// list of p tags for kind:1
|
List<String> pTags;// list of p tags for kind:1
|
||||||
List<List<String>> tags;
|
List<List<String>> tags;
|
||||||
|
bool isNotification; // whether its to be highlighted using highlight color
|
||||||
|
|
||||||
List<Contact> contactList = []; // used for kind:3 events, which is contact list event
|
List<Contact> contactList = []; // used for kind:3 events, which is contact list event
|
||||||
|
|
||||||
@ -88,7 +92,7 @@ class EventData {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
EventData(this.id, this.pubkey, this.createdAt, this.kind, this.content, this.eTagsRest, this.pTags, this.contactList, this.tags);
|
EventData(this.id, this.pubkey, this.createdAt, this.kind, this.content, this.eTagsRest, this.pTags, this.contactList, this.tags, {this.isNotification = false});
|
||||||
|
|
||||||
factory EventData.fromJson(dynamic json) {
|
factory EventData.fromJson(dynamic json) {
|
||||||
List<Contact> contactList = [];
|
List<Contact> contactList = [];
|
||||||
@ -184,7 +188,7 @@ class EventData {
|
|||||||
void printEventData(int depth) {
|
void printEventData(int depth) {
|
||||||
int n = 3;
|
int n = 3;
|
||||||
String maxN(String v) => v.length > n? v.substring(0,n) : v.substring(0, v.length);
|
String maxN(String v) => v.length > n? v.substring(0,n) : v.substring(0, v.length);
|
||||||
void printGreen(String s) => stdout.supportsAnsiEscapes ?stdout.write("\x1B[32m$s\x1B[0m"):stdout.write(s);
|
void printGreen(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s\x1B[0m"):stdout.write(s);
|
||||||
|
|
||||||
DateTime dTime = DateTime.fromMillisecondsSinceEpoch(createdAt *1000);
|
DateTime dTime = DateTime.fromMillisecondsSinceEpoch(createdAt *1000);
|
||||||
|
|
||||||
@ -207,7 +211,12 @@ class EventData {
|
|||||||
stdout.write("|Author : $name id: ${maxN(id)} Time: $strDate\n");
|
stdout.write("|Author : $name id: ${maxN(id)} Time: $strDate\n");
|
||||||
printDepth(depth);
|
printDepth(depth);
|
||||||
stdout.write("|Message: ");
|
stdout.write("|Message: ");
|
||||||
printGreen(contentShifted);
|
if( isNotification) {
|
||||||
|
printGreen(contentShifted, notificationColor);
|
||||||
|
isNotification = false;
|
||||||
|
} else {
|
||||||
|
printGreen(contentShifted, commentColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -183,21 +183,26 @@ class Relays {
|
|||||||
Relays relays = Relays({}, [], []);
|
Relays relays = Relays({}, [], []);
|
||||||
|
|
||||||
List<String> getContactFeed(List<Contact> contacts, numEventsToGet) {
|
List<String> getContactFeed(List<Contact> contacts, numEventsToGet) {
|
||||||
|
|
||||||
|
// maps from relay url to list of users that it supplies events for
|
||||||
Map<String, List<String> > mContacts = {};
|
Map<String, List<String> > mContacts = {};
|
||||||
|
|
||||||
List<String> contactList = [];
|
List<String> contactList = [];
|
||||||
|
|
||||||
|
// creat the mapping between relay and its hosted users
|
||||||
for( int i = 0; i < contacts.length; i++) {
|
for( int i = 0; i < contacts.length; i++) {
|
||||||
if( mContacts.containsKey(contacts[i].relay) ) {
|
if( mContacts.containsKey(contacts[i].relay) ) {
|
||||||
mContacts[contacts[i].relay]?.add(contacts[i].id);
|
mContacts[contacts[i].relay]?.add(contacts[i].id);
|
||||||
} else {
|
} else {
|
||||||
mContacts[contacts[i].relay] = [contacts[i].id];
|
mContacts[contacts[i].relay] = [contacts[i].id];
|
||||||
}
|
}
|
||||||
/*if( contacts[i].id == "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245") {
|
|
||||||
print("In getContactFeed: sending request for jb55 32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245");
|
|
||||||
}*/
|
|
||||||
contactList.add(contacts[i].id);
|
contactList.add(contacts[i].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send request for the users events to the relays
|
||||||
mContacts.forEach((key, value) { relays.getMultiUserEvents(key, value, numEventsToGet);}) ;
|
mContacts.forEach((key, value) { relays.getMultiUserEvents(key, value, numEventsToGet);}) ;
|
||||||
|
|
||||||
|
// return contact list for use by caller
|
||||||
return contactList;
|
return contactList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ class Tree {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printThreads(List<Event> events) {
|
void printNotifications(List<Event> events) {
|
||||||
|
|
||||||
// remove duplicate
|
// remove duplicate
|
||||||
Set temp = {};
|
Set temp = {};
|
||||||
@ -164,6 +164,7 @@ class Tree {
|
|||||||
}
|
}
|
||||||
Tree ?t = allEvents[element.eventData.id];
|
Tree ?t = allEvents[element.eventData.id];
|
||||||
if( t != null) {
|
if( t != null) {
|
||||||
|
t.e.eventData.isNotification = true;
|
||||||
Tree topTree = getTopTree(t);
|
Tree topTree = getTopTree(t);
|
||||||
topTree.printTree(0, false, 0);
|
topTree.printTree(0, false, 0);
|
||||||
print("\n");
|
print("\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user