Update improved msg_ atcode functions to assist with rendering message subs

This commit is contained in:
Deon George 2024-12-23 14:52:45 +11:00
parent 018ee63853
commit bf47e44186
4 changed files with 85 additions and 42 deletions

View File

@ -1,7 +1,8 @@
'use strict';
require('ansitex/load/defs.js','ANSITEX_HOME'); // ANSITEX definitions
// Array of page owners
pageowners = [];
var pageowners = [];
// String repeat.
if (!String.prototype.repeat) {
@ -81,10 +82,8 @@ function ans2bin(ansi,frame) {
* @note bbs.atcodes() cannot process modifiers, so this function is a replacement.
*/
function atcode(field,length,pad,context) {
'use strict';
pad = pad ? pad : ' ';
var result = '';
var result = {};
var args = [];
if (field.search(/:/)) {
@ -92,27 +91,44 @@ function atcode(field,length,pad,context) {
field = args.shift();
}
//log(LOG_DEBUG,'Field:'+field,'Args:'+JSON.stringify(args));
log(LOG_DEBUG,'Field:'+field,'Args:'+JSON.stringify(args));
switch(field) {
// Get the ECHOAREA FTN AREA_TAG
case 'msg_area_areatag':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
// Work out the key for the message area
case 'msg_area_key':
var index = args.shift();
log(LOG_DEBUG,'Context:'+context+', Index:'+index);
// If the message area exists, we'll return a key and a index
if (new MsgAreas().getArea(context+index.padStart(2,'0'))) {
result.value = index;
result.key = '1'+context+index.padStart(2,'0');
}
result = context.msgbase.cfg.area_tag;
break;
// Get the ECHOAREA Description
case 'msg_area_desc':
if (typeof context !== 'object') {
log(LOG_ERROR,'Unable to render ['+field+'], no context provided');
break;
}
// Get the ECHOAREA Internal Code
case 'msg_area_tag':
var index = args.shift();
var area = new MsgAreas().getArea(context+index.padStart(2,'0'));
log(LOG_DEBUG,'Context:'+context+', Index:'+index+', Area:'+JSON.stringify(area));
// If the message area exists
if (area)
result.value = area.code.toUpperCase();
break;
// Get the ECHOAREA Name
case 'msg_area_name':
var index = args.shift();
var area = new MsgAreas().getArea(context+index.padStart(2,'0'));
if (area)
result.value = area.area_name;
result = context.msgbase.cfg.description;
break;
// Oldest message in msgarea
@ -125,7 +141,7 @@ function atcode(field,length,pad,context) {
var x = context.list_tagged[0];
result = x ? x.date : '';
result.value = x ? x.date : '';
break;
case 'msg_area_msgoldest_page':
@ -148,7 +164,7 @@ function atcode(field,length,pad,context) {
var x = context.list_tagged[context.list_tagged.length-1];
result = x ? x.date : '';
result.value = x ? x.date : '';
break;
case 'msg_area_msgnewest_page':
@ -170,7 +186,7 @@ function atcode(field,length,pad,context) {
var x = context.newMsgs();
result = x.length ? x.shift().date : '';
result.value = x.length ? x.shift().date : '';
break;
case 'msg_area_msgunread_page':
@ -191,7 +207,7 @@ function atcode(field,length,pad,context) {
var x = context.newMsgsToMe();
result = x.length > 1 ? x[1].date : '';
result.value = x.length > 1 ? x[1].date : '';
break;
case 'msg_area_msgtome_page':
@ -215,7 +231,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+context.newMsgs().length;
result.value = ''+context.newMsgs().length;
break;
// Count of unread messages to me
@ -225,7 +241,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+(context.newMsgsToMe().length > 1 ? context.newMsgsToMe().length-1 : 0);
result.value = ''+(context.newMsgsToMe().length > 1 ? context.newMsgsToMe().length-1 : 0);
break;
// Is this message area in my new scan list
@ -235,7 +251,7 @@ function atcode(field,length,pad,context) {
break;
}
result = (context.getUserStats().scan_ptr & SCAN_CFG_TOYOU) ? 'YES' : 'NO';
result.value = (context.getUserStats().scan_ptr & SCAN_CFG_TOYOU) ? 'YES' : 'NO';
break;
// Is this message area in my new scan list
@ -245,7 +261,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+context.list_untagged.length;
result.value = ''+context.list_untagged.length;
break;
// Get the ECHOAREA Total Number of Messages
@ -255,7 +271,7 @@ function atcode(field,length,pad,context) {
break;
}
result = ''+context.msgbase.total_msgs;
result.value = ''+context.msgbase.total_msgs;
break;
// Get the ECHOAREA Group Name
@ -265,29 +281,29 @@ function atcode(field,length,pad,context) {
break;
}
result = context.zone_name;
result.value = context.zone_name;
break;
case 'nodeid':
result = getNodeID();
result.value = getNodeID();
break;
default:
result = (typeof bbs === 'undefined') ? '*'.repeat(Math.abs(length)) : bbs.atcode(field+(args.length ? ':'+args : ''));
result.value = (typeof bbs === 'undefined') ? '*'.repeat(Math.abs(length)) : bbs.atcode(field+(args.length ? ':'+args : ''));
}
if ((result === null) || (typeof result === 'undefined'))
result = '';
if ((result.value === null) || (result.value === undefined))
result.value = '';
length = length ? length : result.length;
length = length ? length : result.value.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))
result = result.substr(0,Math.abs(length));
if (result.value.length < Math.abs(length))
result.value = (length < 0) ? padright(result.value,Math.abs(length),pad) : padleft(result.value,length,pad);
else if (result.value.length > Math.abs(length))
result.value = result.value.substr(0,Math.abs(length));
log(LOG_DEBUG,'* ATCODE ['+field+'] ('+length+'|"'+pad+'") returns ['+result+']');
log(LOG_DEBUG,'* ATCODE ['+field+'] ('+length+'|"'+pad+'") returns ['+result.value+'] key ['+result.key+']');
return result;
}

View File

@ -99,6 +99,8 @@ function MsgAreas() {
}
}
ma.area_name = msg_area.grp_list[g].sub_list[a].description;
this.areas.push(ma);
}
}

View File

@ -507,7 +507,7 @@ function Page(debug) {
// Insert our *_field data (if it is set)
function insert_fields(fields,build) {
for (var i in fields) {
//log(LOG_DEBUG,'|-- Adding:'+fields[i].name+', with value:'+fields[i].value);
log(LOG_DEBUG,'|-- Adding:'+fields[i].name+', with value:'+fields[i].value);
var content = fields[i].value.split('');
@ -545,12 +545,20 @@ function Page(debug) {
* Build in our dynamic_fields that can be populated automatically
*/
this.build_system_fields = function(context) {
log(LOG_DEBUG,'Building system fields with context:'+context);
var that = this;
var f = this.dynamic_fields.filter(function(item) { return item.value === undefined; });
if (f.length) {
f.forEach(function(field) {
that.dynamic_field(field.name,atcode(field.name,field.length,field.pad,context));
f.forEach(function(field,key) {
log(LOG_DEBUG,'Key is:'+key);
var ac = atcode(field.name,field.length,field.pad,context);
that.dynamic_field(field.name,ac.value);
if (ac.key) {
log(LOG_DEBUG,'ATCODE sets key for ['+field.name+'] using ['+ac.key+']');
that.__properties__.key[ac.value] = ac.key;
}
});
}
}

19
main.js
View File

@ -1019,7 +1019,22 @@ while (bbs.online) {
// @todo consider how we do mail security.
// Echoarea mail summary
if (/^1[0-9]{6}1$/.test(next_page.frame)) {
if (/^1[0-9]{4}1$/.test(next_page.frame)) {
log(LOG_DEBUG,'- ACTION_GOTO - load echoarea list: ['+next_page.frame.toString().slice(1,5)+']');
if (! so.get(new PageObject({frame: next_page.frame, index: next_page.index}))) {
so.baselineSend('ERR_ROUTE',false);
action = mode = null;
break;
}
// @todo trigger page load, it isnt loaded yet so build_system_fields does nothing
so.page.build_system_fields(next_page.frame.toString().slice(1,5));
next_page = null;
// Echoarea list
} else if (/^1[0-9]{6}1$/.test(next_page.frame)) {
log(LOG_DEBUG,'- ACTION_GOTO - load echoarea summary: ['+next_page.frame+']');
var ma = new MsgAreas();
@ -1142,6 +1157,8 @@ while (bbs.online) {
cf = null;
log(LOG_DEBUG,'- ACTION_RELOAD: ['+(next_page ? pageStr(next_page) : '')+']');
// If we have configured debug_mode auto login, jump to the debug_mode page
if (debug_mode && so.page.name.toString() === '98b')
so.page.key[1] = debug_mode.split('/')[2];