Newer
Older

Eric Oulashin
committed
var readableMsgIdx = this.FindNextReadableMsgIdx(msgIndex, true);
// If a non-deleted message was not found, then try going backward.

Eric Oulashin
committed
if (readableMsgIdx == -1)
readableMsgIdx = this.FindNextReadableMsgIdx(msgIndex, false);
// If a non-deleted message was found, then set msgIndex to it.
// Otherwise, return.
// Note: If there are no messages in the chosen sub-board at all,
// then the error would have already been shown.

Eric Oulashin
committed
if (readableMsgIdx > -1)
msgIndex = readableMsgIdx;
else
{
if (this.NumMessages() != 0)
{
// There are messages, but none that are not deleted.
console.clear("\x01n");
console.center("\x01h\x01yThere are no messages to display.");
console.crlf();
console.pause();
}
retObj.stoppedReading = true;
return retObj;
}
}
// Set the hotkey help line again, since the new sub-board might have
// different settings for whether messages can be edited or deleted,
// then refresh it on the screen.
var oldHotkeyHelpLine = this.enhReadHelpLine;
this.SetEnhancedReaderHelpLine();
if ((oldHotkeyHelpLine != this.enhReadHelpLine) && this.scrollingReaderInterface && console.term_supports(USER_ANSI))

