Newer
Older
this.PopulateHdrsForCurrentSubBoard();
// Check the pAllowChgArea parameter. If it's a boolean, then use it. If
// not, then check to see if we're reading personal mail - If not, then allow
// the user to change to a different message area.
var allowChgMsgArea = true;
if (typeof(pAllowChgArea) == "boolean")
allowChgMsgArea = pAllowChgArea;
else
allowChgMsgArea = (this.subBoardCode != "mail");
// If reading personal email and messages haven't been collected (searched)
// yet, then do so now.
if (this.readingPersonalEmail && (!this.msgSearchHdrs.hasOwnProperty(this.subBoardCode)))
this.msgSearchHdrs[this.subBoardCode] = searchMsgbase(this.subBoardCode, this.searchType, this.searchString, this.readingPersonalEmailFromUser);
// Determine whether to start in list or reader mode, depending
// on the value of this.startMode.
var readerMode = this.startMode;
Eric Oulashin
committed
// If an initial mode override was specified and is valid, then use it.
if (typeof(pInitialModeOverride) === "number" && (pInitialModeOverride == READER_MODE_READ || pInitialModeOverride == READER_MODE_LIST))
readerMode = pInitialModeOverride;
// User input loop
var selectedMessageOffset = 0;
if (typeof(pStartingMsgOffset) == "number")
selectedMessageOffset = pStartingMsgOffset;
else if (this.SearchingAndResultObjsDefinedForCurSub())
{
// If reading personal mail, start at the first unread message index
// (or the last message, if all messages have been read)
if (this.readingPersonalEmail)
{
selectedMessageOffset = this.GetLastReadMsgIdxAndNum(false).lastReadMsgIdx; // Used to be true
if ((selectedMessageOffset > -1) && (selectedMessageOffset < this.NumMessages() - 1))
++selectedMessageOffset;
}
else
selectedMessageOffset = 0;
}
else if (this.hdrsForCurrentSubBoard.length > 0)
{
selectedMessageOffset = this.GetMsgIdx(GetScanPtrOrLastMsgNum(this.subBoardCode));
if (selectedMessageOffset < 0)
selectedMessageOffset = 0;
else if (selectedMessageOffset >= this.hdrsForCurrentSubBoard.length)
selectedMessageOffset = this.hdrsForCurrentSubBoard.length - 1;
}
else
selectedMessageOffset = -1;
var otherRetObj = null;
var continueOn = true;
while (continueOn)
{
switch (readerMode)
{
case READER_MODE_READ:
// Call the ReadMessages method - DOn't change the sub-board,
// and pass the selected index of the message to read. If that
// index is -1, the ReadMessages method will use the user's
// last-read message index.
Eric Oulashin
committed
otherRetObj = this.ReadMessages(null, selectedMessageOffset, true, allowChgMsgArea,
pReturnOnNextAreaNav, pPromptToGoNextIfNoResults);
// If the user wants to quit or if there was an error, then stop
// the input loop.
if (otherRetObj.stoppedReading)
{
retObj.stoppedReading = true;
continueOn = false;
}
// If we're set to return on navigation to the next message area and
// the user's last keypress was the right arrow key or next action
// was to go to the next message area, then don't continue the input
// loop, and also say that the user didn't stop reading.
else if (pReturnOnNextAreaNav &&
((otherRetObj.lastUserInput == KEY_RIGHT) || (otherRetObj.lastUserInput == KEY_ENTER) || (otherRetObj.lastAction == ACTION_GO_NEXT_MSG_AREA)))
{
retObj.stoppedReading = false;
continueOn = false;
}
else if (otherRetObj.messageListReturn)
readerMode = READER_MODE_LIST;
Eric Oulashin
committed
break;
case READER_MODE_LIST:
// Note: Doing the message list is also handled in this.ReadMessages().
// This code is here in case the reader is configured to start up
// in list mode first.
// List messages
otherRetObj = this.ListMessages(null, pAllowChgArea);
// If the user wants to quit, set continueOn to false to get out
// of the loop. Otherwise, set the selected message offset to
// what the user chose from the list.
if (otherRetObj.lastUserInput == "Q")
{
retObj.stoppedReading = true;
continueOn = false;
}
else
{
selectedMessageOffset = otherRetObj.selectedMsgOffset;
readerMode = READER_MODE_READ;
}
break;
default:
break;
}
}
console.clear("\x01n");
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
return retObj;
}
// Helper for DigDistMsgReader_ReadOrListSubBoard(): Populates this.msgSearchHdrs
// if an applicable search type is specified; also, if there are no messages in
// the current sub-board, outputs an error to the user.
//
// Parameters:
// pCloseMsgbaseAndSetNullIfNoMsgs: Optional boolean - Whether or not to close the message
// base if there are no messages. Defaults to true.
// pOutputMessages: Boolean - Whether or not to output messages to the screen.
// Defaults to true.
// pPauseOnNoMsgError: Optional boolean - Whether or not to pause for a keypress
// after displaying the "no messages" error. Defaults to true.
//
// Return value: Boolean - Whether or not there are messages to read in the current
// sub-board
function DigDistMsgReader_PopulateHdrsIfSearch_DispErrorIfNoMsgs(pCloseMsgbaseAndSetNullIfNoMsgs,
pOutputMessages, pPauseOnNoMsgError)
{
var thereAreMessagesToRead = true;
var outputMessages = (typeof(pOutputMessages) == "boolean" ? pOutputMessages : true);
// If a search is is specified that would populate the search results, then
// perform the message search for the current sub-board.
if (this.SearchTypePopulatesSearchResults())
{
if (!this.msgSearchHdrs.hasOwnProperty(this.subBoardCode))
{
// TODO: In case new messages were posted in this sub-board, it might help
// to check the current number of messages vs. the previous number of messages
// and search the new messages if there are more.
if (outputMessages)
{
console.crlf();
Eric Oulashin
committed
var formattedText = "";
if (this.readingPersonalEmail)
Eric Oulashin
committed
formattedText = format(this.text.loadingPersonalMailText, subBoardGrpAndName(this.subBoardCode));
else
Eric Oulashin
committed
formattedText = format(this.text.searchingSubBoardText, subBoardGrpAndName(this.subBoardCode));
console.print("\x01n" + replaceAtCodesInStr(formattedText) + "\x01n");
}
this.msgSearchHdrs[this.subBoardCode] = searchMsgbase(this.subBoardCode, this.searchType, this.searchString, this.readingPersonalEmailFromUser);
}
}
else
{
// There is no search is specified, so clear the search results for the
// current sub-board to help ensure that there are messages to read.
if (this.msgSearchHdrs.hasOwnProperty(this.subBoardCode))
{
delete this.msgSearchHdrs[this.subBoardCode].indexed;
delete this.msgSearchHdrs[this.subBoardCode];
}
}
// If there are no messages to display in the current sub-board, then set the
// return value and let the user know (if outputMessages is true).
if (this.NumMessages() == 0)
{
thereAreMessagesToRead = false;
if (outputMessages)
{
console.print("\x01n");
console.crlf();
if (this.readingPersonalEmail)
Eric Oulashin
committed
console.print(replaceAtCodesInStr(this.text.noPersonalEmailText));
else
{
Eric Oulashin
committed
var formattedText = "";
if (this.msgSearchHdrs.hasOwnProperty(this.subBoardCode))
Eric Oulashin
committed
formattedText = format(this.text.noSearchResultsInSubBoardText, subBoardGrpAndName(this.subBoardCode));
else
Eric Oulashin
committed
formattedText = format(this.text.noMessagesInSubBoardText, subBoardGrpAndName(this.subBoardCode));
console.print(replaceAtCodesInStr(formattedText));
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
}
console.crlf();
var pauseOnNoMsgsError = (typeof(pPauseOnNoMsgError) == "boolean" ? pPauseOnNoMsgError : true);
if (pauseOnNoMsgsError)
console.pause();
}
}
return thereAreMessagesToRead;
}
// For the DigDistMsgReader class: Returns whether the search type is a type
// that would result in the search results structure being populated. Search
// types where that wouldn't happen are SEARCH_NONE (no search) and any of the
// message scan search types.
function DigDistMsgReader_SearchTypePopulatesSearchResults()
{
return (this.readingPersonalEmail || searchTypePopulatesSearchResults(this.searchType));
}
// For the DigDistMsgReader class: Returns whether the search type is a type
// that requires search text. Search types that require search text are the
// keyword search, from name search, and to name search. Search types that
// don't require search text are SEARCH_NONE (no search) & the message scan search
// types.
function DigDistMsgReader_SearchTypeRequiresSearchText()
{
return searchTypeRequiresSearchText(this.searchType);
}
// Returns whether a search type value would populate search results.
//
// Parameters:
// pSearchType: A search type integer value
//
// Return value: Boolean - Whether or not the search type would populate search
// results
function searchTypePopulatesSearchResults(pSearchType)
{
return ((pSearchType == SEARCH_KEYWORD) ||
(pSearchType == SEARCH_FROM_NAME) ||
(pSearchType == SEARCH_TO_NAME_CUR_MSG_AREA) ||
(pSearchType == SEARCH_TO_USER_CUR_MSG_AREA) ||
(pSearchType == SEARCH_TO_USER_NEW_SCAN) ||
(pSearchType == SEARCH_TO_USER_NEW_SCAN_CUR_SUB) ||
(pSearchType == SEARCH_TO_USER_NEW_SCAN_CUR_GRP) ||
(pSearchType == SEARCH_TO_USER_NEW_SCAN_ALL) ||
(pSearchType == SEARCH_ALL_TO_USER_SCAN));
}
// Returns whether a search type value requires search text.
//
// Parameters:
// pSearchType: A search type integer value
//
// Return value: Boolean - Whether or not the search type requires search text
function searchTypeRequiresSearchText(pSearchType)
{
return ((pSearchType == SEARCH_KEYWORD) ||
(pSearchType == SEARCH_FROM_NAME) ||
(pSearchType == SEARCH_TO_NAME_CUR_MSG_AREA));
}
// For the DigDistMsgReader class: Scans the message area(s) for new messages,
// unread messages to the user, or all messages to the user.
//
// Parameters:
// pScanCfgOpt: The scan configuration option to check for in the sub-boards
// (from sbbsdefs.js). Supported values are SCAN_CFG_NEW (new
Eric Oulashin
committed
// message scan), and SCAN_CFG_TOYOU (messages to the user)
// pScanMode: The scan mode (from sbbsdefs.js). Supported values are SCAN_NEW
// (new message scan), SCAN_TOYOU (scan for all messages to the
// user), and SCAN_UNREAD (scan for new messages to the user).
// pScanScopeChar: Optional - A character (as a string) representing the scan
// scope: "S" for sub-board, "G" for group, or "A" for all.
// If this is not specified, the user will be prompted for the
// scan scope.
function DigDistMsgReader_MessageAreaScan(pScanCfgOpt, pScanMode, pScanScopeChar)
{
var scanScopeChar = "";
if ((typeof(pScanScopeChar) == "string") && /^[SGA]$/.test(pScanScopeChar))
scanScopeChar = pScanScopeChar;
else
{
// Prompt the user to scan in the current sub-board, the current message group,
// or all. Default to all.
console.print("\x01n");
Eric Oulashin
committed
console.mnemonics(bbs.text(SubGroupOrAll));
scanScopeChar = console.getkeys("SGAC").toString();
// If the user just pressed Enter without choosing anything, then abort and return.
if (scanScopeChar.length == 0)
{
console.crlf();
Eric Oulashin
committed
console.print(replaceAtCodesInStr(this.text.msgScanAbortedText));
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
console.crlf();
console.pause();
return;
}
}
// Do some logging if verbose logging is enabled
if (gCmdLineArgVals.verboselogging)
{
var logMessage = "Doing a message area scan (";
if (pScanCfgOpt == SCAN_CFG_NEW)
{
// The only valid value for pScanMode in this case is SCAN_NEW, so no
// need to check pScanMode to append more to the log message.
logMessage += "new";
}
else if (pScanCfgOpt == SCAN_CFG_TOYOU)
{
// Valid values for pScanMode in this case are SCAN_UNREAD and SCAN_TOYOU.
if (pScanMode == SCAN_UNREAD)
logMessage += "unread messages to the user";
else if (pScanMode == SCAN_TOYOU)
logMessage += "all messages to the user";
}
if (scanScopeChar == "A") // All sub-boards
logMessage += ", all sub-boards";
else if (scanScopeChar == "G") // Current message group
{
logMessage += ", current message group (" +
msg_area.grp_list[bbs.curgrp].description + ")";
}
else if (scanScopeChar == "S") // Current sub-board
{
logMessage += ", current sub-board (" +
msg_area.grp_list[bbs.curgrp].description + " - " +
msg_area.grp_list[bbs.curgrp].sub_list[bbs.cursub].description + ")";
}
logMessage += ")";
writeToSysAndNodeLog(logMessage);
}
// Save the original search type, sub-board code, searched message headers,
// etc. to be restored later
var originalSearchType = this.searchType;
var originalSubBoardCode = this.subBoardCode;
var originalBBSCurGrp = bbs.curgrp;
var originalBBSCurSub = bbs.cursub;
var originalMsgSrchHdrs = this.msgSearchHdrs;
// Make sure there is no search data
this.ClearSearchData();
// Create an array of internal codes of sub-boards to scan
Eric Oulashin
committed
var subBoardsToScan = getSubBoardsToScanArray(scanScopeChar);
// Scan through the sub-boards
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
this.doingMsgScan = true;
var continueNewScan = true;
var userAborted = false;
this.doingMultiSubBoardScan = (subBoardsToScan.length > 1);
for (var subCodeIdx = 0; (subCodeIdx < subBoardsToScan.length) && continueNewScan; ++subCodeIdx)
{
// Force garbage collection to ensure enough memory is available to continue
js.gc(true);
// Set the console line counter to 0 to prevent screen pausing
// when the "Searching ..." and "No messages were found" text is
// displayed repeatedly
console.line_counter = 0;
// If the sub-board's access requirements allows the user to read it
// and it's enabled in the user's message scan configuration, then go
// ahead with this sub-board.
// Note: Used to use this to determine whether the user could access the
// sub-board:
//user.compare_ars(msg_area.grp_list[grpIndex].sub_list[subIndex].ars)
// Now using the can_read property.
this.setSubBoardCode(subBoardsToScan[subCodeIdx]); // Needs to be set before getting the last read/scan pointer index
if (msg_area.sub[this.subBoardCode].can_read && ((msg_area.sub[this.subBoardCode].scan_cfg & pScanCfgOpt) == pScanCfgOpt))
{
Eric Oulashin
committed
var grpIndex = msg_area.sub[this.subBoardCode].grp_index;
var subIndex = msg_area.sub[this.subBoardCode].index;
// Sub-board description: msg_area.grp_list[grpIndex].sub_list[subIndex].description
// Open the sub-board and check for unread messages. If there are any, then let
// the user read the messages in the sub-board.
//var msgbase = new MsgBasesubBoardsToScan[subCodeIdx]);
var msgbase = new MsgBase(this.subBoardCode);
if (msgbase.open())
{
// Get a filtered list of messages for this sub-board
this.PopulateHdrsForCurrentSubBoard();
//this.setSubBoardCode(subBoardsToScan[subCodeIdx]); // Needs to be set before getting the last read/scan pointer index
// If the current sub-board contains only deleted messages,
// or if the user has already read the last message in this
// sub-board, then skip it.
var scanPtrMsgIdx = this.GetScanPtrMsgIdx();
var nonDeletedMsgsExist = (this.FindNextNonDeletedMsgIdx(scanPtrMsgIdx-1, true) > -1);
var userHasReadLastMessage = false;
if (this.subBoardCode != "mail")
{
// What if newest_message_header.number is invalid (e.g. NaN or 0xffffffff or >
// msgbase.last_msg)?
if (this.hdrsForCurrentSubBoard.length > 0)
{
if ((msg_area.sub[this.subBoardCode].last_read == this.hdrsForCurrentSubBoard[this.hdrsForCurrentSubBoard.length-1].number) ||
(scanPtrMsgIdx == this.hdrsForCurrentSubBoard.length-1))
{
userHasReadLastMessage = true;
}
}
}
if (!nonDeletedMsgsExist || userHasReadLastMessage)
{
if (msgbase != null)
msgbase.close();
continue;
}
// In the switch cases below, bbs.curgrp and bbs.cursub are
// temporarily changed the user's sub-board to the current
// sub-board so that certain @-codes (such as @GRP-L@, etc.)
// are displayed by Synchronet correctly.
// We might want the starting message index to be different
// depending on the scan mode.
switch (pScanMode)
{
case SCAN_NEW:
// Make sure the sub-board has some messages. Let the user read it if
// the scan pointer index is -1 (one unread message) or if it points to
// a message within the number of messages in the sub-board.
var totalNumMsgs = msgbase.total_msgs;
if ((totalNumMsgs > 0) && ((scanPtrMsgIdx == -1) || (scanPtrMsgIdx < totalNumMsgs-1)))
{
bbs.curgrp = grpIndex;
bbs.cursub = subIndex;
// Start at the scan pointer
var startMsgIdx = scanPtrMsgIdx;
// If the message has already been read, then start at the next message
var tmpMsgHdr = this.GetMsgHdrByIdx(startMsgIdx);
if ((tmpMsgHdr != null) && (msg_area.sub[this.subBoardCode].last_read == tmpMsgHdr.number) && (startMsgIdx < this.NumMessages(true) - 1))
++startMsgIdx;
// Allow the user to read messages in this sub-board. Don't allow
// the user to change to a different message area, don't pause
// when there's no search results in a sub-board, and return
// instead of going to the next sub-board via navigation.
var readRetObj = this.ReadOrListSubBoard(null, startMsgIdx, false, true, false);
// If the user stopped reading & decided to quit, then exit the
// message scan loops.
if (readRetObj.stoppedReading)
{
continueNewScan = false;
userAborted = true;
}
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
}
break;
case SCAN_TOYOU: // All messages to the user
bbs.curgrp = grpIndex;
bbs.cursub = subIndex;
// Search for messages to the user in the current sub-board
// and let the user read the sub-board if messages are
// found. Don't allow the user to change to a different
// message area, don't pause when there's no search results
// in a sub-board, and return instead of going to the next
// sub-board via navigation.
this.searchType = SEARCH_TO_USER_CUR_MSG_AREA;
var readRetObj = this.ReadOrListSubBoard(null, 0, false, true, false);
// If the user stopped reading & decided to quit, then exit the
// message scan loops.
if (readRetObj.stoppedReading)
{
continueNewScan = false;
userAborted = true;
}
break;
case SCAN_UNREAD: // New (unread) messages to the user
bbs.curgrp = grpIndex;
bbs.cursub = subIndex;
// Search for messages to the user in the current sub-board
// and let the user read the sub-board if messages are
// found. Don't allow the user to change to a different
// message area, don't pause when there's no search results
// in a sub-board, and return instead of going to the next
// sub-board via navigation.
this.searchType = SEARCH_TO_USER_NEW_SCAN;
var readRetObj = this.ReadOrListSubBoard(null, 0, false, true, false);
// If the user stopped reading & decided to quit, then exit the
// message scan loops.
if (readRetObj.stoppedReading)
{
continueNewScan = false;
userAborted = true;
}
break;
default:
break;
}
if (msgbase != null)
msgbase.close();
}
}
// Pause for a short moment to avoid causing CPU usage going to 99%
mswait(10);
}
this.doingMultiSubBoardScan = false;
// Restore the original sub-board code, searched message headers, etc.
this.searchType = originalSearchType;
this.setSubBoardCode(originalSubBoardCode);
this.msgSearchHdrs = originalMsgSrchHdrs;
bbs.curgrp = originalBBSCurGrp;
bbs.cursub = originalBBSCurSub;
if ((msgbase != null) && msgbase.is_open)
msgbase.close();
this.doingMultiSubBoardScan = false;
this.doingMsgScan = false;
if (this.pauseAfterNewMsgScan)
{
console.crlf();
if (userAborted)
console.print("\x01n" + replaceAtCodesInStr(this.text.msgScanAbortedText) + "\x01n");
else
console.print("\x01n" + replaceAtCodesInStr(this.text.msgScanCompleteText) + "\x01n");
console.crlf();
console.pause();
}
}
// For the DigDistMsgReader class: Performs the message reading activity.
//
// Parameters:
// pSubBoardCode: Optional - The internal code of a sub-board to read.
// If not specified, the internal sub-board code specified
// when creating the object will be used.
// pStartingMsgOffset: Optional - The offset of a message to start at
// pReturnOnMessageList: Optional boolean - Whether or not to quit when the
// user wants to list messages (used when this method
// is called from ReadOrListSubBoard()).
// pAllowChgArea: Optional boolean - Whether or not to allow changing the
// message area
// pReturnOnNextAreaNav: Optional boolean - Whether or not this method should
// return when it would move to the next message area due
// navigation from the user (i.e., with the right arrow
// key or with < (go to previous message area) or > (go
// to next message area))
Eric Oulashin
committed
// pPromptToGoToNextAreaIfNoSearchResults: Optional boolean - Whether or not to
// prompt the user to go to the next/previous sub-board
// when there are no search results
//
// Return value: An object that has the following properties:
// lastUserInput: The user's last keypress/input
// lastAction: The last action chosen by the user based on their
// last keypress, etc.
// stoppedReading: Boolean - Whether reading has stopped
// (due to user quitting, error, or otherwise)
// messageListReturn: Boolean - Whether this method is returning for
// the caller to display the message list. This
// will only be true when the pReturnOnMessageList
// parameter is true and the user wants to list
// messages.
function DigDistMsgReader_ReadMessages(pSubBoardCode, pStartingMsgOffset, pReturnOnMessageList,
Eric Oulashin
committed
pAllowChgArea, pReturnOnNextAreaNav, pPromptToGoToNextAreaIfNoSearchResults)
{
var retObj = {
lastUserInput: "",
lastAction: ACTION_NONE,
stoppedReading: false,
messageListReturn: false
};
// 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();
retObj.stoppedReading = true;
return retObj;
}
}
if (this.subBoardCode.length == 0)
{
console.print("\x01n\x01h\x01yWarning: \x01wThe Message Reader connot continue because no message");
console.crlf();
console.print("sub-board was specified. Please notify the sysop.");
console.crlf();
console.pause();
retObj.stoppedReading = true;
return retObj;
}
// 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();
retObj.stoppedReading = true;
return retObj;
}
}
var msgbase = new MsgBase(this.subBoardCode);
// If the message base was not opened, then output an error and return.
if (!msgbase.open())
{
console.print("\x01n");
console.crlf();
console.print("\x01h\x01y* \x01wUnable to open message sub-board:");
console.crlf();
console.print(subBoardGrpAndName(this.subBoardCode));
console.crlf();
console.pause();
retObj.stoppedReading = true;
return retObj;
}
// If there are no messages to display in the current sub-board, then let the
// user know and exit.
var numOfMessages = this.NumMessages(msgbase);
msgbase.close();
if (numOfMessages == 0)
{
console.clear("\x01n");
console.center("\x01n\x01h\x01yThere are no messages to display.");
console.crlf();
console.pause();
retObj.stoppedReading = true;
return retObj;
}
// Check the pAllowChgArea parameter. If it's a boolean, then use it. If
// not, then check to see if we're reading personal mail - If not, then allow
// the user to change to a different message area.
var allowChgMsgArea = true;
if (typeof(pAllowChgArea) == "boolean")
allowChgMsgArea = pAllowChgArea;
else
allowChgMsgArea = (this.subBoardCode != "mail");
// If reading personal email and messages haven't been collected (searched)
// yet, then do so now.
if (this.readingPersonalEmail && (!this.msgSearchHdrs.hasOwnProperty(this.subBoardCode)))
this.msgSearchHdrs[this.subBoardCode] = searchMsgbase(this.subBoardCode, this.searchType, this.searchString, this.readingPersonalEmailFromUser);
// Determine the index of the message to start at. This will be
// pStartingMsgOffset if pStartingMsgOffset is valid, or the index
// of the user's last-read message in this sub-board.
var msgIndex = 0;
if ((typeof(pStartingMsgOffset) == "number") && (pStartingMsgOffset >= 0) && (pStartingMsgOffset < this.NumMessages()))
msgIndex = pStartingMsgOffset;
else if (this.SearchingAndResultObjsDefinedForCurSub())
msgIndex = 0;
else
{
msgIndex = this.GetLastReadMsgIdxAndNum().lastReadMsgIdx;
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
if (msgIndex == -1)
msgIndex = 0;
}
// If the current message index is for a message that has been
// deleted, then find the next non-deleted message.
var testMsgHdr = this.GetMsgHdrByIdx(msgIndex);
if ((testMsgHdr == null) || ((testMsgHdr.attr & MSG_DELETE) == MSG_DELETE))
{
// First try going forward
var nonDeletedMsgIdx = this.FindNextNonDeletedMsgIdx(msgIndex, true);
// If a non-deleted message was not found, then try going backward.
if (nonDeletedMsgIdx == -1)
nonDeletedMsgIdx = this.FindNextNonDeletedMsgIdx(msgIndex, false);
// If a non-deleted message was found, then set msgIndex to it.
// Otherwise, tell the user there are no messages in this sub-board
// and return.
if (nonDeletedMsgIdx > -1)
msgIndex = nonDeletedMsgIdx;
else
{
console.clear("\x01n");
console.center("\x01h\x01yThere are no messages to display.");
console.crlf();
console.pause();
retObj.stoppedReading = true;
return retObj;
}
}
// Construct the hotkey help line (needs to be done after the message
// base is open so that the delete & edit keys can be added correctly).
this.SetEnhancedReaderHelpLine();
// Get the screen ready for reading messages - First, clear the screen.
console.clear("\x01n");
// Display the help line at the bottom of the screen
if (this.scrollingReaderInterface && console.term_supports(USER_ANSI))
this.DisplayEnhancedMsgReadHelpLine(console.screen_rows, allowChgMsgArea);
// Input loop
var msgHdr = null;
var dateTimeStr = null;
var screenY = 1; // For screen updates requiring more than one line
var continueOn = true;
var readMsgRetObj = null;
// previousNextAction will store the next action from the previous iteration.
// It is useful for some checks, such as when the current message is deleted,
// we'll want to see if the user wanted to go to the previous message/area
// for navigation purposes.
var previousNextAction = ACTION_NONE;
while (continueOn && (msgIndex >= 0) && (msgIndex < this.NumMessages()))
{
// Display the message with the enhanced read method
readMsgRetObj = this.ReadMessageEnhanced(msgIndex, allowChgMsgArea);
retObj.lastUserInput = readMsgRetObj.lastKeypress;
retObj.lastAction = readMsgRetObj.nextAction;
// If we should refresh the enhanced reader help line on the screen (and
// the returned message offset is valid and the user's terminal supports ANSI),
// then refresh the help line.
if (readMsgRetObj.refreshEnhancedRdrHelpLine && readMsgRetObj.offsetValid && console.term_supports(USER_ANSI))
this.DisplayEnhancedMsgReadHelpLine(console.screen_rows, allowChgMsgArea);
// If the returned message offset is invalid, then quit.
if (!readMsgRetObj.offsetValid)
{
continueOn = false;
retObj.stoppedReading = true;
break;
}

nightfox
committed
// If the message is not readable to the user, then go to the
// next/previous message

nightfox
committed
else if (readMsgRetObj.msgNotReadable)
{
// If the user's next action in the last iteration was to go to the
// previous message, then go backwards; otherwise, go forward.
if (previousNextAction == ACTION_GO_PREVIOUS_MSG)

nightfox
committed
msgIndex = this.FindNextNonDeletedMsgIdx(msgIndex, false);
else

nightfox
committed
msgIndex = this.FindNextNonDeletedMsgIdx(msgIndex, true);
continueOn = ((msgIndex >= 0) && (msgIndex < this.NumMessages()));
}
else if (readMsgRetObj.nextAction == ACTION_QUIT) // Quit
{
// Quit
continueOn = false;
retObj.stoppedReading = true;
break;
}
else if (readMsgRetObj.lastKeypress == "R")
{
// Replying to the message is handled in ReadMessageEnhanced().
// The help line at the bottom of the screen needs to be redrawn though,
// for ANSI users.
if (this.scrollingReaderInterface && console.term_supports(USER_ANSI))

nightfox
committed
this.DisplayEnhancedMsgReadHelpLine(console.screen_rows, allowChgMsgArea);
}
else if (readMsgRetObj.nextAction == ACTION_GO_PREVIOUS_MSG) // Go to previous message/area
{
// TODO: There is some opportunity for screen redraw optimization - If
// already at the first readable sub-board, this would redraw the
// screen unnecessarily. Similar for the right arrow key too.
// The newMsgOffset value will be 0 or more if a prior non-deleted
// message was found. If it's -1, then allow going to the previous
// message sub-board/group.
if (readMsgRetObj.newMsgOffset > -1)

nightfox
committed
msgIndex = readMsgRetObj.newMsgOffset;
else
{
// The user is at the beginning of the current sub-board.
if (allowChgMsgArea)
{
Eric Oulashin
committed
if (this.SearchTypePopulatesSearchResults())
console.print("\x01n\r\nLoading messages...");
Eric Oulashin
committed
var goToPrevRetval = this.GoToPrevSubBoardForEnhReader(allowChgMsgArea, pPromptToGoToNextAreaIfNoSearchResults);
retObj.stoppedReading = goToPrevRetval.shouldStopReading;
// If we're going to stop reading, then
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;
}
}
// Go to next message action - This can happen with the right arrow key or
// if the user deletes the message in the ReadMessageEnhanced() method.
else if (readMsgRetObj.nextAction == ACTION_GO_NEXT_MSG)
{
// The newMsgOffset value will be 0 or more if a later non-deleted
// message was found. If it's -1, then allow going to the next
// message sub-board/group.
if (readMsgRetObj.newMsgOffset > -1)

nightfox
committed
msgIndex = readMsgRetObj.newMsgOffset;
else
{
// The user is at the end of the current sub-board.
if (allowChgMsgArea && !pReturnOnNextAreaNav)
{
Eric Oulashin
committed
if (this.SearchTypePopulatesSearchResults())
console.print("\x01n\r\nLoading messages...");
Eric Oulashin
committed
var goToNextRetval = this.GoToNextSubBoardForEnhReader(allowChgMsgArea, pPromptToGoToNextAreaIfNoSearchResults);
retObj.stoppedReading = goToNextRetval.shouldStopReading;
// If we're going to stop reading, then
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;
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
}
}
else if (readMsgRetObj.nextAction == ACTION_GO_FIRST_MSG) // Go to the first message
{
// Go to the first message that's not marked as deleted. This passes -1 as the
// starting message index because FindNextNonDeletedMsgIdx() will increment it
// before searching in order to find the "next" message.
msgIndex = this.FindNextNonDeletedMsgIdx(-1, true);
}
else if (readMsgRetObj.nextAction == ACTION_GO_LAST_MSG) // Go to the last message
{
// Go to the last message that's not marked as deleted
msgIndex = this.FindNextNonDeletedMsgIdx(this.NumMessages(), false);
}
else if (readMsgRetObj.nextAction == ACTION_CHG_MSG_AREA) // Change message area, if allowed
{
if (allowChgMsgArea)
{
// Change message sub-board. If a different sub-board was
// chosen, then change some variables to use the new
// chosen sub-board.
var oldSubBoardCode = this.subBoardCode;
this.SelectMsgArea();
if (this.subBoardCode != oldSubBoardCode)
this.PopulateHdrsForCurrentSubBoard();
var chgSubBoardRetObj = this.EnhancedReaderChangeSubBoard(bbs.cursub_code);
if (chgSubBoardRetObj.succeeded)
{
// Set the message index, etc.
// If there are search results, then set msgIndex to the first
// message. Otherwise (if there is no search specified), then
// set the message index to the user's last read message.
if (this.SearchingAndResultObjsDefinedForCurSub())

nightfox
committed
msgIndex = 0;
else

nightfox
committed
msgIndex = chgSubBoardRetObj.lastReadMsgIdx;
// If the current message index is for a message that has been
// deleted, then find the next non-deleted message.
testMsgHdr = this.GetMsgHdrByIdx(msgIndex);
if ((testMsgHdr == null) || ((testMsgHdr.attr & MSG_DELETE) == MSG_DELETE))
{
// First try going forward
var nonDeletedMsgIdx = this.FindNextNonDeletedMsgIdx(msgIndex, true);
// If a non-deleted message was not found, then try going backward.
if (nonDeletedMsgIdx == -1)

nightfox
committed
nonDeletedMsgIdx = this.FindNextNonDeletedMsgIdx(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.
if (nonDeletedMsgIdx > -1)

nightfox
committed
msgIndex = nonDeletedMsgIdx;
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
{
// If this.reverseListOrder is the string "ASK", the user will be prompted
// on the last line of the screen for whether they want to list the
// messages in reverse order. So, erase the help line on the bottom of
// the screen.
if ((typeof(this.reverseListOrder) == "string") && (this.reverseListOrder.toUpperCase() == "ASK"))
{
if (this.scrollingReaderInterface && console.term_supports(USER_ANSI))
{
console.gotoxy(1, console.screen_rows);
console.cleartoeol("\x01n");
}
}
// 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");