From 176cc105881f3b3dcd26f98064ac07d00c9f1320 Mon Sep 17 00:00:00 2001
From: nightfox <>
Date: Fri, 13 Jan 2017 03:21:19 +0000
Subject: [PATCH] When viewing vote poll results, it now updates the user's
 last read & scan pointers.  Also, it now determines the initial message index
 to use based on the user's last read pointer.

---
 xtrn/SlyVote/SlyVote.js | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/xtrn/SlyVote/SlyVote.js b/xtrn/SlyVote/SlyVote.js
index 8d05d3354c..b6be71e2cc 100644
--- a/xtrn/SlyVote/SlyVote.js
+++ b/xtrn/SlyVote/SlyVote.js
@@ -59,8 +59,8 @@ load("scrollbar.js");
 load("DDLightbarMenu.js");
 
 // Version information
-var SLYVOTE_VERSION = "0.03 Beta";
-var SLYVOTE_DATE = "2017-01-11";
+var SLYVOTE_VERSION = "0.04 Beta";
+var SLYVOTE_DATE = "2017-01-12";
 
 // Determine the script's startup directory.
 // This code is a trick that was created by Deuce, suggested by Rob Swindell
@@ -1273,13 +1273,22 @@ function ViewVoteResults(pSubBoardCode)
 	var msgbase = new MsgBase(pSubBoardCode);
 	if (msgbase.open())
 	{
-		// Fill an array of message headers for the poll messages
+		// Fill an array of message headers for the poll messages.
+		// Also, determine the index of the message to read based on the
+		// user's last-read pointer.
+		var currentMsgIdx = 0;
+		var pollMsgIdx = 0;
 		var pollMsgHdrs = [];
 		var msgHdrs = msgbase.get_all_msg_headers(true);
 		for (var prop in msgHdrs)
 		{
 			if ((msgHdrs[prop].type & MSG_TYPE_POLL) == MSG_TYPE_POLL)
+			{
 				pollMsgHdrs.push(msgHdrs[prop]);
+				if (msgHdrs[prop].number == msg_area.sub[pSubBoardCode].last_read)
+					currentMsgIdx = pollMsgIdx;
+				++pollMsgIdx;
+			}
 		}
 		delete msgHdrs; // Free some memory
 		
@@ -1321,7 +1330,6 @@ function ViewVoteResults(pSubBoardCode)
 		console.print(keyHelpLine);
 
 		// User input loop
-		var currentMsgIdx = 0;
 		var drawMsg = true;
 		var drawKeyHelpLine = false;
 		var continueOn = true;
@@ -1439,6 +1447,16 @@ function ViewVoteResults(pSubBoardCode)
 			}
 			else if (scrollRetObj.lastKeypress == gReaderKeys.quit)
 				continueOn = false;
+
+			// Update the user's scan pointer and last read message pointer
+			if (pSubBoardCode != "mail") // && !this.SearchTypePopulatesSearchResults()
+			{
+				// What if newest_message_header.number is invalid  (e.g. NaN or 0xffffffff or >
+				// msgbase.last_msg)?
+				if (pollMsgHdrs[currentMsgIdx].number > msg_area.sub[pSubBoardCode].scan_ptr)
+					msg_area.sub[pSubBoardCode].scan_ptr = pollMsgHdrs[currentMsgIdx].number;
+				msg_area.sub[pSubBoardCode].last_read = pollMsgHdrs[currentMsgIdx].number;
+			}
 		}
 
 		msgbase.close();
-- 
GitLab