diff --git a/load/frame-page.js b/load/frame-page.js index 7f8145a..138167c 100644 --- a/load/frame-page.js +++ b/load/frame-page.js @@ -239,24 +239,26 @@ PageFrame.prototype.loadMessage = function(page) { var newmsgs = area.newMsgsToMe(); log(LOG_DEBUG,'User has: '+newmsgs.length+' msgs to read to ME'); if (newmsgs.length) { - var next = newmsgs.shift(); + var next = newmsgs[0]; - log(LOG_DEBUG,'NEXT is: '+next.tag+' , this is: '+msg.tag); - - if (next.tag === msg.tag) + //log(LOG_DEBUG,'- NEXT is: '+next.tags+', this is: '+msg.tags); + if (next.tags === msg.tags) { + log(LOG_DEBUG,'- Updating scan_ptr to: '+next.number); stats.scan_ptr = next.number; + } } // if this message is the next message, update last_read var newmsgs = area.newMsgs(); log(LOG_DEBUG,'User has: '+newmsgs.length+' msgs to read'); if (newmsgs.length) { - var next = newmsgs.shift(); + var next = newmsgs[0]; - log(LOG_DEBUG,'NEXT is: '+next.tag+' , this is: '+msg.tag); - - if (next.tag === msg.tag) + //log(LOG_DEBUG,'- NEXT is: '+next.tags+', this is: '+msg.tags); + if (next.tags === msg.tags) { + log(LOG_DEBUG,'- Updating last_read to: '+next.number); stats.last_read = next.number; + } } log(LOG_DEBUG,'Built frame: ['+this.frame+']['+this.index+'] ('+this.page+')'); diff --git a/load/funcs.js b/load/funcs.js index 0432a6c..ec2db0e 100644 --- a/load/funcs.js +++ b/load/funcs.js @@ -134,16 +134,16 @@ function atcode(field,length,pad,context) { break; // Oldest message in msgarea + // Our oldest message, is the first message with a tag from the headers case 'msg_area_msgoldest_date': if (typeof context !== 'object') { log(LOG_ERROR,'Unable to render ['+field+'], no context provided'); break; } - // @todo Cant use context.msgbase.first_msg - it is always zero? - var x = Object.keys(context.headers)[0]; + var x = context.list_tagged[0]; - result = x ? context.headers[x].date : ''; + result = x ? x.date : ''; break; case 'msg_area_msgoldest_page': @@ -152,19 +152,21 @@ function atcode(field,length,pad,context) { break; } - // @todo Cant use context.msgbase.first_msg - it is always zero? - var x = Object.keys(context.headers)[0]; + var x = context.list_tagged[0]; - return x ? context.getMessagePage(context.headers[x].number) : null; + return x ? context.getMessagePage(x.number) : null; // Newest message in msgarea + // Our newest message, is the last message with a tag from the headers case 'msg_area_msgnewest_date': if (typeof context !== 'object') { log(LOG_ERROR,'Unable to render ['+field+'], no context provided'); break; } - result = context.headers[context.msgbase.last_msg] ? context.headers[context.msgbase.last_msg].date : ''; + var x = context.list_tagged[context.list_tagged.length-1]; + + result = x ? x.date : ''; break; case 'msg_area_msgnewest_page': @@ -173,7 +175,9 @@ function atcode(field,length,pad,context) { break; } - return context.msgbase.last_msg ? context.getMessagePage(context.headers[context.msgbase.last_msg].number) : null; + var x = context.list_tagged[context.list_tagged.length-1]; + + return x ? context.getMessagePage(x.number) : null; // First unread message case 'msg_area_msgunread_date': diff --git a/load/msgbases.js b/load/msgbases.js index a060831..21bfeb4 100644 --- a/load/msgbases.js +++ b/load/msgbases.js @@ -54,6 +54,9 @@ function MsgArea() { this.grp_number = undefined; this.subnum = undefined; + /** + * Build a MsgArea once we are given the code + */ Object.defineProperty(this,'code',{ set: function(code) { this.msgbase = new MsgBase(code); @@ -64,6 +67,8 @@ function MsgArea() { } this.headers = this.msgbase.get_all_msg_headers(false,false) || []; + // @todo If there are more than 10,000, take only the last 10,000. + this.msgbase.close(); } }); @@ -75,13 +80,6 @@ function MsgArea() { } }); - // Total Messages - Object.defineProperty(this,'list',{ - get: function() { - return this.headers ? Object.keys(this.headers) : []; - } - }); - // Total tagged messages Object.defineProperty(this,'list_tagged',{ get: function() { @@ -167,14 +165,14 @@ function MsgArea() { MsgArea.prototype.newMsgs = function() { var msgs = []; var stats = this.getUserStats(); - //log(LOG_DEBUG,'Users scan pointer: '+JSON.stringify(stats.scan_ptr)); + //log(LOG_DEBUG,'Users last_read pointer: '+JSON.stringify(stats.last_read)); - for(var x in this.headers) { + for(var x in this.list_tagged) { // Advance past our last scan_ptr - if (x <= stats.last_read) + if (this.list_tagged[x].number <= stats.last_read) continue; - msgs.push(this.headers[x]); + msgs.push(this.list_tagged[x]); write(); // @todo This is needed for this to work? } @@ -188,15 +186,15 @@ MsgArea.prototype.newMsgs = function() { MsgArea.prototype.newMsgsToMe = function() { var msgs = []; var stats = this.getUserStats(); - //log(LOG_DEBUG,'Users scan pointer: '+JSON.stringify(stats.scan_ptr)); + //log(LOG_DEBUG,'Users scan_ptr pointer: '+JSON.stringify(stats.scan_ptr)); - for(var x in this.headers) { + for(var x in this.list_tagged) { // Advance past our last scan_ptr - if (x <= stats.scan_ptr) + if (this.list_tagged[x].number <= stats.scan_ptr) continue; - if ((this.headers[x].to === user.name) || (this.headers[x].to === user.alias)) - msgs.push(this.headers[x]); + if ((this.list_tagged[x].to === user.name) || (this.list_tagged[x].to === user.alias)) + msgs.push(this.list_tagged[x]); write(); // @todo This is needed for this to work? } @@ -210,9 +208,9 @@ MsgArea.prototype.newMsgsToMe = function() { MsgArea.prototype.getMessage = function(page) { var msg = undefined; - for(var x in this.headers) { - if (this.headers[x].tags === page) { - msg = this.headers[x]; + for(var x in this.list_tagged) { + if (this.list_tagged[x].tags === page) { + msg = this.list_tagged[x]; break; } write(); // @todo This is needed for this to work? @@ -246,9 +244,10 @@ MsgArea.prototype.getMessagePage = function(number) { var r; - for (var x in this.headers) { - if (this.headers[x].number === number) { - r = this.headers[x]; + for (var x in this.list_tagged) { + if (this.list_tagged[x].number === number) { + r = this.list_tagged[x]; + break; } } diff --git a/main.js b/main.js index 1134a08..86c8f9d 100644 --- a/main.js +++ b/main.js @@ -432,7 +432,7 @@ while(bbs.online) { } } - if ((viewdata && read === '_') || (! viewdata && read === '#') || read === "\r") { + if ((viewdata && read === '_') || (! viewdata && read === '#') || ((read === "\r") && (cmd.length > 0))) { // Nothing typed between * and # // *# means go back if (cmd === '') { @@ -947,11 +947,10 @@ while(bbs.online) { // Parent fo.key[0] = (''+next_page.frame).substr(0,7); - // First Unread - fo.key[1] = atcode('msg_area_msgunread_page',null,null,area); - // First to me - fo.key[2] = atcode('msg_area_msgtome_page',null,null,area); + fo.key[1] = atcode('msg_area_msgtome_page',null,null,area); + // First Unread + fo.key[2] = atcode('msg_area_msgunread_page',null,null,area); // Oldest fo.key[3] = atcode('msg_area_msgoldest_page',null,null,area); diff --git a/text/198a.tex b/text/198a.tex index f8f87d4..a1fae6c 100644 --- a/text/198a.tex +++ b/text/198a.tex @@ -1 +1 @@ -{"version":1,"frame":198,"index":"a","owner":1,"cost":0,"content":"G1swbRtbNzZDG1sxbS4bWzBtDQogG1szM20bWG1zZ19ncnBfbmFtZTs0MBtcG1szMEMbWzM3bRtbMW3awr/Cv7+zG1swbQ0KIBtbMzZtG1htc2dfYXJlYV9hcmVhdGFnOzQwG1wbWzMwQxtbMzdtsyCzwrSzsw0KIBtbMTszNm0bWG1zZ19hcmVhX2Rlc2M7NDAbXBtbMzBDG1sxOzM3bVN1bW1hcnkbWzBtDQobWzE7MzBtxMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMSzxMTExMTExMTExMTExMTExMTExMTExMTExMTExBtbMG0NCiAbWERBVEVUSU1FOzI0G1wbWzI1QxtbMTszMG2zG1swbSAbWzFtTmV3IE1lc3NhZ2VzIHRvIFlvdRtbMG06IBtbMTszMW0bWG1zZ19hcmVhX25ld3RvbWU7LTUbXBtbMG0NChtbNTBDG1sxOzMwbbMbWzBtICAgICAbWzFtVW5yZWFkIE1lc3NhZ2VzG1swbTogG1sxOzMxbRtYbXNnX2FyZWFfbmV3Oy01G1wbWzBtDQogG1sxOzMybTEbWzM3bSBGaXJzdCB1bnJlYWQgICAbWzM0bRtYbXNnX2FyZWFfbXNndW5yZWFkX2RhdGU7MzEbXBtbMG0gG1sxOzMwbbMbWzBtICAgICAgG1sxbVRvdGFsIE1lc3NhZ2VzG1swbTogG1sxOzMxbRtYbXNnX2FyZWFfdG90YWw7LTUbXBtbMG0NCiAbWzE7MzJtMhtbMG0gG1sxbUZpcnN0IHRvIHlvdRtbMG0gICAbWzE7MzRtG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gICAgICAbWzE7NDRtsxtbMzNtIBtbMDszMjs0NG00G1sxOzM2bSAbWzA7MzY7NDRtUHJldmlvdXMbWzFtICAbWzA7NDRtICAbWzFtsxtbMDs0NG0gG1szMm0zG1sxOzM2bSAbWzA7MzY7NDRtUHJldiBUaHJlYWQbWzM3bSAbWzE7MzNtIBtbMzdtsxtbMG0NCiAbWzE7MzJtMBtbMDszMm0gG1sxOzM3bUJhY2sbWzBtICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAbWzE7NDRtsxtbMzNtIBtbMDszMjs0NG02G1sxOzM2bSAbWzA7MzY7NDRtTmV4dBtbMW0gG1swOzQ0bSAgICAgICAbWzFtsxtbMDs0NG0gG1szMm03G1szN20gG1szNm1OZXh0IFRocmVhZBtbMzdtIBtbMTszM20gG1szN22zG1swbQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgG1sxOzQ0bbMbWzA7NDRtIBtbMzJtNRtbMzdtIBtbMzZtV3JpdGUgTmV3G1szN20gICAbWzFtsxtbMDs0NG0gG1szMm04G1szN20gG1szNm1SZXBseRtbMzdtICAgICAgIBtbMTszM20gG1szN22zG1swbQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgG1sxOzQ0bbMbWzA7NDRtIBtbMzJtIxtbMzdtIBtbMzZtTXNnIEF0dHJzICAbWzM3bSAbWzFtsxtbMDs0NG0gG1szMm0wG1szN20gG1szNm1SZXR1cm4gaGVyZRtbMzdtIBtbMTszM20gG1szN22zG1swbQ0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgG1sxOzQ0bdTNzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzb4bWzBtDQo=","isPublic":0,"isAccessible":1,"type":"m","key":[null,null,null,null,null,null,null,null,null,null],"date":"2022-04-29T00:00:00.000Z"} +{"version":1,"frame":198,"index":"a","owner":1,"cost":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AgICAgICAgICAgICAgICAgICAgICAgG1sxOzQ0bbMbWzMzbSAbWzA7MzI7NDRtNhtbMTszNm0gG1swOzM2OzQ0bU5leHQbWzFtIBtbMDs0NG0gICAgICAgG1sxbbMbWzA7NDRtIBtbMzJtNxtbMzdtIBtbMzZtTmV4dCBUaHJlYWQbWzM3bSAbWzE7MzNtIBtbMzdtsxtbMG0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIBtbMTs0NG2zG1swOzQ0bSAbWzMybTUbWzM3bSAbWzM2bVdyaXRlIE5ldxtbMzdtICAgG1sxbbMbWzA7NDRtIBtbMzJtOBtbMzdtIBtbMzZtUmVwbHkbWzM3bSAgICAgICAbWzE7MzNtIBtbMzdtsxtbMG0NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIBtbMTs0NG2zG1swOzQ0bSAbWzMybSMbWzM3bSAbWzM2bU1zZyBBdHRycyAgG1szN20gG1sxbbMbWzA7NDRtIBtbMTszMm0wG1szN20gG1sxOzM2bVJldHVybiBoZXJlG1szN20gG1sxOzMzbSAbWzM3bbMbWzBtDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAbWzE7NDRt1M3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3NvhtbMG0NCg==","isPublic":0,"isAccessible":1,"type":"m","key":[null,null,null,null,null,null,null,null,null,null],"date":"2022-04-29T00:00:00.000Z"}