Message reading navigation, enable tagging a specific message area
This commit is contained in:
@@ -59,9 +59,6 @@ function echomail(page) {
|
||||
pageframe.scroll(0,-1);
|
||||
read = '';
|
||||
break;
|
||||
|
||||
case '*':
|
||||
break;
|
||||
}
|
||||
|
||||
pageframe.cycle();
|
||||
|
@@ -45,7 +45,7 @@ function FrameAnsi() {
|
||||
this.settings.LOGIN_ERROR = '\1n\1h\1RERROR LOGGING IN, PLEASE TRY AGAIN *00';
|
||||
this.settings.CANCEL_MSG = '\1n\1h\1GPRESS 2 TO CANCEL';
|
||||
this.settings.SYS_ERROR = '\1n\1h\1RSYSTEM ERROR DETECTED - TRY AGAIN OR TELL US *08';
|
||||
this.settings.LOADING = '\1n\1h\1Wloading...';
|
||||
this.settings.LOADING = '\1n\1h\1Kloading...';
|
||||
|
||||
/**
|
||||
* Set the attribute at the current position
|
||||
|
@@ -194,6 +194,7 @@ PageFrame.prototype.loadMessage = function(page) {
|
||||
this.isAccessible = true;
|
||||
// @todo Keys should map to next/previous/send, etc as indicated in the template frame.
|
||||
this.key = [this.frame.substr(0,7)+'1',null,null,null,null,null,null,null,null,null];
|
||||
// @todo validate that FRAME_TYPE_MESSAGE is a message template
|
||||
this.type = FRAME_TYPE_MESSAGE;
|
||||
|
||||
// Load our message
|
||||
@@ -242,30 +243,54 @@ PageFrame.prototype.loadMessage = function(page) {
|
||||
|
||||
// if this message is to the user, and the msg number > scan_ptr and it is the next message on the user's new mail list
|
||||
var newmsgs = area.newMsgsToMe();
|
||||
var next;
|
||||
log(LOG_DEBUG,'User has: '+newmsgs.length+' msgs to read to ME');
|
||||
if (newmsgs.length) {
|
||||
var next = newmsgs[0];
|
||||
next = newmsgs[1];
|
||||
log(LOG_DEBUG,'- NEXT is: '+next.tags+', this is: '+msg.tags);
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
// Last message
|
||||
next = newmsgs[0];
|
||||
log(LOG_DEBUG,'- LAST TO ME is: '+next.tags);
|
||||
if (next !== undefined) {
|
||||
this.key[1] = area.page(next.tags);
|
||||
}
|
||||
|
||||
// Next new message
|
||||
next = newmsgs[2];
|
||||
log(LOG_DEBUG,'- NEXT TO ME is: '+next.tags);
|
||||
if (next !== undefined)
|
||||
this.key[2] = area.page(next.tags);
|
||||
}
|
||||
|
||||
// if this message is the next message, update last_read
|
||||
var newmsgs = area.newMsgs();
|
||||
newmsgs = area.newMsgs();
|
||||
log(LOG_DEBUG,'User has: '+newmsgs.length+' msgs to read');
|
||||
if (newmsgs.length) {
|
||||
var next = newmsgs[0];
|
||||
next = newmsgs[0];
|
||||
log(LOG_DEBUG,'- NEXT is: '+next.tags+', this is: '+msg.tags);
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
// Previous Message
|
||||
x = area.MessagePrev(this.frame);
|
||||
if (x)
|
||||
this.key[4] = area.page(x.tags);
|
||||
|
||||
// Next Message
|
||||
x = area.MessageNext(this.frame);
|
||||
if (x)
|
||||
this.key[6] = area.page(x.tags);
|
||||
|
||||
log(LOG_DEBUG,'Built frame: ['+this.frame+']['+this.index+'] ('+this.page+')');
|
||||
}
|
||||
|
||||
|
@@ -217,7 +217,7 @@ function atcode(field,length,pad,context) {
|
||||
|
||||
var x = context.newMsgsToMe();
|
||||
|
||||
result = x.length ? x.shift().date : '';
|
||||
result = x.length > 1 ? x[1].date : '';
|
||||
break;
|
||||
|
||||
case 'msg_area_msgtome_page':
|
||||
@@ -227,7 +227,7 @@ function atcode(field,length,pad,context) {
|
||||
}
|
||||
|
||||
var x = context.newMsgsToMe();
|
||||
return x.length ? context.getMessagePage(x.shift().number) : null;
|
||||
return x.length > 1 ? context.getMessagePage(x[1].number) : null;
|
||||
|
||||
// Count of unread messages
|
||||
case 'msg_area_new':
|
||||
@@ -251,7 +251,7 @@ function atcode(field,length,pad,context) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = ''+context.newMsgsToMe().length;
|
||||
result = ''+(context.newMsgsToMe().length > 1 ? context.newMsgsToMe().length-1 : 0);
|
||||
break;
|
||||
|
||||
// Is this message area in my new scan list
|
||||
|
@@ -63,8 +63,12 @@ function MsgArea() {
|
||||
|
||||
try {
|
||||
if (this.msgbase.open()) {
|
||||
// @todo If there are more than 10,000, take only the last 10,000.
|
||||
this.headers = this.msgbase.get_all_msg_headers(false,false) || [];
|
||||
headers = this.msgbase.get_all_msg_headers(false,false) || [];
|
||||
|
||||
// Just take the last MAX_MESSAGES
|
||||
this.headers = Object.keys(headers).slice(-(MAX_PAGE_NUM+1)).map(function(key) { return headers[key]; });
|
||||
headers = undefined;
|
||||
|
||||
this.msgbase.close();
|
||||
|
||||
} else {
|
||||
@@ -76,8 +80,6 @@ function MsgArea() {
|
||||
log(LOG_ERROR,code+' cannot be opened:'+e.message);
|
||||
this.headers = [];
|
||||
}
|
||||
|
||||
log(LOG_DEBUG,'msgbase:'+JSON.stringify(this.msgbase));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -166,7 +168,8 @@ function MsgArea() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unread messages
|
||||
* Unread messages [1..]
|
||||
* Array key 0 returns the last read message
|
||||
*
|
||||
* @returns {*[]}
|
||||
*/
|
||||
@@ -194,12 +197,21 @@ MsgArea.prototype.newMsgs = function() {
|
||||
MsgArea.prototype.newMsgsToMe = function() {
|
||||
var msgs = [];
|
||||
var stats = this.getUserStats();
|
||||
var last = null;
|
||||
//log(LOG_DEBUG,'Users scan_ptr pointer: '+JSON.stringify(stats.scan_ptr));
|
||||
|
||||
for(var x in this.list_tagged) {
|
||||
// Advance past our last scan_ptr
|
||||
if (this.list_tagged[x].number <= stats.scan_ptr)
|
||||
if (this.list_tagged[x].number <= stats.scan_ptr) {
|
||||
if ((this.list_tagged[x].to === user.name) || (this.list_tagged[x].to === user.alias))
|
||||
last = x;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add our previous to me message
|
||||
if (msgs.length === 0)
|
||||
msgs.push(last !== null ? this.list_tagged[last] : []);
|
||||
|
||||
if ((this.list_tagged[x].to === user.name) || (this.list_tagged[x].to === user.alias))
|
||||
msgs.push(this.list_tagged[x]);
|
||||
@@ -270,15 +282,77 @@ MsgArea.prototype.getUserStats = function() {
|
||||
return this.msgbase.cfg ? msg_area.grp_list[this.msgbase.cfg.grp_number].sub_list[msg_area.sub[this.msgbase.cfg.code].index] : [];
|
||||
}
|
||||
|
||||
MsgArea.prototype.MessageNext = function(page) {
|
||||
var x = null;
|
||||
|
||||
if (! page)
|
||||
return undefined;
|
||||
|
||||
var msgid = page.substr(7,4);
|
||||
|
||||
for(x in this.list_tagged) {
|
||||
if (this.list_tagged[x].tags === msgid) {
|
||||
break;
|
||||
}
|
||||
|
||||
write(); // @todo This is needed for this to work?
|
||||
}
|
||||
|
||||
//log(LOG_DEBUG,'- Next Message is:'+JSON.stringify(this.list_tagged[(parseInt(x)+1)])+', msgid:'+msgid+', page:'+page+', x:'+x);
|
||||
|
||||
/*
|
||||
= Our next message is either
|
||||
+ x+1 if x < this.list_tagged.length
|
||||
+ x=0 if x == this.list_tagged.length (-1)
|
||||
+ null if this.list_tagged.length == null; (thus no messages)
|
||||
*/
|
||||
|
||||
return x === null ? null : this.list_tagged[(parseInt(x) === this.list_tagged.length-1) ? 0 : (parseInt(x)+1)];
|
||||
}
|
||||
|
||||
MsgArea.prototype.MessagePrev = function(page) {
|
||||
var prev = null;
|
||||
var x = null;
|
||||
|
||||
if (! page)
|
||||
return undefined;
|
||||
|
||||
var msgid = page.substr(7,4);
|
||||
|
||||
for(x in this.list_tagged) {
|
||||
if (this.list_tagged[x].tags === msgid) {
|
||||
break;
|
||||
|
||||
} else {
|
||||
prev = x;
|
||||
}
|
||||
|
||||
write(); // @todo This is needed for this to work?
|
||||
}
|
||||
|
||||
/*
|
||||
= Our previous message is either
|
||||
+ prev if a tag was found, unless
|
||||
+ prev is null, in which case it is this.list_tagged.length -1
|
||||
+ null if x is still null (thus no messages)
|
||||
*/
|
||||
|
||||
// If prev is still null, then our last message must be the last one, unless x is null then there are no messages
|
||||
return x === null ? null : this.list_tagged[(prev === null) ? this.list_tagged.length-1 : parseInt(prev)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag messages with a frame number
|
||||
* @note: May need to run jsexec with -m 32MB to overcome memory issues
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
MsgArea.prototype.tag_msgs = function() {
|
||||
var msgs = this.list_untagged;
|
||||
|
||||
// See if we need to something
|
||||
writeln("We have "+msgs.length+" messages to tag.");
|
||||
|
||||
// See if we need to tag something
|
||||
if (! msgs.length)
|
||||
return;
|
||||
|
||||
@@ -308,6 +382,10 @@ MsgArea.prototype.tag_msgs = function() {
|
||||
return true;
|
||||
}
|
||||
|
||||
MsgArea.prototype.page = function(msgid) {
|
||||
return '1'+this.page_prefix+msgid;
|
||||
}
|
||||
|
||||
MsgAreas.prototype.getArea = function(area) {
|
||||
log(LOG_DEBUG,'- AREA:'+JSON.stringify(area));
|
||||
if (area === undefined)
|
||||
|
Reference in New Issue
Block a user