From f9cf98438163eb2380906033d599ad1554bda1a2 Mon Sep 17 00:00:00 2001 From: Tyler Brown Cifu Shuster Date: Tue, 8 Sep 2020 15:20:40 -0700 Subject: [PATCH] chat: prevent message rerender --- .../apps/chat/components/lib/chat-message.tsx | 165 +++++++++--------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/components/lib/chat-message.tsx b/pkg/interface/src/views/apps/chat/components/lib/chat-message.tsx index 12174803a..e29e18802 100644 --- a/pkg/interface/src/views/apps/chat/components/lib/chat-message.tsx +++ b/pkg/interface/src/views/apps/chat/components/lib/chat-message.tsx @@ -5,87 +5,88 @@ import { Message } from "./message"; import { Envelope } from "~/types/chat-update"; import _ from "lodash"; -export const ChatMessage = (props) => { - const { - msg, - previousMsg, - nextMsg, - isFirstUnread, - group, - association, - contacts, - unreadRef, - hideAvatars, - hideNicknames, - remoteContentPolicy, - className = '' - } = props; - - // Render sigil if previous message is not by the same sender - const aut = ["author"]; - const renderSigil = - _.get(nextMsg, aut) !== _.get(msg, aut, msg.author); - const paddingTop = renderSigil; - const paddingBot = - _.get(previousMsg, aut) !== _.get(msg, aut, msg.author); - - const when = ["when"]; - const dayBreak = - moment(_.get(nextMsg, when)).format("YYYY.MM.DD") !== - moment(_.get(msg, when)).format("YYYY.MM.DD"); - - const messageElem = ( - - ); - - if (isFirstUnread) { - return ( - - {messageElem} -
-
-

New messages below

-
- {dayBreak && ( -

- {moment(_.get(msg, when)).calendar()} -

- )} -
-
-
+export class ChatMessage extends PureComponent { + render() { + const { + msg, + previousMsg, + nextMsg, + isFirstUnread, + group, + association, + contacts, + unreadRef, + hideAvatars, + hideNicknames, + remoteContentPolicy, + className = '' + } = this.props; + + // Render sigil if previous message is not by the same sender + const aut = ["author"]; + const renderSigil = + _.get(nextMsg, aut) !== _.get(msg, aut, msg.author); + const paddingTop = renderSigil; + const paddingBot = + _.get(previousMsg, aut) !== _.get(msg, aut, msg.author); + + const when = ["when"]; + const dayBreak = + moment(_.get(nextMsg, when)).format("YYYY.MM.DD") !== + moment(_.get(msg, when)).format("YYYY.MM.DD"); + + const messageElem = ( + ); - } else if (dayBreak) { - return ( - -
-

{moment(_.get(msg, when)).calendar()}

-
- {messageElem} -
- ); - } else { - return messageElem; + + if (isFirstUnread) { + return ( + + {messageElem} +
+
+

New messages below

+
+ {dayBreak && ( +

+ {moment(_.get(msg, when)).calendar()} +

+ )} +
+
+
+ ); + } else if (dayBreak) { + return ( + +
+

{moment(_.get(msg, when)).calendar()}

+
+ {messageElem} +
+ ); + } else { + return messageElem; + } } -}; - +} \ No newline at end of file