Skip to content

Commit b03f4d2

Browse files
committed
Merge pull request #165 from dgets/message-scan-pointers
Message scan pointers; primarily ``remap_message_indices()``
2 parents 5995933 + 7d41206 commit b03f4d2

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

load/dmbase.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,80 @@ msg_base = {
276276
* messages
277277
*/
278278
util : {
279+
/*
280+
* summary:
281+
* Method remaps message start through finish for a room/sub-board
282+
* into an array that skips deleted message slots and gives us a
283+
* set of indices that are more easily utilized at base 1
284+
* mBase:
285+
* Base that we are currently working with
286+
* return:
287+
* Array of valid messages
288+
*
289+
* NOTE: We might have to configure this to pass back a valid new
290+
* 'current' index since we're remapping the whole lot of 'em
291+
*/
292+
remap_message_indices : function(mBase) {
293+
var msgMap = new Array(), curHdr = new Object();
294+
var curPtr = 0;
295+
296+
if (!mBase.is_open()) {
297+
if (userSettings.debug.message_scan) {
298+
console.putmsg(cyan + "Opening " + mBase.cfg.name + " for" +
299+
" message mapping. . .\n");
300+
}
301+
try {
302+
mBase.open();
303+
} catch (e) {
304+
throw new docIface.dDocException("remap_message_indices" +
305+
"() Exception", e.message, 1);
306+
}
307+
}
308+
309+
if (userSettings.debug.message_scan) {
310+
console.putmsg(yellow + "Remapping:\n");
311+
}
312+
for (var ndx = mBase.first_msg; ndx <= mBase.last_msg; ndx++) {
313+
if (userSettings.debug.message_scan) {
314+
console.clearline();
315+
}
316+
317+
try {
318+
curHdr = mBase.get_msg_header(ndx);
319+
} catch (e) {
320+
console.putmsg("Exception getting header: " + e.message +
321+
"\n");
322+
mBase.close();
323+
throw new docIface.dDocException("remap_message_indices" +
324+
"() Exception", e.message, 2);
325+
}
326+
327+
if ((curHdr == null) || (curHdr.attr&MSG_DELETED)) {
328+
continue; //skip this shit, we don't want this indexed
329+
} else {
330+
if (userSettings.debug.message_scan) {
331+
console.putmsg(yellow + high_intensity + ndx + " to " +
332+
curPtr);
333+
}
334+
msgMap[curPtr++] = ndx;
335+
}
336+
}
337+
338+
if (msgMap.length == 0) {
339+
console.putmsg(red + "No messages found for mapping\n");
340+
throw new docIface.dDocException("remap_message_indices()" +
341+
" Exception", "No messages in " + mBase.cfg.name +
342+
" for mapping!", 3);
343+
}
344+
345+
if (userSettings.debug.message_scan) {
346+
console.putmsg(green + "Returning message mapping: " + msgMap +
347+
"\nFor base: " + mBase.cfg.name + "\n");
348+
}
349+
350+
mBase.close();
351+
return msgMap;
352+
},
279353
/*
280354
* summary:
281355
* Deletes the message (if appropriate permissions) at the current

0 commit comments

Comments
 (0)