nightfox
committed
this.DisplayEnhancedMsgReadHelpLine(console.screen_rows, allowChgMsgArea);
}
else
{
retObj.stoppedReading = false;
return retObj;
}
}
}
else if (readMsgRetObj.nextAction == ACTION_GO_PREV_MSG_AREA) // Go to the previous message area
{
// The user is at the beginning of the current sub-board.
if (allowChgMsgArea)
{
Eric Oulashin
committed
var goToPrevRetval = this.GoToPrevSubBoardForEnhReader(allowChgMsgArea, pPromptToGoToNextAreaIfNoSearchResults);
retObj.stoppedReading = goToPrevRetval.shouldStopReading;
if (retObj.stoppedReading)
msgIndex = 0;
else if (goToPrevRetval.changedMsgArea)

nightfox
committed
msgIndex = goToPrevRetval.msgIndex;
}
// If the caller wants this method to return instead of going to the next
// sub-board with messages, then do so.
if (pReturnOnNextAreaNav)

nightfox
committed
return retObj;
}
else if (readMsgRetObj.nextAction == ACTION_GO_NEXT_MSG_AREA) // Go to the next message area
{
if (allowChgMsgArea && !pReturnOnNextAreaNav)
{
Eric Oulashin
committed
var goToNextRetval = this.GoToNextSubBoardForEnhReader(allowChgMsgArea, pPromptToGoToNextAreaIfNoSearchResults);
retObj.stoppedReading = goToNextRetval.shouldStopReading;
if (retObj.stoppedReading)
msgIndex = 0;
else if (goToNextRetval.changedMsgArea)

nightfox
committed
msgIndex = goToNextRetval.msgIndex;
}
// If the caller wants this method to return instead of going to the next
// sub-board with messages, then do so.
if (pReturnOnNextAreaNav)

nightfox
committed
return retObj;
}
else if (readMsgRetObj.nextAction == ACTION_DISPLAY_MSG_LIST) // Display message list
{
// If we need to return to the caller for this, then do so.
if (pReturnOnMessageList)
{
retObj.messageListReturn = true;
return retObj;
}
else
{
// List messages
var listRetObj = this.ListMessages(null, pAllowChgArea);
// If the user wants to quit, then stop the input loop.
if (listRetObj.lastUserInput == "Q")
{
continueOn = false;
retObj.stoppedReading = true;
}
// If the user chose a different message, then set the message index
else if ((listRetObj.selectedMsgOffset > -1) && (listRetObj.selectedMsgOffset < this.NumMessages()))

nightfox
committed
msgIndex = listRetObj.selectedMsgOffset;
}
}
// Go to specific message & new message offset is valid: Read the new
// message
else if ((readMsgRetObj.nextAction == ACTION_GO_SPECIFIC_MSG) && (readMsgRetObj.newMsgOffset > -1))
msgIndex = readMsgRetObj.newMsgOffset;
// Save this iteration's next action for the "previous" next action for the next iteration
previousNextAction = readMsgRetObj.nextAction;
}
return retObj;
}
// For the DigDistMsgReader class: Performs the message listing, given a
// sub-board code.
//
// Paramters:
// pSubBoardCode: Optional - The internal sub-board code, or "mail"
// for personal email.

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(pSubBoardCode, pAllowChgSubBoard)
{
var retObj = {
lastUserInput: "",
selectedMsgOffset: -1
};
// If the passed-in sub-board code was different than what was set in the object before,
// then open the new message sub-board.
var previousSubBoardCode = this.subBoardCode;
if (typeof(pSubBoardCode) == "string")
{
if (subBoardCodeIsValid(pSubBoardCode))
this.setSubBoardCode(pSubBoardCode);
else
{
console.print("\x01n\x01h\x01yWarning: \x01wThe Message Reader connot continue because an invalid");
console.crlf();
console.print("sub-board code was specified (" + pSubBoardCode + "). Please notify the sysop.");
console.crlf();
console.pause();
return retObj;
}
}
if (this.subBoardCode.length == 0)
{
console.print("\x01n\x01h\x01yWarning: \x01wThe Message Reader connot continue because no message\r\n");
console.print("sub-board was specified. Please notify the sysop.\r\n\x01p");
// If the user doesn't have permission to read the current sub-board, then
// don't allow the user to read it.
if (this.subBoardCode != "mail")
{
if (!msg_area.sub[this.subBoardCode].can_read)
{
var errorMsg = format(bbs.text(CantReadSub), msg_area.sub[this.subBoardCode].grp_name, msg_area.sub[this.subBoardCode].name);
console.print("\x01n" + errorMsg);
console.pause();
return retObj;
}
}
// If there are no messages to display in the current sub-board, then let the
// user know and exit.
if (this.NumMessages() == 0)
{
console.clear("\x01n");
console.center("\x01n\x01h\x01yThere are no messages to display.\r\n\x01p");
return retObj;
// Construct the traditional UI pause text and the line of help text for lightbar
// mode. This adds the delete and edit keys if the user is allowed to delete & edit
// messages.
this.SetMsgListPauseTextAndLightbarHelpLine();
// 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.
//
// 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)
{
var retObj = {
lastUserInput: "",
selectedMsgOffset: -1
};
// If the user doesn't have permission to read the current sub-board, then
// don't allow the user to read it.
if (this.subBoardCode != "mail")
{
if (!msg_area.sub[this.subBoardCode].can_read)
{
var errorMsg = format(bbs.text(CantReadSub), msg_area.sub[this.subBoardCode].grp_name, msg_area.sub[this.subBoardCode].name);
console.print("\x01n" + errorMsg);
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;
var msgbase = new MsgBase(this.subBoardCode);
if (!msgbase.open())
{
console.center("\x01n\x01h\x01yError: \x01wUnable to open the sub-board.\r\n\x01p");

nightfox
committed
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;
this.RecalcMsgListWidthsAndFormatStrs();
// Clear the screen and write the header at the top
console.clear("\x01n");

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).

Eric Oulashin
committed
if (this.userSettings.listMessagesInReverse)
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")
{

Eric Oulashin
committed
if (this.userSettings.listMessagesInReverse)

nightfox
committed
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
{
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")
{

Eric Oulashin
committed
if (this.userSettings.listMessagesInReverse)

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

Eric Oulashin
committed
if (this.userSettings.listMessagesInReverse)

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

Eric Oulashin
committed
if (this.userSettings.listMessagesInReverse)

nightfox
committed
{
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

Eric Oulashin
committed
else if (retvalObj.userInput == "D" || retvalObj.userInput == this.msgListKeys.deleteMessage || retvalObj.userInput == '\x7f' || retvalObj.userInput == '\x08')

nightfox
committed
{

Eric Oulashin
committed
if (retvalObj.userInput == '\x08')
console.crlf();

nightfox
committed
if (this.CanDelete() || this.CanDeleteLastMsg())
{
Eric Oulashin
committed
var msgNum = this.PromptForMsgNum({ x: curpos.x, y: curpos.y+1 }, replaceAtCodesInStr(this.text.deleteMsgNumPromptText), false, ERROR_PAUSE_WAIT_MS, false);

nightfox
committed
// 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.PromptAndDeleteOrUndeleteMessage(msgNum-1, null, true);

nightfox
committed
// Refresh the top header on the screen for continuing to list
// messages.
console.clear("\x01n");

nightfox
committed
this.WriteMsgListScreenTopHeader();
}
}
// E: Edit a message

Eric Oulashin
committed
else if (retvalObj.userInput == this.msgListKeys.editMsg) // "E"

nightfox
committed
{
if (this.CanEdit())
{
Eric Oulashin
committed
var msgNum = this.PromptForMsgNum({ x: curpos.x, y: curpos.y+1 }, replaceAtCodesInStr(this.text.editMsgNumPromptText), false, ERROR_PAUSE_WAIT_MS, false);

nightfox
committed
// 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);

Eric Oulashin
committed
if (tmpMsgHdr != null)
var returnObj = this.EditExistingMsg(msgNum-1);
else
{
console.print("\x01n\r\n\x01h\x01yThat message isn't editable.\x01n");
console.crlf();
console.pause();
}
}

nightfox
committed
// Refresh the top header on the screen for continuing to list
// messages.
console.clear("\x01n");

nightfox
committed
this.WriteMsgListScreenTopHeader();
}
}
// G: Go to a specific message by # (place that message on the top)
else if (retvalObj.userInput == this.msgListKeys.goToMsg)

nightfox
committed
{
var msgNum = this.PromptForMsgNum(curpos, "\x01n" + replaceAtCodesInStr(this.text.goToMsgNumPromptText), false, ERROR_PAUSE_WAIT_MS, false);

nightfox
committed
if (msgNum > 0)
this.tradListTopMsgIdx = msgNum - 1;

nightfox
committed
// Refresh the top header on the screen for continuing to list
// messages.
console.clear("\x01n");

nightfox
committed
this.WriteMsgListScreenTopHeader();
}
// ?: Display help
else if (retvalObj.userInput == "?")
{
console.clear("\x01n");
this.DisplayMsgListHelp(!this.readingPersonalEmail && allowChgSubBoard, true);
console.clear("\x01n");

nightfox
committed
this.WriteMsgListScreenTopHeader();
}
// C: Change to another message area (sub-board)

Eric Oulashin
committed
else if (retvalObj.userInput == this.msgListKeys.chgMsgArea) // "C"

nightfox
committed
{
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("\x01n");

nightfox
committed
this.WriteMsgListScreenTopHeader();
}
}
}
// S: Select message(s)
else if (retvalObj.userInput == "S")
{
// Input the message number list from the user
console.print("\x01n\x01cNumber(s) of message(s) to select, (\x01hA\x01n\x01c=All, \x01hN\x01n\x01c=None, \x01hENTER\x01n\x01c=cancel)\x01g\x01h: \x01c");
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
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("\x01n");
this.WriteMsgListScreenTopHeader();
}
// Ctrl-D: Batch delete (for selected messages)

Eric Oulashin
committed
else if (retvalObj.userInput == this.msgListKeys.batchDelete) // CTRL_D
{
console.attributes = "N";
console.crlf();
if (this.NumSelectedMessages() > 0)
{
// The PromptAndDeleteOrUndeleteSelectedMessages() method will prompt the user for confirmation
// to delete the message and then delete it if confirmed.
this.PromptAndDeleteOrUndeleteSelectedMessages(null, true);
// In case all messages were deleted, if the user can't view deleted messages,
// show an appropriate message and don't continue listing messages.
//if (this.NumMessages(true) == 0)
if (!this.NonDeletedMessagesExist() && !canViewDeletedMsgs())
{
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.
//msgbase.close();
//msgbase = null;
//console.clear("\x01n");
//console.center("\x01n\x01h\x01yThere 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("\x01n");
this.WriteMsgListScreenTopHeader();
}
}
else
{
// There are no selected messages
console.print("\x01n\x01h\x01yThere are no selected messages.");
mswait(ERROR_PAUSE_WAIT_MS);
// Refresh the top header on the screen for continuing to list messages.
console.clear("\x01n");
this.WriteMsgListScreenTopHeader();
}
}

Eric Oulashin
committed
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
// User settings
else if (retvalObj.userInput == this.msgListKeys.userSettings)
{
/*
var continueOn = true;
var retvalObj = null;
var curpos = null; // Current character position
var lastScreen = false;
this.RecalcMsgListWidthsAndFormatStrs();
if (this.tradListTopMsgIdx == -1)
this.SetUpTraditionalMsgListVars();
this.WriteMsgListScreenTopHeader();
*/
var userSettingsRetObj = this.DoUserSettings_Traditional();
retvalObj.userInput = "";
//drawMenu = userSettingsRetObj.needWholeScreenRefresh;
// In case the user changed their twitlist, re-filter the messages for this sub-board
if (userSettingsRetObj.userTwitListChanged)
{
console.gotoxy(1, console.screen_rows);
console.crlf();
console.print("\x01nTwitlist changed; re-filtering..");
var tmpMsgbase = new MsgBase(this.subBoardCode);
if (tmpMsgbase.open())
{
var tmpAllMsgHdrs = tmpMsgbase.get_all_msg_headers(true);
tmpMsgbase.close();
this.FilterMsgHdrsIntoHdrsForCurrentSubBoard(tmpAllMsgHdrs, true);
}
else
console.print("\x01y\x01hFailed to open the messagbase!\x01\r\n\x01p");
this.RecalcMsgListWidthsAndFormatStrs();
if (this.tradListTopMsgIdx == -1)
this.SetUpTraditionalMsgListVars();
// If there are still messages in this sub-board, and the message offset is beyond the last
// message, then adjust the top message index as necessary.
if (this.hdrsForCurrentSubBoard.length > 0)
{
if (this.tradListTopMsgIdx > this.hdrsForCurrentSubBoard.length)
this.tradListTopMsgIdx = this.hdrsForCurrentSubBoard.length - this.tradMsgListNumLines;
}
else
{
continueOn = false;
retObj.selectedMsgOffset = -1;
}
}
if (userSettingsRetObj.needWholeScreenRefresh)
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;
}
}
}
msgbase.close();

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.
//
// 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)
{
var retObj = {
lastUserInput: "",
selectedMsgOffset: -1
};
// If the user doesn't have permission to read the current sub-board, then
// don't allow the user to read it.
if (this.subBoardCode != "mail")
{
if (!msg_area.sub[this.subBoardCode].can_read)
{
var errorMsg = format(bbs.text(CantReadSub), msg_area.sub[this.subBoardCode].grp_name, msg_area.sub[this.subBoardCode].name);
console.print("\x01n" + errorMsg);
console.pause();
return retObj;
}
}
// 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\x01h\x01ySorry, an ANSI terminal is required for this operation.\x01n\x01w\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;
this.RecalcMsgListWidthsAndFormatStrs();

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);

Eric Oulashin
committed
// Mouse: console.print replaced with console.putmsg for mouse click hotspots
Eric Oulashin
committed
//console.print(pHelpLineText);
console.putmsg(pHelpLineText); // console.putmsg() can process @-codes, which we use for mouse click tracking
console.cleartoeol("\x01n");

nightfox
committed
}

nightfox
committed
// Clear the screen and write the header at the top
console.clear("\x01n");

nightfox
committed
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();
}
// Create a DDLightbarMenu for the message list and list messages
// and let the user choose one
var msgListMenu = this.CreateLightbarMsgListMenu();
// numMessages & numMessagesPerPage are used with msgListMenu.CalcPageForItemAndSetTopItemIdx() when
// going to a specific message. They're optional, but it can be faster to get them just once instead of
// every time.
var numMessages = msgListMenu.NumItems();
var numMessagesPerPage = msgListMenu.GetNumItemsPerPage();

nightfox
committed
var msgHeader = null;
var drawMenu = true;

nightfox
committed
var continueOn = true;
while (continueOn)
{
var userChoice = msgListMenu.GetVal(drawMenu);
drawMenu = true;
var lastUserInputUpper = (typeof(msgListMenu.lastUserInput) == "string" ? msgListMenu.lastUserInput.toUpperCase() : msgListMenu.lastUserInput);
// If the user's last input is null, then something bad/weird must have
// happened, so don't continue the input loop.
if (lastUserInputUpper == null)
{
continueOn = false;
break;
}
this.lightbarListSelectedMsgIdx = msgListMenu.selectedItemIdx;
// If userChoice is a number, then it will be a message number for a message to read
if (typeof(userChoice) == "number")

nightfox
committed
{
// The user choice a message to read
this.lightbarListSelectedMsgIdx = msgListMenu.selectedItemIdx;
msgHeader = this.GetMsgHdrByIdx(this.lightbarListSelectedMsgIdx, this.showScoresInMsgList);

Eric Oulashin
committed
// TODO: Is this commented-out code necessary? In indexed newscan mode, when reading a
// message, then switching to the list, then selecting a message to read, this is re-printing
// the message info line from the message list and it's appearing over the help line at the
// bottom of the screen.
//if (msgHeader != null)
// this.PrintMessageInfo(msgHeader, true, this.lightbarListSelectedMsgIdx+1);
console.gotoxy(this.lightbarListCurPos); // Make sure the cursor is still in the right place

Eric Oulashin
committed
if (msgHeader != null)

nightfox
committed
{
// 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.attributes = "N";
console.clearline();
readMsg = console.yesno(sReadMsgConfirmText);
}
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)
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)
{
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}
}

nightfox
committed
}
// If userChoice is not a number, then it should be null in this case,
// and the user would have pressed one of the additional quit keys set
// up for the menu. So look at the menu's lastUserInput and do the
// appropriate thing.
else if ((lastUserInputUpper == this.msgListKeys.quit) || (lastUserInputUpper == KEY_ESC)) // Quit

nightfox
committed
{
continueOn = false;
retObj.lastUserInput = "Q"; // So the reader will quit out

nightfox
committed
}
// Numeric digit: The start of a number of a message to read
else if (lastUserInputUpper.match(/[0-9]/))

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(lastUserInputUpper);

nightfox
committed
// Move the cursor to the bottom of the screen and
// prompt the user for the message number.
console.gotoxy(1, console.screen_rows);
Eric Oulashin
committed
var userInput = this.PromptForMsgNum({ x: 1, y: console.screen_rows }, replaceAtCodesInStr(this.text.readMsgNumPromptText), true, ERROR_PAUSE_WAIT_MS, false);

nightfox
committed
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);

