+ /* If the requested page number is -3,
+ * it means "whichever page on which new messages start"
+ * Change that to an actual page number now.
+ */
+ if (BBS->requested_page == (-3)) {
+ if (BBS->num_msgs == 0) {
+ /*
+ * The room is empty; just start at the top and leave it there.
+ */
+ BBS->requested_page = 0;
+ }
+ else if (
+ (BBS->num_msgs > 0)
+ && (BBS->lastseen <= BBS->msgs[0])
+ ) {
+ /*
+ * All messages are new; this is probably the user's first visit to the room,
+ * so start at the last page instead of showing ancient history.
+ */
+ BBS->requested_page = BBS->num_pages - 1;
+ go_to_the_very_end = 1;
+ }
+ else {
+ /*
+ * Some messages are old and some are new. Go to the start of new messages.
+ */
+ for (i=0; i<BBS->num_msgs; ++i) {
+ if (
+ (BBS->msgs[i] > BBS->lastseen)
+ && ( (i == 0) || (BBS->msgs[i-1] <= BBS->lastseen) )
+ ) {
+ BBS->requested_page = (i / Stat->maxmsgs) ;
+ }
+ }
+ }
+ }