diff --git a/load/funcs.js b/load/funcs.js index 3a24efa..12d19ec 100644 --- a/load/funcs.js +++ b/load/funcs.js @@ -140,9 +140,10 @@ function atcode(field,length,pad,context) { break; } - var x = context.msgbase.first_msg || 1; + // @todo Cant use context.msgbase.first_msg - it is always zero? + var x = Object.keys(context.headers)[0]; - result = x ? context.getMessagePtr(x).date : ''; + result = x ? context.headers[x].date : ''; break; case 'msg_area_msgoldest_page': @@ -151,9 +152,10 @@ function atcode(field,length,pad,context) { break; } - var x = context.msgbase.first_msg || 1; + // @todo Cant use context.msgbase.first_msg - it is always zero? + var x = Object.keys(context.headers)[0]; - return x ? context.getMessagePage(x) : null; + return x ? context.getMessagePage(context.headers[x].number) : null; // Newest message in msgarea case 'msg_area_msgnewest_date': @@ -162,7 +164,7 @@ function atcode(field,length,pad,context) { break; } - result = context.msgbase.last_msg ? context.getMessagePtr(context.msgbase.last_msg).date : ''; + result = context.headers[context.msgbase.last_msg] ? context.headers[context.msgbase.last_msg].date : ''; break; case 'msg_area_msgnewest_page': @@ -171,7 +173,7 @@ function atcode(field,length,pad,context) { break; } - return context.msgbase.last_msg ? context.getMessagePage(context.msgbase.last_msg) : null; + return context.msgbase.last_msg ? context.getMessagePage(context.headers[context.msgbase.last_msg].number) : null; // First unread message case 'msg_area_msgunread_date': diff --git a/load/msgbases.js b/load/msgbases.js index 6518cc2..a060831 100644 --- a/load/msgbases.js +++ b/load/msgbases.js @@ -235,32 +235,28 @@ 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 + * @param number * @returns {string} */ -MsgArea.prototype.getMessagePage = function(ptr) { - log(LOG_DEBUG,'Get Message Page with ptr ['+JSON.stringify(ptr)+']'); +MsgArea.prototype.getMessagePage = function(number) { + log(LOG_DEBUG,'Get Message Page with number ['+number+']'); - ptr = ptr || 1; + var r; - if (! this.headers[ptr] || this.headers[ptr].tags === undefined) + for (var x in this.headers) { + if (this.headers[x].number === number) { + r = this.headers[x]; + break; + } + } + + if (! r || r.tags === undefined) return null; - return '1'+this.zone_id+this.area_id+this.headers[ptr].tags; + return '1'+this.zone_id+this.area_id+r.tags; } MsgArea.prototype.getUserStats = function() {