Eric Oulashin
committed
if (tmpMsgHdr != null)

nightfox
committed
{
// 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, "\x01n\x01h\x01yThat's not a readable message.", ERROR_PAUSE_WAIT_MS, "\x01n", true);

nightfox
committed
}

nightfox
committed
// If the user chose to continue listing messages, then re-draw
// the screen.
if (continueOn)
{
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}
}
// DEL key: Delete a message

Eric Oulashin
committed
else if (lastUserInputUpper == this.msgListKeys.deleteMessage || lastUserInputUpper == '\x7f' || lastUserInputUpper == '\x08')

nightfox
committed
{
if (this.CanDelete() || this.CanDeleteLastMsg())
{
console.gotoxy(1, console.screen_rows);
console.attributes = "N";

nightfox
committed
console.clearline();
// The PromptAndDeleteOrUndeleteMessage() method will prompt the user for confirmation
// to delete the message and then delete it if confirmed.
this.PromptAndDeleteOrUndeleteMessage(this.lightbarListSelectedMsgIdx, { x: 1, y: console.screen_rows}, true);
// In case all messages were deleted, if the user can't view deleted messages,
// show an appropriate message and don't continue listing messages.
//if (this.NumMessages(true) == 0)
if (!this.NonDeletedMessagesExist() && !canViewDeletedMsgs())
continueOn = false;
else
{
// There are still some messages to show, so refresh the screen.
// Refresh the header & help line.
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}

nightfox
committed
}
}
// E: Edit a message
else if (lastUserInputUpper == this.msgListKeys.editMsg)

