Echoarea front page navigation

This commit is contained in:
Deon George
2022-05-03 21:10:09 +10:00
parent 2dc348a29c
commit 51de982fbb
6 changed files with 284 additions and 32 deletions

View File

@@ -29,21 +29,21 @@ function FrameAnsi() {
this.settings.ERR_ROUTE = '\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
this.settings.ERR_METHOD_NOT_EXIST = '\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
this.settings.ACCESS_DENIED = '\1n\1h\1RACCESS DENIED. MISTAKE? TRY AGAIN OR TELL US *08';
this.settings.ALREADY_MEMBER = '\1n\1h\1RALREADY MEMBER OF CUG'
this.settings.INACTIVITY = '\1n\1h\1RINACTIVITY ALERT, DISCONNECT PENDING...';
this.settings.ALREADY_MEMBER = '\1n\1h\1RALREADY MEMBER OF CUG'
this.settings.INACTIVITY = '\1n\1h\1RINACTIVITY ALERT, DISCONNECT PENDING...';
this.settings.INACTIVE = '\1n\1h\1RINACTIVITY DISCONNECT';
this.settings.NOACTION = '\1n\1h\1RNO ACTION PERFORMED';
this.settings.BASESTAR = '\1N\1G\1H*';
this.settings.INVALID_CODE = '\1n\1h\1RINVAID CODE, PLEASE TRY AGAIN *00';
this.settings.TOKEN_EMAIL = '\1n\1h\1RTOKEN EMAILED TO YOU...';
this.settings.TOKEN_SENT = '\1n\1h\1RTOKEN SENT, PLEASE ENTER TOKEN';
this.settings.TOKEN_SENT = '\1n\1h\1RTOKEN SENT, PLEASE ENTER TOKEN';
this.settings.INVALID_EMAIL = '\1n\1h\1RINVAID EMAIL, PLEASE TRY AGAIN *00';
this.settings.INVALID_UID = '\1n\1h\1RINVAID USER ID, PLEASE TRY AGAIN *00';
this.settings.CANNOT_SEND_TOKEN = '\1n\1h\1RCANNOT SEND VALIDATION CODE, PLEASE TRY AGAIN *00';
this.settings.USER_EXISTS = '\1n\1h\1RERROR USER EXISTS, PLEASE TRY AGAIN *00';
this.settings.USER_CREATE_ERROR = '\1n\1h\1RERROR CREATING USER, PLEASE TRY AGAIN *00';
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.CANCEL_MSG = '\1n\1h\1GPRESS 2 TO CANCEL';
/**
* Set the attribute at the current position

View File

@@ -182,7 +182,7 @@ PageFrame.prototype.load = function(filename) {
* @param page
*/
PageFrame.prototype.loadMessage = function(page) {
this.frame = '1'+page;
this.frame = ''+page;
this.index = 'a';
this.owner = 1;
this.isPublic = true;
@@ -193,6 +193,7 @@ PageFrame.prototype.loadMessage = function(page) {
// Load our message
var ma = new MsgAreas()
var area = ma.getArea(this.frame);
var msg = ma.getMessage(this.frame);
var msg_header;
@@ -231,7 +232,23 @@ PageFrame.prototype.loadMessage = function(page) {
//log(LOG_DEBUG,'Loaded message: '+msg_header+msg.content);
this.content = base64_encode(msg_header+msg.content);
log(LOG_DEBUG,'Loaded frame: ['+this.frame+']['+this.index+'] ('+this.page+')');
// Update the user's pointers
var stats = ma.getUserStats(this.frame);
// 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.newMsgs();
if (newmsgs.length) {
var next = newmsgs.shift();
if (next.tag === msg.tag)
stats.scan_ptr = next.number;
}
// if this message is the next message, update last_read
if (msg.number === stats.last_read+1)
stats.last_read = msg.number;
log(LOG_DEBUG,'Built frame: ['+this.frame+']['+this.index+'] ('+this.page+')');
}
/**

View File

@@ -109,13 +109,12 @@ function ans2bin(ansi,frame) {
function atcode(field,length,pad,context) {
'use strict';
length = length ? length : field.length;
pad = pad ? pad : ' ';
var result = '';
switch(field) {
// Get the ECHOAREA FTN AREA_TAG
case 'areatag':
case 'msg_area_areatag':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
@@ -125,7 +124,7 @@ function atcode(field,length,pad,context) {
break;
// Get the ECHOAREA Description
case 'areadesc':
case 'msg_area_desc':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
@@ -134,18 +133,165 @@ function atcode(field,length,pad,context) {
result = context.msgbase.cfg.description;
break;
// Oldest message in msgarea
case 'msg_area_msgoldest_date':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
var x = context.msgbase.first_msg || 1;
result = x ? context.getMessagePtr(x).date : '';
break;
case 'msg_area_msgoldest_page':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
var x = context.msgbase.first_msg || 1;
result = x ? context.getMessagePage(x) : null;
break;
// Newest message in msgarea
case 'msg_area_msgnewest_date':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = context.msgbase.last_msg ? context.getMessagePtr(context.msgbase.last_msg).date : '';
break;
case 'msg_area_msgnewest_page':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = context.msgbase.last_msg ? context.getMessagePage(context.msgbase.last_msg) : null;
break;
// First unread message
case 'msg_area_msgunread_date':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
var x = context.getUserStats().last_read+1;
result = (x <= context.msgbase.last_msg) ? context.getMessagePtr(x).date : '';
break;
case 'msg_area_msgunread_page':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
var x = context.getUserStats().last_read+1;
result = (x <= context.msgbase.last_msg) ? context.getMessagePage(x) : null;
break;
// First unread message to me
case 'msg_area_msgotome_date':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
var x = context.newMsgs();
result = x.length ? x.shift().date : '';
break;
case 'msg_area_msgtome_page':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
var x = context.newMsgs();
result = x.length ? context.getMessagePage(x.shift().number) : null;
break;
// Count of unread messages
case 'msg_area_new':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = ''+(context.msgbase.last_msg-context.getUserStats().last_read);
break;
// Count of unread messages to me
case 'msg_area_newtome':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = ''+context.newMsgs().length;
break;
// Is this message area in my new scan list
case 'msg_area_newscan':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = (context.getUserStats().scan_ptr & SCAN_CFG_TOYOU) ? 'YES' : 'NO';
break;
// Is this message area in my new scan list
case 'msg_area_pending':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = ''+context.list_untagged.length;
break;
// Get the ECHOAREA Total Number of Messages
case 'msg_area_total':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = ''+context.msgbase.total_msgs;
break;
// Get the ECHOAREA Group Name
case 'msg_grp_name':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
result = context.zone_name;
break;
case 'nodeid':
result = getNodeID();
break;
default:
result = bbs.atcode(field);
if (result === null)
result = '';
}
log(LOG_DEBUG,' - result length ['+result.length+'] desired ('+length+')');
if ((result === null) || (typeof result === 'undefined'))
result = '';
length = length ? length : result.length;
//log(LOG_DEBUG,' - result length ['+result.length+'] desired ('+length+')');
if (result.length < Math.abs(length))
result = (length < 0) ? padright(result,Math.abs(length),pad) : padleft(result,length,pad);
else if (result.length > Math.abs(length))

View File

@@ -63,7 +63,7 @@ function MsgArea() {
exit(2);
}
this.headers = this.msgbase.get_all_msg_headers(false,false);
this.headers = this.msgbase.get_all_msg_headers(false,false) || [];
this.msgbase.close();
}
});
@@ -159,6 +159,28 @@ function MsgArea() {
});
}
/**
* New Messages for the logged in user
*/
MsgArea.prototype.newMsgs = function() {
var msgs = [];
var stats = this.getUserStats();
//log(LOG_DEBUG,'Users scan pointer: '+JSON.stringify(stats.scan_ptr));
for(var x in this.headers) {
// Advance past our last scan_ptr
if (x <= stats.scan_ptr)
continue;
if ((this.headers[x].to === user.name) || (this.headers[x].to === user.alias))
msgs.push(this.headers[x]);
write(); // @todo This is needed for this to work?
}
return msgs;
}
/**
* Get a specific message with a tag
*/
@@ -190,6 +212,38 @@ MsgArea.prototype.getMessage = function(page) {
return msg;
}
/**
* Get a message by pointer
*
* @param ptr
*/
MsgArea.prototype.getMessagePtr = function(ptr) {
ptr = ptr || 1;
return this.headers[ptr];
}
/**
* Get a message page by pointer
*
* @param ptr
* @returns {string}
*/
MsgArea.prototype.getMessagePage = function(ptr) {
log(LOG_DEBUG,'Get Message Page with ptr ['+JSON.stringify(ptr)+']');
ptr = ptr || 1;
if (! this.headers[ptr] || this.headers[ptr].tags === undefined)
return null;
return '1'+this.zone_id+this.area_id+this.headers[ptr].tags;
}
MsgArea.prototype.getUserStats = function() {
return msg_area.grp_list[this.msgbase.cfg.grp_number].sub_list[msg_area.sub[this.msgbase.cfg.code].index];
}
/**
* Tag messages with a frame number
*