printed only 20 maximum events in a thread to reduce screen spam from long threads

renamed lnurl to lud06 which is what it is
This commit is contained in:
Vishal 2022-12-26 23:19:22 +05:30
parent a64fd45409
commit f8074d9d2a
5 changed files with 106 additions and 63 deletions

View File

@ -28,10 +28,10 @@ Future<void> processAnyIncomingEvents(Store node, [bool printNotifications = tru
Set<String> newEventIds = node.processIncomingEvent(getRecievedEvents());
clearEvents();
Point numPrinted1 = Point(0, 0);
List<int> numPrinted1 = [0,0,0];
if( printNotifications) {
numPrinted1 = node.printTreeNotifications(newEventIds);
showAllNotifications(node, numPrinted1.x.toInt(), numPrinted1.y.toInt());
showAllNotifications(node, numPrinted1[0], numPrinted1[2]);
}
});
@ -309,12 +309,11 @@ void printProfile(Store node, String profilePubkey) {
String about = gKindONames[profilePubkey]?.about??"";
String picture = gKindONames[profilePubkey]?.picture??"";
String lud16 = gKindONames[profilePubkey]?.lud16??"";
String lud16 = gKindONames[profilePubkey]?.lud06??"";
int dateLastUpdated = gKindONames[profilePubkey]?.createdAt??0;
bool verified = gKindONames[profilePubkey]?.nip05Verified??false;
String nip05Id = gKindONames[profilePubkey]?.nip05Id??"";
// print QR code
print("The QR code for public key:\n\n");
try {
@ -324,7 +323,7 @@ void printProfile(Store node, String profilePubkey) {
}
// print LNRUL if it exists
if( lud16.length > gMinLud16AddressLength) {
if( lud16.length > gMinLud06AddressLength) {
try {
List<int>? typesAndModule = getTypeAndModule(lud16);
if( typesAndModule != null) {
@ -1310,18 +1309,18 @@ Future<void> socialMenuUi(Store node) async {
clearScreen();
bool selectorTrees_userNotifications (Tree t) => t.treeSelectorotificationsFor({userPublicKey});
int notificationHours = gHoursDefaultPrint>24? gHoursDefaultPrint: 24; // minimum 24
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications);
if( numPrinted.y > 0) {
print("Showed ${numPrinted.y.toInt()} notifications.\n");
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications);
if( numPrinted[2] > 0) {
print("Showed ${numPrinted[2]} notifications.\n");
} else {
print("No notifications.");
}
break;
case 4:
clearScreen();
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_selfPosts);
if( numPrinted.x > 0) {
print("Showed ${numPrinted.x.toInt()} posts made by you in last $gHoursDefaultPrint hours.\n");
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_selfPosts);
if( numPrinted[2] > 0) {
print("Showed ${numPrinted[2]} posts made by you in last $gHoursDefaultPrint hours.\n");
} else {
print("No posts made by you in last $gHoursDefaultPrint hours.");
}
@ -1329,9 +1328,9 @@ Future<void> socialMenuUi(Store node) async {
case 5:
clearScreen();
bool selectorTrees_userActions (Tree t) => t.treeSelectorUserPostAndLike({userPublicKey});
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userActions);
if( numPrinted.x > 0) {
print("Showed ${numPrinted.x.toInt()} thread where you replied or liked in in last $gHoursDefaultPrint hours.\n");
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userActions);
if( numPrinted[0] > 0) {
print("Showed ${numPrinted[0]} thread where you replied or liked in in last $gHoursDefaultPrint hours.\n");
} else {
print("No replies/likes made by you in last $gHoursDefaultPrint hours.");
}
@ -1339,9 +1338,9 @@ Future<void> socialMenuUi(Store node) async {
case 6:
clearScreen();
bool selectorTrees_followActions (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey));
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActions);
if( numPrinted.x > 0) {
print("Showed ${numPrinted.x.toInt()} threads where your follows participated.\n");
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActions);
if( numPrinted[0] > 0) {
print("Showed ${numPrinted[0]} threads where your follows participated.\n");
} else {
print("No threads to show where your follows participated in last $gHoursDefaultPrint hours.");
}
@ -1353,8 +1352,8 @@ Future<void> socialMenuUi(Store node) async {
String words = $tempWords??"";
if( words != "") {
bool onlyWords (Tree t) => t.treeSelectorHasWords(words.toLowerCase());
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyWords); // search for last default hours only
if( numPrinted.x.toInt() == 0) {
List<int> numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyWords, gMaxInteger); // search for last default hours only
if( numPrinted[0] == 0) {
print("\nNot found in the last $gHoursDefaultPrint hours. Try increasing the number of days printed, from social network options to search further back into history.\n");
}
} else printWarning("Blank word entered. Try again.");
@ -1505,11 +1504,15 @@ Future<void> socialMenuUi(Store node) async {
void showAllNotifications(Store node, [int x = 0, int y = 0]) {
//print("In showAllNotifications. x = $x y = $y");
Point numPrinted = Point(x, y);
List<int> numPrinted = [x, 0, y];
bool hasNotifications (Tree t) => t.treeSelectorNotifications();
numPrinted += node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), hasNotifications);
int numNotificationsPrinted = numPrinted.y.toInt();
List<int> temp = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), hasNotifications);
numPrinted[0] = temp[0];
numPrinted[1] = temp[1];
numPrinted[2] = temp[2];
int numNotificationsPrinted = numPrinted[2];
bool showNotifications (ScrollableMessages room) => room.selectorNotifications();
int numDirectRoomsPrinted = node.printDirectRoomsOverview( showNotifications, 100, node.allChildEventsMap);

View File

@ -31,12 +31,12 @@ List<String> nip08PlaceHolders = ["#[0]", "#[1]", "#[2]", "#[3]", "#[4]", "#[5]"
// kind 0 event and/or kind 3 event, both with their own time stamps.
class UserNameInfo {
int? createdAt;
String? name, about, picture, lud16;
String? name, about, picture, lud06;
int? createdAtKind3;
Event ?latestContactEvent;
bool nip05Verified;
String? nip05Id;
UserNameInfo(this.createdAt, this.name, this.about, this.picture, this.lud16, this.nip05Id , this.latestContactEvent, [this.createdAtKind3 = null, this.nip05Verified = false]);
UserNameInfo(this.createdAt, this.name, this.about, this.picture, this.lud06, this.nip05Id , this.latestContactEvent, [this.createdAtKind3 = null, this.nip05Verified = false]);
}
/*
@ -1064,7 +1064,7 @@ bool processKind0Event(Event e) {
String name = "";
String about = "";
String picture = "";
String lud16 = "";
String lud06 = "";
String nip05 = "";
try {
@ -1072,7 +1072,7 @@ bool processKind0Event(Event e) {
name = json["name"]??"";
about = json["about"]??"";
picture = json["picture"]??"";
lud16 = json["lud16"]??"";
lud06 = json["lud06"]??"";
nip05 = json['nip05']??"";
//String twitterId = json['twitter']??"";
//String githubId = json['github']??"";
@ -1082,12 +1082,12 @@ bool processKind0Event(Event e) {
bool newEntry = false, entryModified = false;
if( !gKindONames.containsKey(e.eventData.pubkey)) {
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud16, nip05, null);
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, nip05, null);
newEntry = true;;
} else {
int oldTime = gKindONames[e.eventData.pubkey]?.createdAt??0;
if( oldTime < e.eventData.createdAt) {
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud16, nip05, null);
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, nip05, null);
entryModified = true;
}
}
@ -1123,7 +1123,7 @@ bool processKind0Event(Event e) {
int oldTime = 0;
if( !gKindONames.containsKey(e.eventData.pubkey)) {
//printWarning("in response handing. creating user info");
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud16, null, null);
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, null, null);
} else {
oldTime = gKindONames[e.eventData.pubkey]?.createdAt??0;
//print("in response handing. user info exists with old time = $oldTime and this event time = ${e.eventData.createdAt}");
@ -1169,10 +1169,10 @@ bool processKind3Event(Event newContactEvent) {
String? name = gKindONames[newContactEvent.eventData.pubkey]?.name,
about = gKindONames[newContactEvent.eventData.pubkey]?.about,
picture = gKindONames[newContactEvent.eventData.pubkey]?.picture,
lud16 = gKindONames[newContactEvent.eventData.pubkey]?.lud16,
lud06 = gKindONames[newContactEvent.eventData.pubkey]?.lud06,
nip05id = gKindONames[newContactEvent.eventData.pubkey]?.nip05Id??"";
gKindONames[newContactEvent.eventData.pubkey] = UserNameInfo(createdAt, name, about, picture, lud16, nip05id, newContactEvent, newContactEvent.eventData.createdAt );
gKindONames[newContactEvent.eventData.pubkey] = UserNameInfo(createdAt, name, about, picture, lud06, nip05id, newContactEvent, newContactEvent.eventData.createdAt );
entryModified = true;;
}
}

View File

@ -3,7 +3,7 @@ import 'package:logging/logging.dart';
// name of executable
const String exename = "nostr_console";
const String version = "0.3.0-beta";
const String version = "0.3.1-beta";
int gDebug = 0;
int gSpecificDebug = 0;
@ -192,7 +192,11 @@ int gInvalidInputCount = 0;
const int gMaxInValidInputAccepted = 40;
// LN settings
const int gMinLud16AddressLength = 10; // used in printProfile
const int gMinLud06AddressLength = 10; // used in printProfile
const int gMaxEventsInThreadPrinted = 20;
const int gMaxInteger = 100000000000; // used in printTree
String gWarning_TOO_MANY_TREES = "Note: This thread has more replies than are being printed. Search for top post by id to see full thread.";
// https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors
// Color related settings

View File

@ -1,3 +1,4 @@
import 'dart:ffi';
import 'dart:io';
import 'dart:convert';
import 'package:nostr_console/event_ds.dart';
@ -415,19 +416,32 @@ class Tree {
store = s;
}
/***********************************************************************************************************************************/
/* The main print tree function. Calls the reeSelector() for every node and prints it( and its children), only if it returns true.
* returns Point , where first int is total Threads ( or top trees) printed, and second is notifications printed
* returns list< total top threads printed, total events printed, total notifications printed>
*/
Point printTree(int depth, DateTime newerThan, bool topPost) {
Point numPrinted = Point(0,0);
List<int> printTree(int depth, DateTime newerThan, bool topPost, [int countPrinted = 0, int maxToPrint = gMaxInteger]) {
//Point numPrinted = Point(0,0);
List<int> ret = [0,0,0];
if(event.eventData.isNotification) {
numPrinted += Point(0, 1);
ret[2] = 1;
}
countPrinted++;
event.printEvent(depth, topPost);
ret[1] = 1;
if( countPrinted > maxToPrint) {
print("");
printDepth(0);
print(gWarning_TOO_MANY_TREES);
return ret;
}
// sort children by time
if( children.length > 1) {
children.sort(sortTreeByItsTime);
@ -436,6 +450,13 @@ class Tree {
bool leftShifted = false;
for( int i = 0; i < children.length; i++) {
if( countPrinted > maxToPrint) {
//print("");
//printDepth(depth+1);
//print(gWarning_TOO_MANY_TREES);
break;
}
// 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
// left by about <leftShiftThreadsBy> places
@ -444,22 +465,22 @@ class Tree {
printDepth(depth+1);
stdout.write("${getNumDashes((leftShiftThreadsBy + 1) * gSpacesPerDepth - 1, "")}\n");
leftShifted = true;
if(false && event.eventData.id == "471bb00f66212a594c1e875f708d01fc6aa4ed83d638c928d25e37dee28f8605")
print('left shifting for event id: ${event.eventData.id} i = $i child = ${children[i].event.eventData.id} child kind = ${children[i].event.eventData.kind}');
}
numPrinted += children[i].printTree(depth+1, newerThan, false);
List<int> temp = children[i].printTree(depth+1, newerThan, false, countPrinted, maxToPrint);
ret[1] += temp[1];
ret[2] += temp[2];
countPrinted += ret[1];
}
// https://gist.github.com/dsample/79a97f38bf956f37a0f99ace9df367b9
if( leftShifted) {
stdout.write("\n");
printDepth(depth+1);
print(""); // same spaces as when its left shifted
}
} // end for loop
return numPrinted;
return ret;
}
// returns the time of the most recent comment
@ -1487,7 +1508,7 @@ class Store {
* @printNotifications Add the given events to the Tree, and print the events as notifications
* It should be ensured that these are only kind 1 events
*/
Point printTreeNotifications(Set<String> newEventIdsSet) {
List<int> printTreeNotifications(Set<String> newEventIdsSet) {
int countNotificationEvents = 0;
for( var newEventId in newEventIdsSet) {
@ -1504,9 +1525,8 @@ class Store {
}
if( countNotificationEvents == 0) {
return Point(0,0);
return [0,0,0];
}
List<Tree> topNotificationTree = []; // collect all top tress to display in this list. only unique tress will be displayed
newEventIdsSet.forEach((eventID) {
@ -1560,28 +1580,33 @@ class Store {
Store.reCalculateMarkerStr();
Point retval = Point(0,0);
List<int> ret = [0,0,0];
topNotificationTree.forEach( (t) {
retval += Store.printTopPost(t, 0, DateTime(0));
List<int> temp = Store.printTopPost(t, 0, DateTime(0));
ret[0] += temp[0];
ret[1] += temp[1];
ret[2] += temp[2];
print("\n");
});
return retval;
return ret;
}
// returns Point , where first int is total Threads ( or top trees) printed, and second is notifications printed
static Point printTopPost(Tree topTree, int depth, DateTime newerThan) {
// returns Point , where first int is total Threads ( or top trees) printed, second is total events printed, and third is notifications printed
static List<int> printTopPost(Tree topTree, int depth, DateTime newerThan, [int maxToPrint = gMaxEventsInThreadPrinted]) {
stdout.write(Store.startMarkerStr);
Point numPrinted = topTree.printTree(depth, newerThan, true);
numPrinted += Point(1, 0); // for this top post
List<int> counts = topTree.printTree(depth, newerThan, true, 0, maxToPrint);
counts[0] += 1; // for this top post
stdout.write(endMarkerStr);
return numPrinted;
//print("In node printTopPost: ret =${counts}");
return counts;
}
/***********************************************************************************************************************************/
/* The main print tree function. Calls the reeSelector() for every node and prints it( and its children), only if it returns true.
/* The main print tree function. Calls the treeSelector() for every node and prints it( and its children), only if it returns true.
*/
Point printTree(int depth, DateTime newerThan, fTreeSelector treeSelector) {
List<int> printTree(int depth, DateTime newerThan, fTreeSelector treeSelector, [int maxToPrint = gMaxEventsInThreadPrinted]) {
topPosts.sort(sortTreeNewestReply); // sorting done only for top most threads. Lower threads aren't sorted so save cpu etc TODO improve top sorting
@ -1596,7 +1621,7 @@ class Store {
// comment starts at Sd , then depth = Sd - S1 / gSpacesPerDepth
// Depth is in gSpacesPerDepth
Point numPrinted = Point(0,0);
List<int> ret = [0,0,0];
for( int i = 0; i < topPosts.length; i++) {
// continue if this children isn't going to get printed anyway; selector is only called for top most tree
@ -1615,7 +1640,11 @@ class Store {
stdout.write("\n");
}
numPrinted += printTopPost(topPosts[i], depth, newerThan);
List<int> temp = printTopPost(topPosts[i], depth, newerThan, maxToPrint);
ret[0] += temp[0];
ret[1] += temp[1];
ret[2] += temp[2];
}
int printedNumHours = DateTime.now().difference(newerThan).inHours;
@ -1626,11 +1655,13 @@ class Store {
} else {
strTime = "$printedNumHours hours";
}
if( numPrinted.x > 0) {
print("\nTotal threads printed: ${numPrinted.x} for last $strTime.");
if( ret[0] > 0) {
print("\nTotal threads printed: ${ret[0]} for last $strTime.");
}
return numPrinted;
//print("in node print all: ret = $ret");
return ret;
}
int getNumChannels() {

View File

@ -1,13 +1,18 @@
name: nostr_console
description: A multi-platform nostr client built for terminal/console
version: 0.3.0-beta
version: 0.3.1-beta
homepage: https://github.com/vishalxl/nostr_console
# 0.3.1
# printed only 20 maximum events in a thread to reduce screen spam from long threads. Only in search results are all threads printed; and a thread or event can be searched by 6 digit id-prefix of the event thats mentioned.
# improved user notifications , menu 2 -> 3, now likes are shown as notifications and less informative
# improved 2 -> 5. better printing. and fixed white after reaction highlighed issue
# improved 2 -> 6 too, now follows posts get highlighed, and so do their reactions.
# mentions get highlighed in above menus
# if too many wrong menu inputs are given ( >40) then program exits without saving any new events. for issue #49
# showed lnurl, if any, in profile as qr code. should have key lud16
# 0.3.0
# added check marks; added more default users