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

View File

@ -507,7 +507,7 @@ function Page(debug) {
// Insert our *_field data (if it is set) // Insert our *_field data (if it is set)
function insert_fields(fields,build) { function insert_fields(fields,build) {
for (var i in fields) { 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(''); var content = fields[i].value.split('');
@ -545,12 +545,20 @@ function Page(debug) {
* Build in our dynamic_fields that can be populated automatically * Build in our dynamic_fields that can be populated automatically
*/ */
this.build_system_fields = function(context) { this.build_system_fields = function(context) {
log(LOG_DEBUG,'Building system fields with context:'+context);
var that = this; var that = this;
var f = this.dynamic_fields.filter(function(item) { return item.value === undefined; }); var f = this.dynamic_fields.filter(function(item) { return item.value === undefined; });
if (f.length) { if (f.length) {
f.forEach(function(field) { f.forEach(function(field,key) {
that.dynamic_field(field.name,atcode(field.name,field.length,field.pad,context)); 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. // @todo consider how we do mail security.
// Echoarea mail summary // 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+']'); log(LOG_DEBUG,'- ACTION_GOTO - load echoarea summary: ['+next_page.frame+']');
var ma = new MsgAreas(); var ma = new MsgAreas();
@ -1142,6 +1157,8 @@ while (bbs.online) {
cf = null; cf = null;
log(LOG_DEBUG,'- ACTION_RELOAD: ['+(next_page ? pageStr(next_page) : '')+']'); 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') if (debug_mode && so.page.name.toString() === '98b')
so.page.key[1] = debug_mode.split('/')[2]; so.page.key[1] = debug_mode.split('/')[2];