diff --git a/load/funcs.js b/load/funcs.js index 25809db..937b87e 100644 --- a/load/funcs.js +++ b/load/funcs.js @@ -231,6 +231,11 @@ function atcode(field,length,pad,context) { // Count of unread messages case 'msg_area_new': + if (args.length === 1) { + context = new MsgArea(); + context.code = args[0]; + } + if (typeof context !== 'object') { log(LOG_ERROR,'Unable to render ['+field+'], no context provided'); break; diff --git a/load/msgbases.js b/load/msgbases.js index b10c89c..8111f16 100644 --- a/load/msgbases.js +++ b/load/msgbases.js @@ -61,15 +61,23 @@ function MsgArea() { set: function(code) { this.msgbase = new MsgBase(code); - if (! this.msgbase.open()) { - writeln(code+' cannot be opened:'+this.msgbase.error); - exit(2); + 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) || []; + this.msgbase.close(); + + } else { + log(LOG_ERROR,code+' cannot be opened:'+this.msgbase.error); + this.headers = []; + } + + } catch (e) { + log(LOG_ERROR,code+' cannot be opened:'+e.message); + this.headers = []; } - this.headers = this.msgbase.get_all_msg_headers(false,false) || []; - // @todo If there are more than 10,000, take only the last 10,000. - - this.msgbase.close(); + log(LOG_DEBUG,'msgbase:'+JSON.stringify(this.msgbase)); } }); @@ -259,7 +267,7 @@ MsgArea.prototype.getMessagePage = function(number) { } MsgArea.prototype.getUserStats = function() { - return msg_area.grp_list[this.msgbase.cfg.grp_number].sub_list[msg_area.sub[this.msgbase.cfg.code].index]; + return this.msgbase.cfg ? msg_area.grp_list[this.msgbase.cfg.grp_number].sub_list[msg_area.sub[this.msgbase.cfg.code].index] : []; } /**