Newer
Older
// List the messages using the lightbar or traditional interface, depending on
// what this.msgListUseLightbarListInterface is set to. The lightbar interface requires ANSI.
if (this.msgListUseLightbarListInterface && canDoHighASCIIAndANSI())
retObj = this.ListMessages_Lightbar(pAllowChgSubBoard);
else
retObj = this.ListMessages_Traditional(pAllowChgSubBoard);
return retObj;
}
// For the DigDistMsgReader class: Performs the message listing, given a
// sub-board code. This version uses a traditional user interface, prompting
// the user at the end of each page to continue, quit, or read a message.
// Note: This function requires this.msgbase to be valid and open.
//
// Parameters:

nightfox
committed
// pAllowChgSubBoard: Optional - A boolean to specify whether or not to allow
// changing to another sub-board. Defaults to true.
//
// Return value: An object containing the following properties:
// lastUserInput: The user's last keypress/input
// selectedMsgOffset: The index of the message selected to read,
// if one was selected. If none was selected,
// this will be -1.
function DigDistMsgReader_ListMessages_Traditional(pAllowChgSubBoard)
{

nightfox
committed
var retObj = new Object();
retObj.lastUserInput = "";
retObj.selectedMsgOffset = -1;
// Reset this.readAMessage and deniedReadingmessage to false, in case the
// message listing has previously ended with them set to true.
this.readAMessage = false;
this.deniedReadingMessage = false;
// this.msgbase must be valid before continuing.
if ((typeof(this.msgbase) == "undefined") || (this.msgbase == null))
{

nightfox
committed
console.center("\1n\1h\1yError: \1wUnable to list messages because the sub-board is not open.\r\n\1p");
return retObj;
}
else if (!this.msgbase.is_open)
{

nightfox
committed
console.center("\1n\1h\1yError: \1wUnable to list messages because the sub-board is not open.\r\n\1p");
return retObj;
}

nightfox
committed
var allowChgSubBoard = (typeof(pAllowChgSubBoard) == "boolean" ? pAllowChgSubBoard : true);
// this.tradMsgListNumLines stores the maximum number of lines to write. It's the number
// of rows on the user's screen - 3 to make room for the header line
// at the top, the question line at the bottom, and 1 extra line at
// the bottom of the screen so that displaying carriage returns
// doesn't mess up the position of the header lines at the top.
this.tradMsgListNumLines = console.screen_rows-3;
var nListStartLine = 2; // The first line number on the screen for the message list
// If we will be displaying the message group and sub-board in the
// header at the top of the screen (an additional 2 lines), then
// update this.tradMsgListNumLines and nListStartLine to account for this.
if (this.displayBoardInfoInHeader)
{
this.tradMsgListNumLines -= 2;
nListStartLine += 2;
}

nightfox
committed
// If the user's terminal doesn't support ANSI, then re-calculate
// this.tradMsgListNumLines - we won't be keeping the headers at the top of the
// screen.
if (!canDoHighASCIIAndANSI()) // Could also be !console.term_supports(USER_ANSI)
this.tradMsgListNumLines = console.screen_rows - 2;
// Clear the screen and write the header at the top
console.clear("\1n");

nightfox
committed
this.WriteMsgListScreenTopHeader();
// If this.tradListTopMsgIdx hasn't been set yet, then get the index of the user's
// last read message and figure out which page it's on and set the top message
// index accordingly.
if (this.tradListTopMsgIdx == -1)

nightfox
committed
this.SetUpTraditionalMsgListVars();
// Write the message list
var continueOn = true;

nightfox
committed
var retvalObj = null;
var curpos = null; // Current character position
var lastScreen = false;
while (continueOn)
{
// Go to the top and write the current page of message information,
// then update curpos.
console.gotoxy(1, nListStartLine);
lastScreen = this.ListScreenfulOfMessages(this.tradListTopMsgIdx, this.tradMsgListNumLines);
curpos = console.getxy();
clearToEOS(curpos.y);
console.gotoxy(curpos);
// Prompt the user whether or not to continue or to read a message
// (by message number).
if (this.reverseListOrder)
retvalObj = this.PromptContinueOrReadMsg((this.tradListTopMsgIdx == this.NumMessages()-1), lastScreen, allowChgSubBoard);

nightfox
committed
else
retvalObj = this.PromptContinueOrReadMsg((this.tradListTopMsgIdx == 0), lastScreen, allowChgSubBoard);

nightfox
committed
retObj.lastUserInput = retvalObj.userInput;
retObj.selectedMsgOffset = retvalObj.selectedMsgOffset;
continueOn = retvalObj.continueOn;
// TODO: Update this to use PageUp & PageDown keys for paging? It would
// require updating PromptContinueOrReadMsg(), which would be non-trivial
// because that method uses console.getkeys() with a list of allowed keys
// and a message number limit.
if (continueOn)
{
// If the user chose to go to the previous page of listings,
// then subtract the appropriate number of messages from
// this.tradListTopMsgIdx in order to do so.
if (retvalObj.userInput == "P")
{
if (this.reverseListOrder)

nightfox
committed
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
{
this.tradListTopMsgIdx += this.tradMsgListNumLines;
// If we go past the beginning, then we need to reset
// msgNum so we'll be at the beginning of the list.
var totalNumMessages = this.NumMessages();
if (this.tradListTopMsgIdx >= totalNumMessages)
this.tradListTopMsgIdx = totalNumMessages - 1;
}
else
{
this.tradListTopMsgIdx -= this.tradMsgListNumLines;
// If we go past the beginning, then we need to reset
// msgNum so we'll be at the beginning of the list.
if (this.tradListTopMsgIdx < 0)
this.tradListTopMsgIdx = 0;
}
}
// If the user chose to go to the next page, update
// this.tradListTopMsgIdx appropriately.
else if (retvalObj.userInput == "N")
{
if (this.reverseListOrder)

nightfox
committed
this.tradListTopMsgIdx -= this.tradMsgListNumLines;
else
this.tradListTopMsgIdx += this.tradMsgListNumLines;
}
// First page
else if (retvalObj.userInput == "F")
{
if (this.reverseListOrder)

nightfox
committed
this.tradListTopMsgIdx = this.NumMessages() - 1;
else
this.tradListTopMsgIdx = 0;
}
// Last page
else if (retvalObj.userInput == "L")
{
if (this.reverseListOrder)

nightfox
committed
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
{
this.tradListTopMsgIdx = (this.NumMessages() % this.tradMsgListNumLines) - 1;
// If this.tradListTopMsgIdx is now invalid (below 0), then adjust it
// to properly display the last page of messages.
if (this.tradListTopMsgIdx < 0)
this.tradListTopMsgIdx = this.tradMsgListNumLines - 1;
}
else
{
var totalNumMessages = this.NumMessages();
this.tradListTopMsgIdx = totalNumMessages - (totalNumMessages % this.tradMsgListNumLines);
if (this.tradListTopMsgIdx >= totalNumMessages)
this.tradListTopMsgIdx = totalNumMessages - this.tradMsgListNumLines;
}
}
// D: Delete a message
else if (retvalObj.userInput == "D")
{
if (this.CanDelete() || this.CanDeleteLastMsg())
{
var msgNum = this.PromptForMsgNum({ x: curpos.x, y: curpos.y+1 }, this.text.deleteMsgNumPromptText, false, ERROR_PAUSE_WAIT_MS, false);
// If the user enters a valid message number, then call the
// DeleteMessage() method, which will prompt the user for
// confirmation and delete the message if confirmed.
if (msgNum > 0)
this.PromptAndDeleteMessage(msgNum-1);

nightfox
committed
// Refresh the top header on the screen for continuing to list
// messages.
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
}
// E: Edit a message
else if (retvalObj.userInput == "E")
{
if (this.CanEdit())
{
var msgNum = this.PromptForMsgNum({ x: curpos.x, y: curpos.y+1 }, this.text.editMsgNumPromptText, false, ERROR_PAUSE_WAIT_MS, false);
// If the user entered a valid message number, then let the
// user edit the message.
if (msgNum > 0)
{
// See if the current message header has our "isBogus" property and it's true.
// Only let the user edit the message if it's not a bogus message header.
// The message header could have the "isBogus" property, for instance, if
// it's a vote message (introduced in Synchronet 3.17).
var tmpMsgHdr = this.GetMsgHdrByIdx(msgNum-1);
var hdrIsBogus = (tmpMsgHdr.hasOwnProperty("isBogus") ? tmpMsgHdr.isBogus : false);
if (!hdrIsBogus)
var returnObj = this.EditExistingMsg(msgNum-1);
else
{
console.print("\1n\r\n\1h\1yThat message isn't editable.\n");
console.crlf();
console.pause();
}
}

nightfox
committed
// Refresh the top header on the screen for continuing to list
// messages.
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
}
// G: Go to a specific message by # (place that message on the top)
else if (retvalObj.userInput == "G")
{
var msgNum = this.PromptForMsgNum(curpos, "\1n" + this.text.goToMsgNumPromptText, false, ERROR_PAUSE_WAIT_MS, false);
if (msgNum > 0)
this.tradListTopMsgIdx = msgNum - 1;

nightfox
committed
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
// Refresh the top header on the screen for continuing to list
// messages.
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
// ?: Display help
else if (retvalObj.userInput == "?")
{
console.clear("\1n");
this.DisplayMsgListHelp(allowChgSubBoard, true);
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
// C: Change to another message area (sub-board)
else if (retvalObj.userInput == "C")
{
if (allowChgSubBoard && (this.subBoardCode != "mail"))
{
// Store the current sub-board code so we can see if it changed
var oldSubCode = bbs.cursub_code;
// Let the user choose another message area. If they chose
// a different message area, then set up the message base
// object accordingly.
this.SelectMsgArea();
if (bbs.cursub_code != oldSubCode)
{
var chgSubRetval = this.ChangeSubBoard(bbs.cursub_code);
continueOn = chgSubRetval.succeeded;
}
// Update the traditional list variables and refresh the screen
if (continueOn)
{
this.SetUpTraditionalMsgListVars();
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
}
}
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
// S: Select message(s)
else if (retvalObj.userInput == "S")
{
// Input the message number list from the user
console.print("\1n\1cNumber(s) of message(s) to select, (\1hA\1n\1c=All, \1hN\1n\1c=None, \1hENTER\1n\1c=cancel)\1g\1h: \1c");
var userNumberList = console.getstr(128, K_UPPER);
// If the user entered A or N, then select/un-select all messages.
// Otherwise, select only the messages that the user entered.
if ((userNumberList == "A") || (userNumberList == "N"))
{
var messageSelectToggle = (userNumberList == "A");
var totalNumMessages = this.NumMessages();
for (var msgIdx = 0; msgIdx < totalNumMessages; ++msgIdx)
this.ToggleSelectedMessage(this.subBoardCode, msgIdx, messageSelectToggle);
}
else
{
if (userNumberList.length > 0)
{
var numArray = parseNumberList(userNumberList);
for (var numIdx = 0; numIdx < numArray.length; ++numIdx)
this.ToggleSelectedMessage(this.subBoardCode, numArray[numIdx]-1);
}
}
// Refresh the top header on the screen for continuing to list
// messages.
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
// Ctrl-D: Batch delete (for selected messages)
else if (retvalObj.userInput == CTRL_D)
{
console.print("\1n");
console.crlf();
if (this.NumSelectedMessages() > 0)
{
// The PromptAndDeleteSelectedMessages() method will prompt the user for confirmation
// to delete the message and then delete it if confirmed.
this.PromptAndDeleteSelectedMessages();
// In case all messages were deleted, if that's the case, show
// an appropriate message and don't continue listing messages.
//if (this.NumMessages(true) == 0)
if (!this.NonDeletedMessagesExist())
{
continueOn = false;
// Note: The following doesn't seem to be necessary, since
// the ReadOrListSubBoard() method will show a message saying
// there are no messages to read and then will quit out.
//this.msgbase.close();
//this.msgbase = null;
//console.clear("\1n");
//console.center("\1n\1h\1yThere are no messages to display.");
//console.crlf();
//console.pause();
}
else
{
// There are still messages to list, so refresh the top
// header on the screen for continuing to list messages.
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
}
else
{
// There are no selected messages
console.print("\1n\1h\1yThere are no selected messages.");
mswait(ERROR_PAUSE_WAIT_MS);
// Refresh the top header on the screen for continuing to list messages.
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
}
}

nightfox
committed
else
{
// If a message has been selected, exit out of this input loop
// so we can return from this method - The calling method will
// call the enhanced reader method.
if (retObj.selectedMsgOffset >= 0)

nightfox
committed
continueOn = false;
}
}
}

nightfox
committed
return retObj;
}
// For the DigDistMsgReader class: Performs the message listing, given a
// sub-board code. This verison uses a lightbar interface for message
// navigation. Note: This function requires this.msgbase to be valid and
// open.
//
// Parameters:

nightfox
committed
// pAllowChgSubBoard: Optional - A boolean to specify whether or not to allow
// changing to another sub-board. Defaults to true.
//
// Return value: An object containing the following properties:
// lastUserInput: The user's last keypress/input
// selectedMsgOffset: The index of the message selected to read,
// if one was selected. If none was selected,
// this will be -1.
function DigDistMsgReader_ListMessages_Lightbar(pAllowChgSubBoard)
{

nightfox
committed
var retObj = new Object();
retObj.lastUserInput = "";
retObj.selectedMsgOffset = -1;
// This method is only supported if the user's terminal supports
// ANSI.
if (!canDoHighASCIIAndANSI()) // Could also be !console.term_supports(USER_ANSI)
{
console.print("\r\n\1h\1ySorry, an ANSI terminal is required for this operation.\1n\1w\r\n");
console.pause();
return retObj;
}
// Reset this.readAMessage and deniedReadingMessage to false, in case the
// message listing has previously ended with them set to true.
this.readAMessage = false;
this.deniedReadingMessage = false;

nightfox
committed
// this.msgbase must be valid before continuing.
if ((typeof(this.msgbase) == "undefined") || (this.msgbase == null))
{

nightfox
committed
console.center("\1n\1h\1yError: \1wUnable to list messages because the sub-board is not open.\r\n\1p");
return retObj;
}
else if (!this.msgbase.is_open)
{

nightfox
committed
console.center("\1n\1h\1yError: \1wUnable to list messages because the sub-board is not open.\r\n\1p");
return retObj;
}

nightfox
committed
var allowChgSubBoard = (typeof(pAllowChgSubBoard) == "boolean" ? pAllowChgSubBoard : true);

nightfox
committed
// This function will be used for displaying the help line at
// the bottom of the screen.
function DisplayHelpLine(pHelpLineText)
{
console.gotoxy(1, console.screen_rows);
console.print(pHelpLineText);
console.cleartoeol("\1n");
}

nightfox
committed
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
// Clear the screen and write the header at the top
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
// If the lightbar message list index & cursor position variables haven't been
// set yet, then set them.
if ((this.lightbarListTopMsgIdx == -1) || (this.lightbarListSelectedMsgIdx == -1) ||
(this.lightbarListCurPos == null))
{
this.SetUpLightbarMsgListVars();
}
// List a screenful of message headers
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
var lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
// Move the cursor to where it needs to be
console.gotoxy(this.lightbarListCurPos);
// User input loop
var bottomMsgIndex = 0;
var userInput = "";
var msgHeader = null;
var continueOn = true;
while (continueOn)
{
bbs.command_str = ""; // To prevent weirdness
retObj.selectedMsgOffset = -1;
// Calculate the message number (0-based) of the message
// appearing on the bottom of the screen.
if (this.reverseListOrder)
{

nightfox
committed
bottomMsgIndex = this.lightbarListTopMsgIdx - this.lightbarMsgListNumLines + 1;
if (bottomMsgIndex < 0)
bottomMsgIndex = 0;
}
else
{

nightfox
committed
var totalNumMessages = this.NumMessages();
bottomMsgIndex = this.lightbarListTopMsgIdx + this.lightbarMsgListNumLines - 1;
if (bottomMsgIndex >= totalNumMessages)
bottomMsgIndex = totalNumMessages - 1;
}

nightfox
committed
// Write the current message information with highlighting colors
msgHeader = this.GetMsgHdrByIdx(this.lightbarListSelectedMsgIdx);
this.PrintMessageInfo(msgHeader, true, this.lightbarListSelectedMsgIdx+1);
console.gotoxy(this.lightbarListCurPos); // Make sure the cursor is still in the right place

nightfox
committed
// Get a key from the user (upper-case) and take appropriate action.
userInput = getKeyWithESCChars(K_UPPER|K_NOCRLF|K_NOECHO|K_NOSPIN);
retObj.lastUserInput = userInput;
// Q: Quit
if (userInput == "Q")
{
// Quit
continueOn = false;
break;
}
// ?: Show help
else if (userInput == "?")
{
// Display help
console.clear("\1n");
this.DisplayMsgListHelp(allowChgSubBoard, true);

nightfox
committed
// Re-draw the message list on the screen
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
console.gotoxy(this.lightbarListCurPos); // Put the cursor back where it should be
}
// Up arrow: Highlight the previous message
else if (userInput == KEY_UP)
{
// Make sure this.lightbarListSelectedMsgIdx is within bounds before moving down.
if (this.reverseListOrder)

nightfox
committed
{
if (this.lightbarListSelectedMsgIdx >= this.NumMessages() - 1)
continue;
}
else
{
if (this.lightbarListSelectedMsgIdx <= 0)
continue;
}

nightfox
committed
// Print the current message information with regular colors
this.PrintMessageInfo(msgHeader, false, this.lightbarListSelectedMsgIdx+1);
if (this.reverseListOrder)

nightfox
committed
++this.lightbarListSelectedMsgIdx;
else
--this.lightbarListSelectedMsgIdx;

nightfox
committed
// If the current screen row is above the first line allowed, then
// move the cursor up one row.
if (this.lightbarListCurPos.y > this.lightbarMsgListStartScreenRow)
{
console.gotoxy(1, this.lightbarListCurPos.y-1);
this.lightbarListCurPos.x = 1;
--this.lightbarListCurPos.y;
}
else
{
// Go onto the previous page, with the cursor highlighting
// the last message on the page.
if (this.reverseListOrder)

nightfox
committed
this.lightbarListTopMsgIdx = this.lightbarListSelectedMsgIdx + this.lightbarMsgListNumLines - 1;
else
this.lightbarListTopMsgIdx = this.lightbarListSelectedMsgIdx - this.lightbarMsgListNumLines + 1;

nightfox
committed
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
console.gotoxy(1, this.lightbarMsgListStartScreenRow+this.lightbarMsgListNumLines-1);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow+this.lightbarMsgListNumLines-1;
}
}
// Down arrow: Highlight the next message
else if (userInput == KEY_DOWN)
{
// Make sure this.lightbarListSelectedMsgIdx is within bounds before moving down.
if (this.reverseListOrder)

nightfox
committed
{
if (this.lightbarListSelectedMsgIdx <= 0)
continue;
}
else
{
if (this.lightbarListSelectedMsgIdx >= this.NumMessages() - 1)
continue;
}

nightfox
committed
// Print the current message information with regular colors
this.PrintMessageInfo(msgHeader, false, this.lightbarListSelectedMsgIdx+1);
if (this.reverseListOrder)

nightfox
committed
--this.lightbarListSelectedMsgIdx;
else
++this.lightbarListSelectedMsgIdx;

nightfox
committed
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
// If the current screen row is below the last line allowed, then
// move the cursor down one row.
if (this.lightbarListCurPos.y < this.lightbarMsgListStartScreenRow+this.lightbarMsgListNumLines-1)
{
console.gotoxy(1, this.lightbarListCurPos.y+1);
this.lightbarListCurPos.x = 1;
++this.lightbarListCurPos.y;
}
else
{
// Go onto the next page, with the cursor highlighting
// the first message on the page.
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListTopMsgIdx = this.lightbarListSelectedMsgIdx;
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
// If we were on the last page, then clear the screen from
// the current line to the end of the screen.
if (lastPage)
{
this.lightbarListCurPos = console.getxy();
clearToEOS(this.lightbarListCurPos.y);
// Make sure the help line is still there
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}

nightfox
committed
// Move the cursor to the top of the list
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
}
}
// HOME key: Go to the first message on the screen
else if (userInput == KEY_HOME)
{
// Print the current message information with regular colors
this.PrintMessageInfo(msgHeader, false, this.lightbarListSelectedMsgIdx+1);
// Go to the first message of the current page
if (this.reverseListOrder)

nightfox
committed
this.lightbarListSelectedMsgIdx += (this.lightbarListCurPos.y - this.lightbarMsgListStartScreenRow);
else
this.lightbarListSelectedMsgIdx -= (this.lightbarListCurPos.y - this.lightbarMsgListStartScreenRow);
// Move the cursor to the first message line
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
}
// END key: Go to the last message on the screen
else if (userInput == KEY_END)
{
// Print the current message information with regular colors
this.PrintMessageInfo(msgHeader, false, this.lightbarListSelectedMsgIdx+1);
// Update the selected message #
this.lightbarListSelectedMsgIdx = bottomMsgIndex;
// Go to the last message of the current page
if (this.reverseListOrder)

nightfox
committed
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow + this.lightbarListTopMsgIdx - bottomMsgIndex;
else
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow + bottomMsgIndex - this.lightbarListTopMsgIdx;
console.gotoxy(this.lightbarListCurPos);
}
// Enter key: Select a message to read
else if (userInput == KEY_ENTER)
{
// See if the current message header has our "isBogus" property and it's true.
// Only let the user read the message if it's not a bogus message header.
// The message header could have the "isBogus" property, for instance, if
// it's a vote message (introduced in Synchronet 3.17).
var hdrIsBogus = (msgHeader.hasOwnProperty("isBogus") ? msgHeader.isBogus : false);
if (!hdrIsBogus)

nightfox
committed
{
var originalCurpos = console.getxy();
// Allow the user to read the current message.
var readMsg = true;
if (this.promptToReadMessage)
{
// Confirm with the user whether to read the message.
var sReadMsgConfirmText = this.colors["readMsgConfirmColor"]
+ "Read message "
+ this.colors["readMsgConfirmNumberColor"]
+ +(this.GetMsgIdx(msgHeader.number) + 1)
+ this.colors["readMsgConfirmColor"]
+ ": Are you sure";
console.gotoxy(1, console.screen_rows);
console.print("\1n");
console.clearline();
readMsg = console.yesno(sReadMsgConfirmText);
}
var repliedToMessage = false;
if (readMsg)
{
// If there is a search specified and the search result objects are
// set up for the current sub-board, then the selected message offset
// should be the search result array index. Otherwise (if not
// searching), the message offset should be the actual message offset
// in the message base.
if (this.SearchingAndResultObjsDefinedForCurSub())
retObj.selectedMsgOffset = this.lightbarListSelectedMsgIdx;
else
{
//retObj.selectedMsgOffset = msgHeader.offset;
retObj.selectedMsgOffset = this.GetMsgIdx(msgHeader.number);

nightfox
committed
if (retObj.selectedMsgOffset < 0)
retObj.selectedMsgOffset = 0;
}
// Return from here so that the calling function can switch into
// reader mode.
continueOn = false;
return retObj;
}
else
this.deniedReadingMessage = true;
// Ask the user if they want to continue reading messages
if (this.promptToContinueListingMessages)

nightfox
committed
{
continueOn = console.yesno(this.colors["afterReadMsg_ListMorePromptColor"] +
"Continue listing messages");
}
// If the user chose to continue reading messages, then refresh
// the screen. Even if the user chooses not to read the message,
// the screen needs to be re-drawn so it appears properly.
if (continueOn)
{
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
// If we're dispaying in reverse order and the user replied
// to the message, then we'll have to re-arrange the screen
// a bit to make way for the new message that will appear
// in the list.
if (this.reverseListOrder && repliedToMessage)

nightfox
committed
{
// Make way for the new message, which will appear at the
// top.
++this.lightbarListTopMsgIdx;
// If the cursor is below the bottommost line displaying
// messages, then advance the cursor down one position.
// Otherwise, increment this.lightbarListSelectedMsgIdx (since a new message
// will appear at the top, the previous selected message
// will be pushed to the next page).
if (this.lightbarListCurPos.y < console.screen_rows - 1)
{
++originalCurpos.y;
++this.lightbarListCurPos.y;
}
else
++this.lightbarListSelectedMsgIdx;

nightfox
committed
}
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
console.gotoxy(originalCurpos); // Put the cursor back where it should be

nightfox
committed
}
}
}
// PageDown: Next page
else if (userInput == KEY_PAGE_DOWN)
{
// Next page
if (!lastPage)
{
if (this.reverseListOrder)

nightfox
committed
this.lightbarListTopMsgIdx -= this.lightbarMsgListNumLines;
else
this.lightbarListTopMsgIdx += this.lightbarMsgListNumLines;
this.lightbarListSelectedMsgIdx = this.lightbarListTopMsgIdx;
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
// If we were on the last page, then clear the screen from
// the current line to the end of the screen.
if (lastPage)
{
this.lightbarListCurPos = console.getxy();
clearToEOS(this.lightbarListCurPos.y);
// Make sure the help line is still there
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}

nightfox
committed
// Move the cursor back to the first message info line
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
}
else {
// The user is on the last page - Go to the last message on the page.
if (this.lightbarListSelectedMsgIdx != bottomMsgIndex)
{
// Print the current message information with regular colors
this.PrintMessageInfo(msgHeader, false, this.lightbarListSelectedMsgIdx+1);
// Update the selected message #
this.lightbarListSelectedMsgIdx = bottomMsgIndex;
this.lightbarListCurPos.x = 1;
if (this.reverseListOrder)
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow + this.lightbarListTopMsgIdx - bottomMsgIndex;
else
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow + bottomMsgIndex - this.lightbarListTopMsgIdx;
console.gotoxy(this.lightbarListCurPos);
}
}

nightfox
committed
}
// PageUp: Previous page
else if (userInput == KEY_PAGE_UP)
{
var canGoToPrevious = false;
if (this.reverseListOrder)

nightfox
committed
canGoToPrevious = (this.lightbarListTopMsgIdx < this.NumMessages() - 1);
else
canGoToPrevious = (this.lightbarListTopMsgIdx > 0);
if (canGoToPrevious)

nightfox
committed
{
if (this.reverseListOrder)

nightfox
committed
this.lightbarListTopMsgIdx += this.lightbarMsgListNumLines;
else
this.lightbarListTopMsgIdx -= this.lightbarMsgListNumLines;
this.lightbarListSelectedMsgIdx = this.lightbarListTopMsgIdx;
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
}
else
{
// The user is on the first page - Go to the first message on the page.
if (this.lightbarListSelectedMsgIdx != 0)
{
// Print the current message information with regular colors
this.PrintMessageInfo(msgHeader, false, this.lightbarListSelectedMsgIdx+1);
// Go to the first message of the current page
if (this.reverseListOrder)
this.lightbarListSelectedMsgIdx += (this.lightbarListCurPos.y - this.lightbarMsgListStartScreenRow);
else
this.lightbarListSelectedMsgIdx -= (this.lightbarListCurPos.y - this.lightbarMsgListStartScreenRow);
// Move the cursor to the first message line
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
}
}

nightfox
committed
}
// F: First page
else if (userInput == "F")
{
var canGoToFirst = false;
if (this.reverseListOrder)

nightfox
committed
canGoToFirst = (this.lightbarListTopMsgIdx < this.NumMessages() - 1);
else
canGoToFirst = (this.lightbarListTopMsgIdx > 0);
if (canGoToFirst)
{
if (this.reverseListOrder)

nightfox
committed
this.lightbarListTopMsgIdx = this.NumMessages() - 1;
else
this.lightbarListTopMsgIdx = 0;
this.lightbarListSelectedMsgIdx = this.lightbarListTopMsgIdx;
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
}
}
// L: Last page
else if (userInput == "L")
{
if (!lastPage)
{
// Set the top message index. If this.lightbarListTopMsgIdx is beyond the last
// message in the sub-board, then move back a full page of messages.
if (this.reverseListOrder)

nightfox
committed
{
this.lightbarListTopMsgIdx = (this.NumMessages() % this.lightbarMsgListNumLines) - 1;
// If this.lightbarListTopMsgIdx is now invalid (below 0), then adjust it
// to properly display the last page of messages.
if (this.lightbarListTopMsgIdx < 0)
this.lightbarListTopMsgIdx = this.lightbarMsgListNumLines - 1;
}
else
{
var totalNumMessages = this.NumMessages();
this.lightbarListTopMsgIdx = totalNumMessages - (totalNumMessages % this.lightbarMsgListNumLines);
if (this.lightbarListTopMsgIdx >= totalNumMessages)
this.lightbarListTopMsgIdx = totalNumMessages - this.lightbarMsgListNumLines;
}

nightfox
committed
this.lightbarListSelectedMsgIdx = this.lightbarListTopMsgIdx;
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
// If we were on the last page, then clear the screen from
// the current line to the end of the screen.
if (lastPage)
{
this.lightbarListCurPos = console.getxy();
clearToEOS(this.lightbarListCurPos.y);
// Make sure the help line is still there
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}

nightfox
committed
// Move the cursor back to the first message info line
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
this.lightbarListCurPos.x = 1;
this.lightbarListCurPos.y = this.lightbarMsgListStartScreenRow;
}
}
// Numeric digit: The start of a number of a message to read
else if (userInput.match(/[0-9]/))
{
var originalCurpos = console.getxy();

nightfox
committed
// Put the user's input back in the input buffer to
// be used for getting the rest of the message number.
console.ungetstr(userInput);
// Move the cursor to the bottom of the screen and
// prompt the user for the message number.
console.gotoxy(1, console.screen_rows);
userInput = this.PromptForMsgNum({ x: 1, y: console.screen_rows }, this.text.readMsgNumPromptText, true, ERROR_PAUSE_WAIT_MS, false);
if (userInput > 0)
{
// See if the current message header has our "isBogus" property and it's true.
// Only let the user read the message if it's not a bogus message header.
// The message header could have the "isBogus" property, for instance, if
// it's a vote message (introduced in Synchronet 3.17).
//GetMsgHdrByIdx(pMsgIdx, pExpandFields)
var tmpMsgHdr = this.GetMsgHdrByIdx(+(userInput-1), false);
var hdrIsBogus = (tmpMsgHdr.hasOwnProperty("isBogus") ? tmpMsgHdr.isBogus : false);
if (!hdrIsBogus)

nightfox
committed
{
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
// Confirm with the user whether to read the message
var readMsg = true;
if (this.promptToReadMessage)
{
var sReadMsgConfirmText = this.colors["readMsgConfirmColor"]
+ "Read message "
+ this.colors["readMsgConfirmNumberColor"]
+ userInput + this.colors["readMsgConfirmColor"]
+ ": Are you sure";
readMsg = console.yesno(sReadMsgConfirmText);
}
if (readMsg)
{
// Update the message list screen variables
this.CalcMsgListScreenIdxVarsFromMsgNum(+userInput);
retObj.selectedMsgOffset = userInput - 1;
// Return from here so that the calling function can switch
// into reader mode.
return retObj;
}
else
this.deniedReadingMessage = true;
// Prompt the user whether or not to continue listing
// messages.
if (this.promptToContinueListingMessages)
{
continueOn = console.yesno(this.colors["afterReadMsg_ListMorePromptColor"] +
"Continue listing messages");
}

nightfox
committed
}
else
{
writeWithPause(1, console.screen_rows, "\1n\1h\1yThat's not a readable message.",
ERROR_PAUSE_WAIT_MS, "\1n", true);

nightfox
committed
}
}

nightfox
committed
// If the user chose to continue listing messages, then re-draw
// the screen.
if (continueOn)
{
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
console.gotoxy(originalCurpos); // Put the cursor back where it should be
}
}
// DEL key: Delete a message
else if (userInput == KEY_DEL)
{
if (this.CanDelete() || this.CanDeleteLastMsg())
{
var originalCurpos = console.getxy();

nightfox
committed
console.gotoxy(1, console.screen_rows);
console.print("\1n");
console.clearline();
// The PromptAndDeleteMessage() method will prompt the user for confirmation
// to delete the message and then delete it if confirmed.
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
this.PromptAndDeleteMessage(this.lightbarListSelectedMsgIdx, { x: 1, y: console.screen_rows});
// In case all messages were deleted, if that's the case, show
// an appropriate message and don't continue listing messages.
//if (this.NumMessages(true) == 0)
if (!this.NonDeletedMessagesExist())
{
continueOn = false;
// Note: The following doesn't seem to be necessary, since
// the ReadOrListSubBoard() method will show a message saying
// there are no messages to read and then will quit out.
/*
this.msgbase.close();
this.msgbase = null;
console.clear("\1n");
console.center("\1n\1h\1yThere are no messages to display.");
console.crlf();
console.pause();
*/
}
else
{
// There are still some messages to show, so refresh the screen.
// Refresh the screen
console.clear("\1n");
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
console.gotoxy(1, this.lightbarMsgListStartScreenRow);
lastPage = this.ListScreenfulOfMessages(this.lightbarListTopMsgIdx, this.lightbarMsgListNumLines);
console.gotoxy(originalCurpos); // Put the cursor back where it should be
}

nightfox
committed
}
}
// E: Edit a message
else if (userInput == "E")
{
if (this.CanEdit())
{
// See if the current message header has our "isBogus" property and it's true.
// Only let the user edit the message if it's not a bogus message header.
// The message header could have the "isBogus" property, for instance, if
// it's a vote message (introduced in Synchronet 3.17).
var hdrIsBogus = (msgHeader.hasOwnProperty("isBogus") ? msgHeader.isBogus : false);
if (!hdrIsBogus)
{
var originalCurpos = console.getxy();