Change to use list_tagged when offering message pages for users

This commit is contained in:
Deon George
2022-05-12 22:27:06 +10:00
parent 2ba3fbf231
commit 0bf0e223b5
5 changed files with 48 additions and 44 deletions

View File

@@ -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+')');

View File

@@ -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':

View File

@@ -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;
}
}