improved channel message printing and related

This commit is contained in:
Vishal 2022-09-04 00:15:33 +05:30
parent 42d804a9b6
commit f9eec2731d
4 changed files with 52 additions and 16 deletions

View File

@ -459,6 +459,7 @@ Future<void> channelMenuUI(Store node) async {
//gDebug = 0;
bool continueChatMenu = true;
while(continueChatMenu) {
readjustAlignment();
int option = showMenu([ 'Show public channels', // 1
'Enter a public channel', // 2
'Go back to main menu'], // 3
@ -480,6 +481,7 @@ Future<void> channelMenuUI(Store node) async {
}
int pageNum = 1;
while(showChannelOption) {
readjustAlignment();
String fullChannelId = node.showChannel(channelId, pageNum);
if( fullChannelId == "") {
print("Could not find the given channel.");
@ -618,19 +620,7 @@ Future<void> mainMenuUi(Store node) async {
bool userContinue = true;
while(userContinue) {
// align the text again in case the window size has been changed
if( gAlignment == "center") {
try {
if( gTextWidth > stdout.terminalColumns) {
gTextWidth = stdout.terminalColumns - 5;
}
gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2;
} on StdoutException catch (e) {
print("Terminal information not available");
if( gDebug>0) print("${e.message}");
gNumLeftMarginSpaces = 0;
}
}
readjustAlignment();
await processNotifications(node); // this takes 300 ms

View File

@ -294,6 +294,37 @@ class EventData {
return '"${content.substring(0, len)}..." - ${getAuthorName(pubkey)}';
}
String getStrForChannel(int depth) {
String strToPrint = "";
String name = getAuthorName(pubkey);
String strDate = getPrintableDate(createdAt);
String tempEvaluatedContent = evaluatedContent;
String tempContent = content;
if( isHidden) {
name = "<hidden>";
strDate = "<hidden>";
tempEvaluatedContent = tempContent = "<You have hidden this post>";
}
// delete supercedes hidden
if( isDeleted) {
name = "<deleted>";
strDate = "<deleted>";
tempEvaluatedContent = tempContent = content; // content would be changed so show that
}
String nameToPrint = name.padLeft(gSpacesPerDepth * 2).substring(0, gSpacesPerDepth * 2);
String dateToPrint = strDate.padLeft(gSpacesPerDepth * 2).substring(0, gSpacesPerDepth * 2);
strToPrint = "${getDepthSpaces(depth)} $dateToPrint$nameToPrint: ";
int contentDepth = depth + 4 + 1;
String contentShifted = rightShiftContent(tempEvaluatedContent==""?tempContent: tempEvaluatedContent, gSpacesPerDepth * contentDepth);
strToPrint += contentShifted;
return strToPrint;
}
// 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) {
@ -868,3 +899,18 @@ Set<Event> readEventsFromFile(String filename) {
return events;
}
void readjustAlignment() {
// align the text again in case the window size has been changed
if( gAlignment == "center") {
try {
if( gTextWidth > stdout.terminalColumns) {
gTextWidth = stdout.terminalColumns - 5;
}
gNumLeftMarginSpaces = (stdout.terminalColumns - gTextWidth )~/2;
} on StdoutException catch (e) {
print("Terminal information not available");
if( gDebug>0) print("${e.message}");
gNumLeftMarginSpaces = 0;
}
}
}

View File

@ -112,7 +112,7 @@ const int gMaxDifficultyAllowed = 24;
int gDifficulty = 0;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// channel related settings
const int gNumChannelMessagesToShow = 15;
const int gNumChannelMessagesToShow = 25;
const int gMaxChannelPagesDisplayed = 50;

View File

@ -43,8 +43,8 @@ class ScrollableMessages {
String eId = messageIds[i];
Event? e = tempChildEventsMap[eId]?.event;
if( e!= null) {
e.printEvent(0);
print("");
print(e.eventData.getStrForChannel(0));
//print("");
}
}