Skip to content

Commit a27e898

Browse files
authored
more f1 logging (keybase#26261)
1 parent e1a517d commit a27e898

7 files changed

Lines changed: 100 additions & 40 deletions

File tree

‎shared/chat/conversation/header-area/container.native.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ export const HeaderAreaRight = () => {
1717

1818
const dumpIcon = chatDebugDump ? (
1919
<>
20-
<Kb.SimpleToast iconType="iconfont-check" text="Logged, send feedback" visible={showToast} />
20+
<Kb.SimpleToast iconType="iconfont-check" text="Logged, send feedback next" visible={showToast} />
2121
<Kb.Icon
2222
type="iconfont-keybase"
2323
onClick={() => {
24-
chatDebugDump()
24+
chatDebugDump(conversationIDKey)
2525
setShowToast(true)
2626
setTimeout(() => {
2727
setShowToast(false)
2828
}, 2000)
2929
}}
30-
style={{marginLeft: -40}}
30+
style={{zIndex: 999}}
3131
/>
3232
</>
3333
) : null

‎shared/chat/conversation/input-area/normal/platform-input.desktop.tsx‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {formatDurationShort} from '@/util/timestamp'
1111
import {useSuggestors} from '../suggestors'
1212
import {ScrollContext} from '@/chat/conversation/normal/context'
1313
import logger from '@/logger'
14+
import {DebugChatDumpContext, chatDebugEnabled} from '@/constants/chat2/debug'
1415

1516
type HtmlInputRefType = React.MutableRefObject<HTMLInputElement | null>
1617
type InputRefType = React.MutableRefObject<Kb.PlainInput | null>
@@ -314,35 +315,24 @@ const SideButtons = (p: SideButtonsProps) => {
314315
const PlatformInput = React.memo(function PlatformInput(p: Props) {
315316
const conversationIDKey = C.useChatContext(s => s.id)
316317

318+
const {chatDebugDump} = React.useContext(DebugChatDumpContext)
319+
317320
// TODO REMOVE
318321
React.useEffect(() => {
322+
if (!chatDebugEnabled) return
319323
logger.error('[CHATDEBUG]: PlatformInput F1 inject')
320324
const onKeydown = (e: KeyboardEvent) => {
321325
if (e.key !== 'F1') {
322326
return
323327
}
324328

325-
const cs = C.getConvoState(conversationIDKey)
326-
logger.error('[CHATDEBUG] os: ', cs.messageOrdinals)
327-
logger.error('[CHATDEBUG] pen: ', cs.pendingOutboxToOrdinal)
328-
cs.messageMap.forEach((v, k) => {
329-
const {id, ordinal, submitState, outboxID, type} = v
330-
logger.error('[CHATDEBUG] mm: ', {
331-
key: k,
332-
length: type === 'text' ? v.text.stringValue().length : -1,
333-
mid: id,
334-
ordinal,
335-
outboxID,
336-
submitState,
337-
type,
338-
})
339-
})
329+
chatDebugDump?.(conversationIDKey)
340330
}
341331
window.addEventListener('keydown', onKeydown)
342332
return () => {
343333
window.removeEventListener('keydown', onKeydown)
344334
}
345-
}, [conversationIDKey])
335+
}, [conversationIDKey, chatDebugDump])
346336
// TODO REMOVE
347337

348338
const {cannotWrite, explodingModeSeconds, onCancelEditing} = p

‎shared/chat/conversation/messages/placeholder/wrapper.tsx‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as React from 'react'
44
import * as T from '@/constants/types'
55
import {WrapperMessage, type Props} from '../wrapper/wrapper'
66
import {ForceListRedrawContext} from '../../force-list-redraw-context'
7-
import {useChatDebugDump} from '@/constants/chat2/debug'
87

98
const noop = () => {}
109

@@ -23,13 +22,6 @@ const WrapperPlaceholder = React.memo(function WrapperPlaceholder(p: Props) {
2322
const type = C.useChatContext(s => s.messageMap.get(ordinal)?.type)
2423
const [lastType, setLastType] = React.useState(type)
2524

26-
useChatDebugDump(
27-
`wrapper${o}`,
28-
C.useEvent(() => {
29-
return `placeholder: ${o}: ${type ?? ''}`
30-
})
31-
)
32-
3325
if (lastType !== type) {
3426
setLastType(type)
3527
if (type !== 'placeholder') {

‎shared/chat/conversation/messages/separator.tsx‎

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {formatTimeForChat} from '@/util/timestamp'
66
import {SeparatorMapContext} from './ids-context'
77
import {usingFlashList} from '../list-area/flashlist-config'
88
import {OrangeLineContext} from '../orange-line-context'
9+
import logger from '@/logger'
10+
import {useChatDebugDump} from '@/constants/chat2/debug'
911

1012
const 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

206262
const 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

‎shared/chat/conversation/normal/container.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const useOrangeLine = () => {
105105
return orangeLineRef.current
106106
}
107107

108-
const WithOrange = React.memo(function WithOrange(p: {orangeLine: number}) {
108+
const WithOrange = React.memo(function WithOrange(p: {orangeLine: T.Chat.Ordinal}) {
109109
return (
110110
<OrangeLineContext.Provider value={p.orangeLine}>
111111
<FocusProvider>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import * as React from 'react'
2-
export const OrangeLineContext = React.createContext(0)
2+
import * as T from '@/constants/types'
3+
export const OrangeLineContext = React.createContext(T.Chat.numberToOrdinal(0))

‎shared/constants/chat2/debug.tsx‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Debug utilities for chat
22
import * as React from 'react'
3+
import * as C from '@/constants'
4+
import type * as T from '@/constants/types'
35
import logger from '@/logger'
46

5-
export const chatDebugEnabled = false as boolean
7+
export const chatDebugEnabled = true as boolean
68

79
if (chatDebugEnabled) {
810
for (let i = 0; i < 10; ++i) {
@@ -13,14 +15,32 @@ if (chatDebugEnabled) {
1315
const dumpMap = new Map<string, () => string>()
1416

1517
const chatDebugDump = chatDebugEnabled
16-
? () => {
18+
? (conversationIDKey: T.Chat.ConversationIDKey) => {
19+
const cs = C.getConvoState(conversationIDKey)
20+
logger.error('[CHATDEBUG] os: ', cs.messageOrdinals)
21+
logger.error('[CHATDEBUG] pen: ', cs.pendingOutboxToOrdinal)
22+
logger.error(
23+
'[CHATDEBUG] mm: ',
24+
[...cs.messageMap.entries()].map(([k, v]) => {
25+
const {id, ordinal, submitState, outboxID, type} = v
26+
return {
27+
key: k,
28+
length: type === 'text' ? v.text.stringValue().length : -1,
29+
mid: id,
30+
ordinal,
31+
outboxID,
32+
submitState,
33+
type,
34+
}
35+
})
36+
)
1737
const lines = [...dumpMap.values()]
1838
.reduce((strs, cb) => {
1939
strs.push(cb())
2040
return strs
2141
}, new Array<string>())
2242
.join('\n')
23-
logger.error('Debug chat dump', lines)
43+
logger.error('[CHATDEBUG]: ', lines)
2444
}
2545
: undefined
2646

0 commit comments

Comments
 (0)