From d19f127952025c658e996dfb4f836f830dc23640 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 11 Jun 2021 10:58:09 +0200 Subject: [PATCH] Move message key generation to State.addMessage --- components/app.js | 5 ----- state.js | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/components/app.js b/components/app.js index abf9a71..9379d46 100644 --- a/components/app.js +++ b/components/app.js @@ -45,8 +45,6 @@ const configPromise = fetch("./config.json") const CHATHISTORY_MAX_SIZE = 4000; -let messagesCount = 0; - function parseQueryString() { let query = window.location.search.substring(1); let params = {}; @@ -348,9 +346,6 @@ export default class App extends Component { addMessage(serverID, bufName, msg) { let client = this.clients.get(serverID); - msg.key = messagesCount; - messagesCount++; - msg.isHighlight = irc.isHighlight(msg, client.nick, client.cm); if (!msg.tags) { diff --git a/state.js b/state.js index f54d528..2215ff4 100644 --- a/state.js +++ b/state.js @@ -136,6 +136,7 @@ function insertMessage(list, msg) { let lastServerID = 0; let lastBufferID = 0; +let lastMessageKey = 0; export const State = { updateServer(state, id, updater) { @@ -391,6 +392,9 @@ export const State = { } }, addMessage(state, msg, bufID) { + lastMessageKey++; + msg.key = lastMessageKey; + return State.updateBuffer(state, bufID, (buf) => { let messages = insertMessage(buf.messages, msg); return { messages };