Newer
Older
Eric Oulashin
committed
// reads/lists messages through the sub-boards, performing the search in each sub-board.
//
// Paramters:
// pSearchModeStr: A string to specify the lister mode to use - This can
// be one of the search modes to specify how to search:
// "keyword_search": Search the message subjects & bodies by keyword
// "from_name_search": Search messages by from name
// "to_name_search": Search messages by to name
// "to_user_search": Search messages by to name, to the logged-in user
// pTxtToSearch: Optional - Text to search for (if specified, this won't prompt the user for search text)
// pSubCode: Optional - An internal code of a sub-board if scanning just one sub-board
function DigDistMsgReader_SearchMsgScan(pSearchModeStr, pTxtToSearch, pSubCode)
Eric Oulashin
committed
{
if (typeof(pSearchModeStr) !== "string" || pSearchModeStr.length == 0)
return;
// If the given sub-board code is valid, then use that and scan only in that
// sub-board. Otherwise, prompt the user for sub-board, group, or all, then
// call SearchMessages to do the search.
var scanScopeChar = "";
var previousSubBoardCode = null;
if (typeof(pSubCode) === "string" && subBoardCodeIsValid(pSubCode))
{
var previousSubBoardCode = this.subBoardCode;
this.subBoardCode = pSubCode;
scanScopeChar = "S";
}
else
{
console.mnemonics(bbs.text(SubGroupOrAll));
scanScopeChar = console.getkeys("SGAC").toString();
}
Eric Oulashin
committed
if (scanScopeChar.length > 0)
this.SearchMessages(pSearchModeStr, null, scanScopeChar, pTxtToSearch, true); // Skip/ignore scan config checks
Eric Oulashin
committed
else
{
console.crlf();

Eric Oulashin
committed
//console.print(replaceAtCodesInStr(this.text.msgScanAbortedText));
//console.crlf();
console.putmsg(this.text.msgScanAbortedText);
Eric Oulashin
committed
console.pause();
}
// Restore this.subBoardCode if necessary
if (typeof(previousSubBoardCode) === "string")
this.subBoardCode = previousSubBoardCode;
Eric Oulashin
committed
}
// This function clears the search data from the object.
function DigDistMsgReader_ClearSearchData()
{
this.searchType = SEARCH_NONE;
this.searchString == "";
if (this.msgSearchHdrs != null)
{
for (var subCode in this.msgSearchHdrs)
{
delete this.msgSearchHdrs[subCode].indexed;
delete this.msgSearchHdrs[subCode];
}
this.msgSearchHdrs = {};
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
}
}
// For the DigDistMsgReader class: Performs message reading/listing.
// Depending on the value of this.startMode, starts in either reader
// mode or lister mode. Uses an input loop to let the user switch
// between the two modes.
//
// 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
// 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)
// pPauseOnNoMsgSrchResults: Optional boolean - Whether or not to pause when
// a message search doesn't find any search results
// in the current sub-board. Defaults to true.
Eric Oulashin
committed
// pPromptToGoNextIfNoResults: Optional boolean - Whether or not to prompt the user
// to go onto the next/previous sub-board if there are no
// search results in the current sub-board. Defaults to true.
Eric Oulashin
committed
// pInitialModeOverride: Optional (numeric) to override the initial mode in this
// function (READER_MODE_READ or READER_MODE_LIST). If not
// specified, defaults to this.startMode.
//
// Return value: An object with the following properties:
// stoppedReading: Boolean - Whether or not the user stopped reading.
// This can also be true if there is an error.
function DigDistMsgReader_ReadOrListSubBoard(pSubBoardCode, pStartingMsgOffset,
pAllowChgArea, pReturnOnNextAreaNav,
Eric Oulashin
committed
pPauseOnNoMsgSrchResults,
Eric Oulashin
committed
pPromptToGoNextIfNoResults,
pInitialModeOverride)
{
var retObj = {
stoppedReading: false
};
// Set the sub-board code if applicable
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 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;
}
// Populate this.msgSearchHdrs for the current sub-board if there is a search
// specified. If there are no messages to read in the current sub-board, then
// just return.
var pauseOnNoSearchResults = (typeof(pPauseOnNoMsgSrchResults) == "boolean" ? pPauseOnNoMsgSrchResults : true);
if (!this.PopulateHdrsIfSearch_DispErrorIfNoMsgs(true, true, pauseOnNoSearchResults))
{
retObj.stoppedReading = false;
return retObj;
}
// If not searching, then populate the array of all readable headers for the
// current sub-board.
if (!this.SearchingAndResultObjsDefinedForCurSub())
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");
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
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));

