From c6272c0b4359676abc47bb7939126a45b061bc8a Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Wed, 18 Mar 2020 07:11:40 +0000
Subject: [PATCH] Address issue raised by Rampage (SESTAR): Newly posted
 replies (by the current user) did not appear in the message list. The message
 list was never re-loaded: I added a Ctrl-R command key to reload the message
 list manually and it's also automatically reloaded when replying via a
 public-posted message (email replies don't force a reload).

The sub-board's last-read pointer is also updated whenever the current msg
selection is moved, even if the message isn't read or previewed. This paves
the way for the internal message reader to possibly track to the current
message selected in the msglist module upon exit.

Included in here is a work-around for the (just-fixed) MsgBase.get_index/
get_all_msg_headers() bug where the msgbase status header was not re-read
before determining the max number of messages to load. That work-around will
be removed eventually.
---
 exec/msglist.js | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/exec/msglist.js b/exec/msglist.js
index 5359e024c6..a0264025d6 100644
--- a/exec/msglist.js
+++ b/exec/msglist.js
@@ -730,7 +730,10 @@ function list_msgs(msgbase, list, current, preview, grp_name, sub_name)
 			console_beep();
 			current = list.length-1;
 		}
-
+		
+		if(msgbase.cfg) // Update "last read" pointer
+			msg_area.sub[msgbase.cfg.code].last_read = list[current].number;
+		
 		if(console.screen_columns >= 80)
 			right_justify(format(options.area_nums_fmt || "[message %u of %u]"
 				, current + 1, list.length));
@@ -973,6 +976,7 @@ function list_msgs(msgbase, list, current, preview, grp_name, sub_name)
 							else {
 								console.clear();
 								bbs.post_msg(msgbase.subnum, list[current]);
+								return true;
 							}
 							break;
 						case 'M':
@@ -1026,6 +1030,8 @@ function list_msgs(msgbase, list, current, preview, grp_name, sub_name)
 			case 'Q':
 				console.clear();
 				return false;
+			case ctrl('R'):				
+				return true;
 			case KEY_HOME:
 				if(msg_ctrl)
 					msg_line = 0;
@@ -1115,6 +1121,7 @@ function list_msgs(msgbase, list, current, preview, grp_name, sub_name)
 				else {
 					console.clear();
 					bbs.post_msg(msgbase.subnum, list[current]);
+					return true; // reload msgs
 				}
 				break;
 			case 'M':
@@ -1237,6 +1244,7 @@ function load_msgs(msgbase, which, mode, usernumber)
 {
 	var mail = (msgbase.attributes & SMB_EMAIL);
 	var list = [];
+	msgbase.last_msg;	// Work around bug in MsgBase.get_index()/get_all_msg_headers() in v3.17c
 	if(mail && which !== undefined && which != MAIL_ALL) {
 		var idxlist = msgbase.get_index();
 		var total_msgs = idxlist.length;
@@ -1381,7 +1389,6 @@ function remove_list_format_property(name)
 	}
 }
 
-var curmsg = 0;
 if(msgbase.cfg) {
 	list_formats = sub_list_formats;
 	if(msgbase.cfg.settings & (SUB_FIDO | SUB_QNET | SUB_INET)) {
@@ -1396,7 +1403,6 @@ if(msgbase.cfg) {
 		remove_list_format_property("score");
 	if(!(msgbase.cfg.settings & SUB_TOUSER))
 		remove_list_format_property("to");
-	curmsg = msg_area.sub[msgbase.cfg.code].last_read;
 } else {
 	if(which === undefined)
 		which = MAIL_YOUR;
@@ -1423,13 +1429,6 @@ if(msgbase.attributes & SMB_EMAIL) {
 if(!usernumber)
 	usernumber = user.number;
 
-console.print("Loading messages \x01i...\x01n ");
-var list = load_msgs(msgbase, which, lm_mode, usernumber);
-if(!list || !list.length) {
-	alert("No messages");
-	exit();
-}
-
 js.on_exit("console.status = " + console.status);
 console.status |= CON_CR_CLREOL;
 js.on_exit("console.ctrlkey_passthru = " + console.ctrlkey_passthru);
@@ -1463,10 +1462,15 @@ if(msgbase.cfg) {
 			break;
 	}
 }
-var result = list_msgs(msgbase, list, curmsg, preview, grp_name, sub_name);
-if(result) {
-	if(msgbase.cfg) {
-		msg_area.sub[msgbase.cfg.code].last_read = result;
-		bbs.scan_msgs(msgbase.cfg.code);
+
+do {
+	console.print("\x01[\x01>Loading messages \x01i...\x01n ");
+	var list = load_msgs(msgbase, which, lm_mode, usernumber);
+	if(!list || !list.length) {
+		alert("No messages");
+		break;
 	}
-}
+	var curmsg = 0;
+	if(msgbase.cfg)
+		curmsg = msg_area.sub[msgbase.cfg.code].last_read;
+} while(list_msgs(msgbase, list, curmsg, preview, grp_name, sub_name) === true);
-- 
GitLab