diff options
author | Gabe Kangas <gabek@real-ity.com> | 2022-01-04 15:04:15 -0800 |
---|---|---|
committer | Gabe Kangas <gabek@real-ity.com> | 2022-01-06 23:02:49 -0800 |
commit | 1cd7040cf4d1c6e14e9a2c6ed04f31362671c8b4 (patch) | |
tree | 327af19cec5b55d0c58d5beffa5c4df3619a9640 | |
parent | 275df9a024214213b2478364070e7b14bc01f29e (diff) |
Break out the sort+render messages logic so it can be fired on visibility change. Closes #1643
-rw-r--r-- | webroot/js/app.js | 1 | ||||
-rw-r--r-- | webroot/js/components/chat/chat.js | 17 |
2 files changed, 7 insertions, 11 deletions
diff --git a/webroot/js/app.js b/webroot/js/app.js index 2386958cf..4ad2dacc8 100644 --- a/webroot/js/app.js +++ b/webroot/js/app.js @@ -177,7 +177,6 @@ export default class App extends Component { this.player.init(); // check routing - console.log('==== did mount'); this.getRoute(); } diff --git a/webroot/js/components/chat/chat.js b/webroot/js/components/chat/chat.js index 164dd9dc7..244ed5e29 100644 --- a/webroot/js/components/chat/chat.js +++ b/webroot/js/components/chat/chat.js @@ -50,10 +50,6 @@ export default class Chat extends Component { this.receivedMessageUpdate = false; this.hasFetchedHistory = false; - // Force render is a state to force the messages to re-render when visibility - // changes for messages. This overrides componentShouldUpdate logic. - this.forceRender = false; - // Unordered dictionary of messages keyed by ID. this.messages = {}; @@ -101,10 +97,6 @@ export default class Chat extends Component { sortedMessages, } = this.state; - if (this.forceRender) { - return true; - } - const { webSocketConnected: nextSocket, chatUserNames: nextUserNames, @@ -227,7 +219,8 @@ export default class Chat extends Component { }; this.messages = updatedMessagesList; - this.forceRender = true; + + this.resortAndRenderMessages(); } handleChangeModeratorStatus(isModerator) { @@ -264,12 +257,16 @@ export default class Chat extends Component { }; this.messages = updatedMessagesList; + this.resortAndRenderMessages(); + } + + resortAndRenderMessages() { // Convert the unordered dictionary of messages to an ordered array. // NOTE: This sorts the entire collection of messages on every new message // because the order a message comes in cannot be trusted that it's the order // it was sent, you need to sort by timestamp. I don't know if there // is a performance problem waiting to occur here for larger chat feeds. - var sortedMessages = Object.values(updatedMessagesList) + var sortedMessages = Object.values(this.messages) // Filter out messages set to not be visible .filter((message) => message.visible !== false) .sort((a, b) => { |