Eric Oulashin
committed
formattedText = replaceAtCodesAndRemoveCRLFs(formattedText);

Eric Oulashin
committed
console.print("\x01n" + formattedText + "\x01n");
}

Eric Oulashin
committed
var readingMailUserNum = user.is_sysop ? this.personalMailUserNum : user.number;
this.msgSearchHdrs[this.subBoardCode] = searchMsgbase(this.subBoardCode, this.searchType, this.searchString, this.readingPersonalEmailFromUser, null, null, readingMailUserNum);
}
}
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));
console.putmsg(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));

Eric Oulashin
committed
//console.putmsg(formattedText); // Doesn't seem to be word-wrapping
formattedText = replaceAtCodesInStr(formattedText);
formattedText = word_wrap(formattedText, console.screen_columns-1, formattedText.length, false).replace(/\r|\n/g, "\r\n");
console.print(formattedText);
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
}
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.

Eric Oulashin
committed
console.attributes = "N";
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));
//console.crlf();
console.putmsg(this.text.msgScanAbortedText);
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
2473
2474
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);
}
// If doing a newscan of all sub-boards, and the user has their setting for indexed mode
// for newscan enabled, then do that and return instead of the traditional newscan.
if (pScanCfgOpt === SCAN_CFG_NEW && pScanMode === SCAN_NEW && this.userSettings.useIndexedModeForNewscan)
{
var scanScope = SCAN_SCOPE_ALL;
if (scanScopeChar === "S") scanScope = SCAN_SCOPE_SUB_BOARD;
else if (scanScopeChar === "G") scanScope = SCAN_SCOPE_GROUP;
msgReader.DoIndexedMode(scanScope);
return;
}
// 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
this.doingMsgScan = true;
var continueNewScan = true;
var userAborted = false;
this.doingMultiSubBoardScan = (subBoardsToScan.length > 1);

Eric Oulashin
committed
for (var subCodeIdx = 0; (subCodeIdx < subBoardsToScan.length) && continueNewScan && !console.aborted; ++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))
{
// If running a new message scan (not new-to-you or search), output which sub-board that is currently being scanned
if (pScanMode == SCAN_NEW || pScanMode == SCAN_BACK)

Eric Oulashin
committed
{
var statusText = format(this.text.scanningSubBoardText, subBoardGrpAndName(this.subBoardCode));

Eric Oulashin
committed
console.print("\x01n" + replaceAtCodesAndRemoveCRLFs(statusText) + "\x01n");
console.crlf();
console.line_counter = 0; // Prevent pausing for screen output and when displaying a message
}
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;
}
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
}
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();
}
}

Eric Oulashin
committed
// Briefly wait, to prevent the CPU from reaching 99% usage
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();

Eric Oulashin
committed
if (userAborted || console.aborted)

Eric Oulashin
committed
{

Eric Oulashin
committed
console.print("\x01n" + replaceAtCodesInStr(this.text.msgScanAbortedText) + "\x01n");
if (console.aborted)
console.aborted = false; // So that the console.pause() several lines down will indeed pause

Eric Oulashin
committed
}
else

Eric Oulashin
committed
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;
if (msgIndex == -1)
msgIndex = 0;
else if (msgIndex >= numOfMessages)
msgIndex = numOfMessages - 1;
}
// 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;
}
}
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)