From 8442e002f981068303fb3b0a78218cb769fd4f40 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 15 Apr 2022 02:50:25 -0400 Subject: [PATCH] Pad: Use the Stream library to improve readability --- src/node/db/Pad.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 3011ec68e..920d1661f 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -327,8 +327,8 @@ class Pad { * interval as is typical in code. */ async getChatMessages(start, end) { - const entries = await Promise.all( - [...Array(end + 1 - start).keys()].map((i) => this.getChatMessage(start + i))); + const entries = + await Promise.all(Stream.range(start, end + 1).map(this.getChatMessage.bind(this))); // sort out broken chat entries // it looks like in happened in the past that the chat head was @@ -385,8 +385,8 @@ class Pad { await Promise.all((function* () { yield copyRecord(''); - for (let i = 0; i <= this.head; ++i) yield copyRecord(`:revs:${i}`); - for (let i = 0; i <= this.chatHead; ++i) yield copyRecord(`:chat:${i}`); + yield* Stream.range(0, this.head + 1).map((i) => copyRecord(`:revs:${i}`)); + yield* Stream.range(0, this.chatHead + 1).map((i) => copyRecord(`:chat:${i}`)); yield this.copyAuthorInfoToDestinationPad(destinationID); if (destGroupID) yield db.setSub(`group:${destGroupID}`, ['pads', destinationID], 1); }).call(this));