added msgbase handling and finding a tagged message

This commit is contained in:
Deon George 2022-04-20 21:19:01 +10:00
parent 18d1313eef
commit 30d402e797

View File

@ -1,3 +1,7 @@
const PAGE_LENGTH = 4; // The size of our page tag.
const PAGE_LAST_KEY = 'last_page';
const MAX_PAGE_NUM = 9999;
// Our message bases
function MsgAreas() {
'use strict';
@ -48,9 +52,6 @@ function MsgArea() {
this.tagged_list = undefined;
this.untagged_list = undefined;
const PAGE_LENGTH = 4; // The size of our page tag.
const PAGE_LAST_KEY = 'last_page';
Object.defineProperty(this,'code',{
set: function(code) {
this.msgbase = new MsgBase(code);
@ -177,7 +178,11 @@ MsgArea.prototype.getMessage = function(page) {
if (! msg)
return undefined;
this.msgbase.open();
if (! this.msgbase.open()) {
writeln(code+' cannot be opened:'+this.msgbase.error);
return undefined;
}
msg.content = this.msgbase.get_msg_body(false,msg.number,false,false,true,true);
this.msgbase.close();
@ -196,15 +201,15 @@ MsgArea.prototype.tag_msgs = function() {
if (! msgs.length)
return;
if (! this.msgbase.open('r+')) {
writeln(ma.areas[i].code+' cannot be opened?');
if (! this.msgbase.open()) {
writeln(code+' cannot be opened:'+this.msgbase.error);
return false;
}
var page_next = this.page_next;
for(var x in msgs) {
var msg = this.msgbase.get_msg_header(msgs[x].number, /* expand: */false)
writeln('Setting page:'+(''+(page_next)).padStart(4,'0')+', for:'+msg.number);
writeln('Setting page:'+(''+(page_next)).padStart(4,'0')+', for:'+msg.number+', existing tag:'+msg.tags);
msg.tags = (''+(page_next)).padStart(4,'0');
if(! this.msgbase.put_msg_header(msg.number,msg)) {
writeln('ERROR:'+this.msgbase.error);
@ -215,12 +220,15 @@ MsgArea.prototype.tag_msgs = function() {
}
this.msgbase.close();
this.page_next = page_next;
return true;
}
MsgAreas.prototype.getMessage = function(page) {
if (page === undefined)
return undefined;
var zone = page.substr(0,4);
var echo = page.substr(4,2);
var page = page.substr(6);