nightfox
committed
{
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 tmpMsgHdr = this.GetMsgHdrByIdx(this.lightbarListSelectedMsgIdx, false);

Eric Oulashin
committed
if (tmpMsgHdr != null)
{
// Ask the user if they really want to edit the message
console.gotoxy(1, console.screen_rows);
console.attributes = "N";
console.clearline();
// Let the user edit the message
//var returnObj = this.EditExistingMsg(tmpMsgHdr.offset);
var returnObj = this.EditExistingMsg(this.lightbarListSelectedMsgIdx);
// Refresh the header & help line
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}

nightfox
committed
}
else
drawMenu = false; // No need to re-draw the menu

nightfox
committed
}
// G: Go to a specific message by # (highlight or place that message on the top, or in the page if can't put it on top)
else if (lastUserInputUpper == this.msgListKeys.goToMsg)

nightfox
committed
{
// Move the cursor to the bottom of the screen and
// prompt the user for a message number.
console.gotoxy(1, console.screen_rows);
Eric Oulashin
committed
var userMsgNum = this.PromptForMsgNum({ x: 1, y: console.screen_rows }, "\n" + replaceAtCodesInStr(this.text.goToMsgNumPromptText), true, ERROR_PAUSE_WAIT_MS, false);
if (userMsgNum > 0)

nightfox
committed
{
// Make sure the message number is for a valid message (i.e., it
// could be an invalid message number if there is a search, where
// not all message numbers are consecutive).
if (this.GetMsgHdrByMsgNum(userMsgNum) != null)
{
// If the message is on the current page, then just go to and
// highlight it. Otherwise, set the user's selected message on the
// top of the page. We also have to make sure that this.lightbarListCurPos.y and
// originalCurpos.y are set correctly. Also, account for search
// results if there are any (we'll need to have the correct array
// index for the search results).
var chosenMsgIndex = userMsgNum - 1;

Eric Oulashin
committed
msgListMenu.selectedItemIdx = chosenMsgIndex;
if ((chosenMsgIndex < msgListMenu.NumItems()) && (chosenMsgIndex >= this.lightbarListTopMsgIdx))
{
this.lightbarListSelectedMsgIdx = chosenMsgIndex;
msgListMenu.selectedItemIdx = this.lightbarListSelectedMsgIdx;
msgListMenu.CalcPageForItemAndSetTopItemIdx(numMessagesPerPage, numMessages);
}
else
{
this.lightbarListTopMsgIdx = this.lightbarListSelectedMsgIdx = chosenMsgIndex;
msgListMenu.topItemIdx = this.lightbarListTopMsgIdx;
}
}
else
{
// The user entered an invalid message number
console.print("\x01n" + replaceAtCodesInStr(format(this.text.invalidMsgNumText, userMsgNum)) + "\x01n");
console.inkey(K_NONE, ERROR_PAUSE_WAIT_MS);
}

nightfox
committed
}
// Refresh the header & help lines

nightfox
committed
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}
// C: Change to another message area (sub-board)
else if (lastUserInputUpper == this.msgListKeys.chgMsgArea)

