From 5071c1f1e6a6f5976503f6d6e5db7846cbbf3a12 Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Wed, 28 Dec 2022 14:55:59 +0530 Subject: [PATCH] fix where notifications likes were messing up length .. and getting shifted to left. By counting the newly inserted color string into the calculations. --- lib/event_ds.dart | 32 ++++++++++++++++++++++++-------- test/nostr_console_test.dart | 9 +++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/event_ds.dart b/lib/event_ds.dart index 837ecb6..bbd20c5 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -733,7 +733,9 @@ class EventData { 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)}" ; + List reactionString = getReactionStr(depth); + //print("\n|${reactionString[0]}|\n ${ reactionString[1]}\n }"); + String idDateLikes = " |id: ${maxN(id)}, $strDate ${reactionString[0]}" ; idDateLikes = idDateLikes.padRight(typicalxLen); String temp = tempEvaluatedContent==""?tempContent: tempEvaluatedContent; @@ -761,11 +763,14 @@ class EventData { if( contentShifted.length <= maxLineLen ) effectiveLastLineLen = contentShifted.length; + // needed to use this because the color padding in notifications reactions will mess up the length calculation in the actual reaction string + int colorStrLen = reactionString[0].length - reactionString[1]; + // now actually find where the likesDates string goes if( (gSpacesPerDepth * depth + effectiveNameFieldLen + effectiveLastLineLen + idDateLikes.length ) <= gTextWidth) { - idDateLikes = idDateLikes.padLeft((gTextWidth ) - (gSpacesPerDepth * depth + effectiveNameFieldLen + effectiveLastLineLen)); + idDateLikes = idDateLikes.padLeft((gTextWidth ) + colorStrLen - (gSpacesPerDepth * depth + effectiveNameFieldLen + effectiveLastLineLen)); } else { - idDateLikes = "\n" + idDateLikes.padLeft(gNumLeftMarginSpaces + gTextWidth); + idDateLikes = "\n" + idDateLikes.padLeft(gNumLeftMarginSpaces + gTextWidth + colorStrLen); } // print content and the dateslikes string @@ -901,38 +906,49 @@ class EventData { // looks up global map of reactions, if this event has any reactions, and then prints the reactions // in appropriate color( in case one is a notification, which is stored in member variable) - String getReactionStr(int depth) { + // returns the string and its length in a dynamic list + List getReactionStr(int depth) { String reactorNames = ""; + int len = 0; + if( isHidden || isDeleted) { - return ""; + return ["",0]; } if( gReactions.containsKey(id)) { reactorNames = "Likes: "; + len = reactorNames.length; int numReactions = gReactions[id]?.length??0; List> reactors = gReactions[id]??[]; bool firstEntry = true; for( int i = 0; i listEvents = {exampleEvent1, exampleEvent2, exampleEvent3}; Store node = Store.fromEvents(listEvents); - //node.printTree(0, DateTime.now().subtract(Duration(days:1000)), selectorShowAllTrees); + + //node.printStoreTrees(0, DateTime.now().subtract(Duration(days: 1000)), (a) => true); //print("========================="); }); @@ -262,6 +263,10 @@ String expectedResult = expect(3046, node.getNumMessagesInChannel('25e5c82273a271cb1a840d0060391a0bf4965cafeb029d5ab55350b418953fbb'), reason:'verify a public channel has correct number of messages'); + + //node.printStoreTrees(0, DateTime.now().subtract(Duration(days: 105)), (a) => true); 28 dec 2022 + + String pubkeyQrCodeResult1 = """ █▀▀▀▀▀█ ██▄▄▀ ▄▄ █ ▄▀ █▀▀▀▀▀█ █ ███ █ █▄█ ██▄ ▄▄ ██▀▀ █ ███ █