@@ -6,6 +6,8 @@ import {formatTimeForChat} from '@/util/timestamp'
66import { SeparatorMapContext } from './ids-context'
77import { usingFlashList } from '../list-area/flashlist-config'
88import { OrangeLineContext } from '../orange-line-context'
9+ import logger from '@/logger'
10+ import { useChatDebugDump } from '@/constants/chat2/debug'
911
1012const enoughTimeBetweenMessages = ( mtimestamp ?: number , ptimestamp ?: number ) : boolean =>
1113 ! ! ptimestamp && ! ! mtimestamp && mtimestamp - ptimestamp > 1000 * 60 * 15
@@ -43,16 +45,37 @@ const getUsernameToShow = (message: T.Chat.Message, pMessage: T.Chat.Message | u
4345
4446 if ( ! pMessage ) return message . author
4547
48+ if ( pMessage . author !== message . author ) {
49+ return message . author
50+ }
51+ if ( pMessage . botUsername !== message . botUsername ) {
52+ return message . author
53+ }
54+ if ( ! authorIsCollapsible ( message . type ) ) {
55+ return message . author
56+ }
57+ if ( enoughTimeBetweenMessages ( message . timestamp , pMessage . timestamp ) ) {
58+ return message . author
59+ }
60+
4661 if (
47- pMessage . author !== message . author ||
48- pMessage . botUsername !== message . botUsername ||
49- ! authorIsCollapsible ( message . type ) ||
50- ! authorIsCollapsible ( pMessage . type ) ||
51- enoughTimeBetweenMessages ( message . timestamp , pMessage . timestamp )
62+ ! ( message . author || message . botUsername ) ||
63+ ! ( pMessage . author || pMessage . botUsername ) ||
64+ ! message . timestamp ||
65+ ! pMessage . timestamp
5266 ) {
53- return message . author
67+ // something totally wrong
68+ logger . error ( 'CHATDEBUG: getUsernameToShow FAILED' , {
69+ authors : message . author === pMessage . author ,
70+ botUsernames : message . botUsername === pMessage . botUsername ,
71+ mcollapsible : authorIsCollapsible ( message . type ) ,
72+ mtime : message . timestamp ,
73+ pcollapsible : authorIsCollapsible ( pMessage . type ) ,
74+ ptime : pMessage . timestamp ,
75+ } )
76+ return ''
5477 }
55- // should be impossible
78+
5679 return ''
5780}
5881
@@ -190,17 +213,50 @@ const useStateFast = (_trailingItem: T.Chat.Ordinal, _leadingItem: T.Chat.Ordina
190213 }
191214 const you = C . useCurrentUserState ( s => s . username )
192215 const orangeOrdinal = React . useContext ( OrangeLineContext )
193- return C . useChatContext (
216+
217+ const TEMP = React . useRef ( { } )
218+
219+ const ret = C . useChatContext (
194220 C . useShallow ( s => {
195221 const ordinal = trailingItem
196222 const previous = leadingItem
197223 const pmessage = s . messageMap . get ( previous )
198224 const m = s . messageMap . get ( ordinal ) ?? missingMessage
199225 const showUsername = getUsernameToShow ( m , pmessage , you )
200226 const orangeLineAbove = orangeOrdinal === previous && previous > 0
227+ TEMP . current = {
228+ orangeOrdinal,
229+ ordinal,
230+ previous,
231+ showUsername,
232+ // eslint-disable-next-line
233+ mauthor : m . author ,
234+ mbot : m . botUsername ,
235+ mtype : m . type ,
236+ // eslint-disable-next-line
237+ mtime : m . timestamp ,
238+ pauthor : pmessage ?. author ,
239+ pbot : pmessage ?. botUsername ,
240+ ptype : pmessage ?. type ,
241+ // eslint-disable-next-line
242+ ptime : pmessage ?. timestamp ,
243+ // eslint-disable-next-line
244+ msg : ( m as any ) . text ?. stringValue ?.( ) . length ,
245+ // eslint-disable-next-line
246+ pmsg : ( pmessage as any ) ?. text ?. stringValue ?.( ) . length ,
247+ }
201248 return { orangeLineAbove, ordinal, showUsername}
202249 } )
203250 )
251+
252+ useChatDebugDump (
253+ `CHATDEBUGSep${ trailingItem } :` ,
254+ C . useEvent ( ( ) => {
255+ return JSON . stringify ( TEMP . current , null , 2 )
256+ } )
257+ )
258+
259+ return ret
204260}
205261
206262const useState = ( ordinal : T . Chat . Ordinal ) => {
@@ -283,6 +339,7 @@ const SeparatorConnector = React.memo(function SeparatorConnector(p: Props) {
283339 trailingItem ,
284340 leadingItem ?? T . Chat . numberToOrdinal ( 0 )
285341 )
342+
286343 return ordinal && ( showUsername || orangeLineAbove ) ? (
287344 < Separator ordinal = { ordinal } showUsername = { showUsername } orangeLineAbove = { orangeLineAbove } />
288345 ) : null
0 commit comments