From dd7b234a1d1f1021a0b91da680a2eebbbfbe4058 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 7 Jul 2018 20:04:51 -0600 Subject: [PATCH] Add @markAllRead method for msg_list --- art/themes/luciano_blocktronics/NEWMSGS.ANS | Bin 2312 -> 2340 bytes config/menu.hjson | 4 ++ core/msg_list.js | 52 +++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/art/themes/luciano_blocktronics/NEWMSGS.ANS b/art/themes/luciano_blocktronics/NEWMSGS.ANS index 1065e2956d71a721e9764535d78fb360b2cae214..904399929a667f16171632ce890b9ca08f9ed634 100644 GIT binary patch delta 98 zcmeAWS|YUJFq?^~vvjnfwXsodu5`3Pt^$~2kZUC!4HN?M3_wzeIXMbNsfj6EP}#{( g*Zu R=gmLZ*%%oYO#aWI3IOdD7196z diff --git a/config/menu.hjson b/config/menu.hjson index 8973c833..7dfe4bba 100644 --- a/config/menu.hjson +++ b/config/menu.hjson @@ -783,6 +783,10 @@ keys: [ "x", "shift + x" ] action: @method:fullExit } + { + keys: [ "m", "shift + m" ] + action: @method:markAllRead + } ] } } diff --git a/core/msg_list.js b/core/msg_list.js index d4798012..25c9772d 100644 --- a/core/msg_list.js +++ b/core/msg_list.js @@ -5,7 +5,6 @@ const MenuModule = require('./menu_module.js').MenuModule; const ViewController = require('./view_controller.js').ViewController; const messageArea = require('./message_area.js'); -const stringFormat = require('./string_format.js'); const MessageAreaConfTempSwitcher = require('./mod_mixins.js').MessageAreaConfTempSwitcher; const Errors = require('./enig_error.js').Errors; const Message = require('./message.js'); @@ -64,7 +63,7 @@ exports.getModule = class MessageListModule extends MessageAreaConfTempSwitcher( const modOpts = { extraArgs : { - messageAreaTag : this.getSelectedAreaTag(formData.value.message),// this.config.messageAreaTag, + messageAreaTag : this.getSelectedAreaTag(formData.value.message), messageList : this.config.messageList, messageIndex : formData.value.message, lastMessageNextExit : true, @@ -135,6 +134,13 @@ exports.getModule = class MessageListModule extends MessageAreaConfTempSwitcher( const msgListView = this.viewControllers.allViews.getView(MciViewIds.allViews.msgList); this.enableMessageListIndexUpdates(msgListView); return cb(null); + }, + markAllRead : (formData, extraArgs, cb) => { + if(this.config.noUpdateLastReadId) { + return cb(null); + } + + return this.markAllMessagesAsRead(cb); } }; } @@ -295,6 +301,48 @@ exports.getModule = class MessageListModule extends MessageAreaConfTempSwitcher( msgListView.on('index update', idx => this.populateCustomLabelsForSelected(idx) ); } + markAllMessagesAsRead(cb) { + if(!this.config.messageList || this.config.messageList.length === 0) { + return cb(null); // nothing to do. + } + + // + // Generally we'll have a message list for a specific area, + // but this is not always the case. For a given area, we need + // to find the highest message ID in the list to set a + // last read pointer. + // + const areaHighestIds = {}; + this.config.messageList.forEach(msg => { + const highestId = areaHighestIds[msg.areaTag]; + if(highestId) { + if(msg.messageId > highestId) { + areaHighestIds[msg.areaTag] = msg.messageId; + } + } else { + areaHighestIds[msg.areaTag] = msg.messageId; + } + }); + + async.forEachOf(areaHighestIds, (highestId, areaTag, nextArea) => { + messageArea.updateMessageAreaLastReadId( + this.client.user.userId, + areaTag, + highestId, + err => { + if(err) { + this.client.log.warn( { error : err.message }, 'Failed marking area as read'); + } else { + this.client.log.info( { highestId, areaTag }, 'User marked area as read'); + } + return nextArea(null); // always continue + } + ); + }, () => { + return cb(null); + }); + } + updateMessageNumbersAfterDelete(startIndex) { // all index -= 1 from this point on. for(let i = startIndex; i < this.config.messageList.length; ++i) {