mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-11-30 07:47:31 +01:00
simplified display in sn. showed notifications in inbox at startup if present.
This commit is contained in:
@@ -9,7 +9,7 @@ import 'package:bip340/bip340.dart';
|
||||
Future<void> processNotifications(Store node) async {
|
||||
// need a bit of wait to give other events to execute, so do a delay, which allows
|
||||
// relays to recieve and handle new events
|
||||
const int waitMilliSeconds = 200;
|
||||
const int waitMilliSeconds = 250;
|
||||
Future.delayed(const Duration(milliseconds: waitMilliSeconds), () {
|
||||
|
||||
Set<String> newEventIdsSet = node.processIncomingEvent(getRecievedEvents());
|
||||
@@ -496,13 +496,13 @@ Future<void> otherMenuUi(Store node) async {
|
||||
Future<void> channelMenuUI(Store node) async {
|
||||
bool continueChatMenu = true;
|
||||
|
||||
bool justShowedAllChannels = false;
|
||||
bool justShowedChannels = false;
|
||||
while(continueChatMenu) {
|
||||
|
||||
//await processNotifications(node); // this takes 300 ms
|
||||
if( !justShowedAllChannels) {
|
||||
if( !justShowedChannels) {
|
||||
node.printAllChannelsInfo(20);
|
||||
justShowedAllChannels = false;
|
||||
justShowedChannels = true;
|
||||
}
|
||||
|
||||
int option = showMenu([ 'Show all public channels', // 1
|
||||
@@ -513,10 +513,11 @@ Future<void> channelMenuUI(Store node) async {
|
||||
switch(option) {
|
||||
case 1:
|
||||
node.printAllChannelsInfo(1000);
|
||||
justShowedAllChannels = true;
|
||||
justShowedChannels = true;
|
||||
break;
|
||||
case 2:
|
||||
|
||||
justShowedChannels = false;
|
||||
bool showChannelOption = true;
|
||||
stdout.write("\nType channel id or name, or their 1st few letters; or type 'x' to go to menu: ");
|
||||
String? $tempUserInput = stdin.readLineSync();
|
||||
|
||||
@@ -257,7 +257,7 @@ class EventData {
|
||||
}
|
||||
|
||||
// prints event data in the format that allows it to be shown in tree form by the Tree class
|
||||
void printEventData(int depth) {
|
||||
void printEventData(int depth, bool topPost) {
|
||||
if( !(kind == 1 || kind == 4 || kind == 42)) {
|
||||
return; // only print kind 1 and 42 and 4
|
||||
}
|
||||
@@ -289,18 +289,6 @@ class EventData {
|
||||
print("debug: createdAt == 0 for event $id $content");
|
||||
}
|
||||
|
||||
String contentShifted = rightShiftContent(tempEvaluatedContent==""?tempContent: tempEvaluatedContent, gSpacesPerDepth * depth + 10);
|
||||
|
||||
String strToPrint = "";
|
||||
|
||||
strToPrint += getDepthSpaces(depth);
|
||||
strToPrint += ("+-------+\n");
|
||||
strToPrint += getDepthSpaces(depth);
|
||||
strToPrint += "|Author : $name id: ${maxN(id)} Time: $strDate\n";
|
||||
strToPrint += getReactionStr(depth); // only prints if there are any likes/reactions
|
||||
strToPrint += getDepthSpaces(depth);
|
||||
strToPrint += "|Message: ";
|
||||
|
||||
String commentColor = "";
|
||||
if( isNotification) {
|
||||
commentColor = gNotificationColor;
|
||||
@@ -308,7 +296,56 @@ class EventData {
|
||||
} else {
|
||||
commentColor = gCommentColor;
|
||||
}
|
||||
strToPrint += getStrInColor(contentShifted , commentColor);
|
||||
|
||||
int extraLen = name.length + 4;
|
||||
String strToPrint = "";
|
||||
//strToPrint += getDepthSpaces(depth);
|
||||
|
||||
if(!topPost) {
|
||||
strToPrint += "\n";
|
||||
}
|
||||
strToPrint += getDepthSpaces(depth);
|
||||
strToPrint += "└ ${name}: ";
|
||||
|
||||
const int typicalxLen = "|id: 82b5 , 12:04 AM Sep 19".length + 5; // not sure where 5 comes from
|
||||
|
||||
String idDateLikes = " |id: ${maxN(id)} , $strDate ${getReactionStr(depth)}" ;
|
||||
//print("$typicalxLen ${idDateLikes.length}");
|
||||
|
||||
idDateLikes = idDateLikes.padRight(typicalxLen);
|
||||
String temp = tempEvaluatedContent==""?tempContent: tempEvaluatedContent;
|
||||
|
||||
// comment extends from gNumLeftMarginSpaces + extraLen TO +gTextWidth
|
||||
|
||||
|
||||
// if left_stuff + extraLen + comment len + idStrLike < gTextWidth
|
||||
// then pad idStrLike with gTextWidth - ( left_stuff + extraLen + comment len )
|
||||
if( (gSpacesPerDepth * depth + extraLen + temp.length + idDateLikes.length ) > gTextWidth) {
|
||||
|
||||
// number of lines taken by comment = (comment.length + (extraLen))/ ( gTextWidth) + 1
|
||||
/*int printedTextWidth = ( gTextWidth - ( gSpacesPerDepth * depth + extraLen));
|
||||
int totalCommentWidth = temp.length + idDateLikes.length + 5;
|
||||
|
||||
int nCommentLines = (totalCommentWidth )~/ printedTextWidth + 1;
|
||||
print(nCommentLines);
|
||||
|
||||
int lastLineLen = totalCommentWidth - printedTextWidth * (nCommentLines - 1);
|
||||
|
||||
int padLeftBy = (gTextWidth - (gSpacesPerDepth * depth + extraLen)) - ( lastLineLen ) ;
|
||||
print("comment len = ${temp.length} iDateLikes len = ${idDateLikes.length} dividor = ${ printedTextWidth} padLeftBy = $padLeftBy");
|
||||
idDateLikes = idDateLikes.padLeft( padLeftBy);*/
|
||||
temp = temp + "$idDateLikes";
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
idDateLikes = idDateLikes.padLeft((gTextWidth ) - (gSpacesPerDepth * depth + extraLen + temp.length));
|
||||
temp = temp + "$idDateLikes";
|
||||
}
|
||||
//temp = temp + " |$idDateLikes";
|
||||
String contentShifted = rightShiftContent( temp, gSpacesPerDepth * depth + extraLen);
|
||||
|
||||
strToPrint += getStrInColor(contentShifted + "\n", commentColor);
|
||||
stdout.write(strToPrint);
|
||||
}
|
||||
|
||||
@@ -355,15 +392,15 @@ class EventData {
|
||||
tempEvaluatedContent = tempContent = content; // content would be changed so show that
|
||||
}
|
||||
|
||||
const int nameWidthDepth = 2; // how wide name will be in depth spaces
|
||||
const int timeWidthDepth = 2;
|
||||
const int nameWidthDepth = 16~/gSpacesPerDepth; // how wide name will be in depth spaces
|
||||
const int timeWidthDepth = 16~/gSpacesPerDepth;
|
||||
int nameWidth = gSpacesPerDepth * nameWidthDepth;
|
||||
String nameToPrint = name.padLeft(nameWidth).substring(0, nameWidth);
|
||||
String dateToPrint = strDate.padLeft(gSpacesPerDepth * timeWidthDepth).substring(0, gSpacesPerDepth * timeWidthDepth);
|
||||
|
||||
strToPrint = "${getDepthSpaces(depth)} $dateToPrint $nameToPrint: ";
|
||||
// depth above + ( depth numberof spaces = 1) + (depth of time = 2) + (depth of name = 3)
|
||||
int contentDepth = depth + 1 + timeWidthDepth + nameWidthDepth;
|
||||
int contentDepth = depth + 2 + timeWidthDepth + nameWidthDepth;
|
||||
String contentShifted = rightShiftContent(tempEvaluatedContent==""?tempContent: tempEvaluatedContent, gSpacesPerDepth * contentDepth);
|
||||
strToPrint += contentShifted;
|
||||
if( isNotification) {
|
||||
@@ -384,7 +421,7 @@ class EventData {
|
||||
}
|
||||
|
||||
if( gReactions.containsKey(id)) {
|
||||
reactorNames = getDepthSpaces(depth) + "|Likes : ";
|
||||
reactorNames = "Likes: ";
|
||||
int numReactions = gReactions[id]?.length??0;
|
||||
List<List<String>> reactors = gReactions[id]??[];
|
||||
bool firstEntry = true;
|
||||
@@ -405,7 +442,7 @@ class EventData {
|
||||
}
|
||||
} // end for
|
||||
newLikes.clear();
|
||||
reactorNames += "\n";
|
||||
reactorNames += "";
|
||||
}
|
||||
|
||||
return reactorNames;
|
||||
@@ -465,8 +502,8 @@ class Event {
|
||||
}
|
||||
}
|
||||
|
||||
void printEvent(int depth) {
|
||||
eventData.printEventData(depth);
|
||||
void printEvent(int depth, bool topPost) {
|
||||
eventData.printEventData(depth, topPost);
|
||||
//print("\n$seenOnRelays");
|
||||
//stdout.write("\n$originalJson --------------------------------\n\n");
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ class Relays {
|
||||
if( rEvents.add(e) ) {
|
||||
uniqueIdsRecieved.add(id);
|
||||
String receivedSubscription = json[1];
|
||||
if( gDebug > 3) e.eventData.printEventData(0);
|
||||
if( gDebug > 3) e.eventData.printEventData(0, true);
|
||||
if( gDebug > 2) print("");
|
||||
|
||||
if( gDebug > 1) log.info("In relay listener for relay url $relay: after adding element, rEvents Size = ${rEvents.length} numReceived = ${newRelay.numReceived} for subscription $receivedSubscription");
|
||||
|
||||
@@ -17,7 +17,7 @@ bool gOverWriteFile = false; // overwrite the file, and don't ju
|
||||
|
||||
const int gDontAddToStoreBeforeDays = 60; // events older than this are not added to the Store of all events
|
||||
|
||||
const int gDaysToGetEventsFor = 30; // when getting events, this is the since field (unless a fully formed request is given in command line)
|
||||
const int gDaysToGetEventsFor = 60; // when getting events, this is the since field (unless a fully formed request is given in command line)
|
||||
const int gLimitPerSubscription = 6000;
|
||||
|
||||
// don't show notifications for events that are older than 5 days and come when program is running
|
||||
@@ -58,6 +58,7 @@ String userPublicKey = gDefaultPublicKey;
|
||||
// default follows; taken from nostr.io/stats
|
||||
List<String> gDefaultFollows = [
|
||||
"3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681", //damus
|
||||
"6b0d4c8d9dc59e110d380b0429a02891f1341a0fa2ba1b1cf83a3db4d47e3964" // dergigi
|
||||
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245", // jb55
|
||||
"3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", // fiatjaf
|
||||
"2ef93f01cd2493e04235a6b87b10d3c4a74e2a7eb7c3caf168268f6af73314b5", // unclebobmarting
|
||||
@@ -89,7 +90,7 @@ const String gDummyAccountPubkey = "Non";
|
||||
const int gMinValidTextWidth = 60; // minimum text width acceptable
|
||||
const int gDefaultTextWidth = 120; // default text width
|
||||
int gTextWidth = gDefaultTextWidth; // is changed by --width option
|
||||
const int gSpacesPerDepth = 8; // constant
|
||||
const int gSpacesPerDepth = 4; // constant
|
||||
int gNumLeftMarginSpaces = 0;// this number is modified in main
|
||||
String gAlignment = "center"; // is modified in main if --align argument is given
|
||||
const int gapBetweenTopTrees = 1;
|
||||
@@ -117,6 +118,7 @@ Map<String, String> gColorMap = { "green": greenColor,
|
||||
"red" : redColor,
|
||||
"blue" : blueColor};
|
||||
|
||||
const String brightGreenColor = "\x1B[92m"; // bright green
|
||||
// 33 yellow, 31 red, 34 blue, 35 magenta. Add 60 for bright versions.
|
||||
String gCommentColor = greenColor;
|
||||
String gNotificationColor = cyanColor; // cyan
|
||||
|
||||
@@ -248,20 +248,20 @@ class Tree {
|
||||
/***********************************************************************************************************************************/
|
||||
/* The main print tree function. Calls the reeSelector() for every node and prints it( and its children), only if it returns true.
|
||||
*/
|
||||
int printTree(int depth, DateTime newerThan) {
|
||||
int printTree(int depth, DateTime newerThan, bool topPost) {
|
||||
int numPrinted = 0;
|
||||
|
||||
//if( event.eventData.pubkey != gDummyAccountPubkey) { // don't print dummy events
|
||||
event.printEvent(depth);
|
||||
event.printEvent(depth, topPost);
|
||||
numPrinted++;
|
||||
//}
|
||||
|
||||
bool leftShifted = false;
|
||||
for( int i = 0; i < children.length; i++) {
|
||||
|
||||
stdout.write("\n");
|
||||
printDepth(depth+1);
|
||||
stdout.write("|\n");
|
||||
//stdout.write("\n");
|
||||
//printDepth(depth+1);
|
||||
//stdout.write("│");
|
||||
|
||||
// if the thread becomes too 'deep' then reset its depth, so that its
|
||||
// children will not be displayed too much on the right, but are shifted
|
||||
@@ -269,17 +269,17 @@ class Tree {
|
||||
if( depth > maxDepthAllowed) {
|
||||
depth = maxDepthAllowed - leftShiftThreadsBy;
|
||||
printDepth(depth+1);
|
||||
stdout.write("<${getNumDashes((leftShiftThreadsBy + 1) * gSpacesPerDepth - 1)}+\n");
|
||||
stdout.write("┌${getNumDashes((leftShiftThreadsBy + 1) * gSpacesPerDepth - 1)}+\n");
|
||||
leftShifted = true;
|
||||
}
|
||||
|
||||
numPrinted += children[i].printTree(depth+1, newerThan);
|
||||
numPrinted += children[i].printTree(depth+1, newerThan, false);
|
||||
}
|
||||
|
||||
if( leftShifted) {
|
||||
stdout.write("\n");
|
||||
printDepth(depth+1);
|
||||
print(">");
|
||||
print("┴");
|
||||
}
|
||||
|
||||
return numPrinted;
|
||||
@@ -666,7 +666,7 @@ class Store {
|
||||
} else {
|
||||
// in case where the parent of the new event is not in the pool of all events,
|
||||
// then we create a dummy event and put it at top ( or make this a top event?) TODO handle so that this can be replied to, and is fetched
|
||||
Event dummy = Event("","", EventData(parentId,gDummyAccountPubkey, tree.event.eventData.createdAt, 1, "Unknown parent event", [], [], [], [[]], {}), [""], "[json]");
|
||||
Event dummy = Event("","", EventData(parentId,gDummyAccountPubkey, tree.event.eventData.createdAt, 1, "Event not loaded", [], [], [], [[]], {}), [""], "[json]");
|
||||
|
||||
Tree dummyTopNode = Tree.withoutStore(dummy, []);
|
||||
dummyTopNode.children.add(tree);
|
||||
@@ -922,7 +922,7 @@ class Store {
|
||||
topNotificationTree.retainWhere((t) => ids.add(t.event.eventData.id));
|
||||
|
||||
topNotificationTree.forEach( (t) {
|
||||
t.printTree(0, DateTime(0));
|
||||
t.printTree(0, DateTime(0), true);
|
||||
print("\n");
|
||||
});
|
||||
print("\n");
|
||||
@@ -957,10 +957,10 @@ class Store {
|
||||
}
|
||||
|
||||
String topPostLine = getDepthSpaces(depth+1);
|
||||
topPostLine += ("+\n");
|
||||
topPostLine += ("┬\n");
|
||||
stdout.write(topPostLine);
|
||||
|
||||
numPrinted += topPosts[i].printTree(depth+1, newerThan);
|
||||
numPrinted += topPosts[i].printTree(depth+1, newerThan, true);
|
||||
}
|
||||
|
||||
print("\n\nTotal posts/replies printed: $numPrinted for last $gNumLastDays days");
|
||||
@@ -1068,6 +1068,17 @@ class Store {
|
||||
*/
|
||||
void printDirectRoomInfo(fDirectRoomSelector roomSelector) {
|
||||
directRooms.sort(scrollableCompareTo);
|
||||
|
||||
int numNotificationRooms = 0;
|
||||
for( int j = 0; j < directRooms.length; j++) {
|
||||
if( roomSelector(directRooms[j]))
|
||||
numNotificationRooms++;
|
||||
}
|
||||
|
||||
if( numNotificationRooms == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
print("\n\nDirect messages inbox:");
|
||||
printUnderlined(" From Num of Messages Latest Message ");
|
||||
for( int j = 0; j < directRooms.length; j++) {
|
||||
|
||||
@@ -4,7 +4,7 @@ version: 0.0.7-beta
|
||||
homepage: https://github.com/vishalxl/nostr_console
|
||||
|
||||
|
||||
# mutual follows, fixed test, used trim in name in inbox
|
||||
# simplified visual
|
||||
|
||||
environment:
|
||||
sdk: '>=2.17.3 <3.0.0'
|
||||
|
||||
Reference in New Issue
Block a user