@@ -56,13 +56,9 @@ const ChatMessageList = (props: { messages: Message[]; darkMode: boolean }) => {
5656 />
5757 )
5858}
59- const ChatMessageListMemo = React . memo (
60- ChatMessageList ,
61- ( prevProps , nextProps ) => prevProps . messages === nextProps . messages
62- )
59+ const ChatMessageListMemo = React . memo ( ChatMessageList ) // Shallow prop compare.
6360
64- const createErrorHandler = (
65- color : string ,
61+ const errorHandler = (
6662 addMessage : ( text : MinecraftChat ) => void ,
6763 translated : string
6864) => ( error : unknown ) => {
@@ -89,7 +85,6 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => {
8985 connection && connection . connection . options . protocolVersion >= 306 // 16w38a
9086 ? 256
9187 : 100
92- const colorMap = darkMode ? mojangColorMap : lightColorMap
9388 const addMessage = ( text : MinecraftChat ) =>
9489 setMessages ( m => {
9590 const trunc = m . length > 500 ? m . slice ( 0 , 499 ) : m
@@ -103,23 +98,18 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => {
10398 if ( ! loggedInRef . current && connection . connection . loggedIn ) {
10499 setLoggedIn ( true )
105100 loggedInRef . current = true
106- const errorHandler = createErrorHandler (
107- colorMap . dark_red ,
108- addMessage ,
109- sendMessageErr
110- )
111101 if ( settings . sendJoinMessage ) {
112102 connection . connection
113103 . writePacket (
114104 0x03 ,
115105 concatPacketData ( [ settings . joinMessage . substring ( charLimit ) ] )
116106 )
117- . catch ( errorHandler )
107+ . catch ( errorHandler ( addMessage , sendMessageErr ) )
118108 }
119109 if ( settings . sendSpawnCommand ) {
120110 connection . connection
121111 . writePacket ( 0x03 , concatPacketData ( [ '/spawn' ] ) )
122- . catch ( errorHandler )
112+ . catch ( errorHandler ( addMessage , sendMessageErr ) )
123113 }
124114 } else if ( packet . id === 0x0f ) {
125115 try {
@@ -133,15 +123,14 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => {
133123 addMessage ( parseValidJson ( chatJson ) )
134124 }
135125 } catch ( e ) {
136- createErrorHandler ( colorMap . dark_red , addMessage , parseMessageErr ) ( e )
126+ errorHandler ( addMessage , parseMessageErr ) ( e )
137127 }
138128 }
139129 } )
140130 return ( ) => {
141131 connection . connection . removeAllListeners ( 'packet' )
142132 }
143133 } , [
144- colorMap ,
145134 charLimit ,
146135 connection ,
147136 settings . joinMessage ,
@@ -169,7 +158,7 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => {
169158 if ( trim . startsWith ( '/' ) ) setCommandHistory ( ch => ch . concat ( [ trim ] ) )
170159 connection . connection
171160 . writePacket ( 0x03 , concatPacketData ( [ trim ] ) )
172- . catch ( createErrorHandler ( colorMap . dark_red , addMessage , sendMessageErr ) )
161+ . catch ( errorHandler ( addMessage , sendMessageErr ) )
173162 }
174163
175164 if ( ! connection ) return < > </ > // This should never be hit hopefully.
0 commit comments