nightfox
committed
{
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;
if (chgSubRetval.succeeded)
{
console.attributes = "N";
console.gotoxy(1, console.screen_rows);
console.cleartoeol("\x01n");
console.gotoxy(1, console.screen_rows);
console.print("Loading...");
this.PopulateHdrsForCurrentSubBoard();
this.SetUpLightbarMsgListVars();
}

nightfox
committed
}
// Update the lightbar list variables and refresh the header & help lines

nightfox
committed
if (continueOn)
{
console.clear("\x01n");
// Adjust the menu indexes to ensure they're correct for the current sub-board
this.AdjustLightbarMsgListMenuIdxes(msgListMenu);

nightfox
committed
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);
}
}
else
drawMenu = false; // No need to re-draw the menu
}
else if (lastUserInputUpper == this.msgListKeys.showHelp) // Show help
{
console.clear("\x01n");
this.DisplayMsgListHelp(!this.readingPersonalEmail && allowChgSubBoard, true);
// Re-draw the message list header & help line before
// the menu is re-drawn
this.WriteMsgListScreenTopHeader();
DisplayHelpLine(this.msgListLightbarModeHelpLine);

nightfox
committed
}
// Spacebar: Select a message for batch operations (such as batch
// delete, etc.)
else if (lastUserInputUpper == " ")
{
this.ToggleSelectedMessage(this.subBoardCode, this.lightbarListSelectedMsgIdx);
// Have the menu draw only the check character column in the
// next iteration
msgListMenu.nextDrawOnlyItemSubstr = { start: this.MSGNUM_LEN, end: this.MSGNUM_LEN+1 };
}
// Ctrl-A: Select/de-select all messages
else if (lastUserInputUpper == CTRL_A)
{
console.gotoxy(1, console.screen_rows);
console.attributes = "N";
console.clearline();
console.gotoxy(1, console.screen_rows);
// Prompt the user to select All, None (un-select all), or Cancel
console.print("\x01n\x01gSelect \x01c(\x01hA\x01n\x01c)\x01gll, \x01c(\x01hN\x01n\x01c)\x01gone, or \x01c(\x01hC\x01n\x01c)\x01gancel: \x01h\x01g");