Repository navigation
Expand file tree
/
Copy pathdebug.tsx
More file actions
73 lines (67 loc) · 2.16 KB
/
Copy pathdebug.tsx
File metadata and controls
73 lines (67 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Debug utilities for chat
import * as React from 'react'
import * as C from '@/constants'
import type * as T from '@/constants/types'
import logger from '@/logger'
import {debugWarning} from '@/util/debug-warning'
import {registerDebugClear} from '@/util/debug'
export const chatDebugEnabled = false as boolean
if (chatDebugEnabled) {
debugWarning('Debug chat enabled!')
}
const dumpMap = new Map<string, () => string>()
registerDebugClear(() => {
dumpMap.clear()
})
const chatDebugDump = chatDebugEnabled
? (conversationIDKey: T.Chat.ConversationIDKey) => {
const cs = C.getConvoState(conversationIDKey)
logger.error('[CHATDEBUG] os: ', cs.messageOrdinals)
logger.error('[CHATDEBUG] orange: ', cs.orangeAboveOrdinal)
const m = cs.meta
logger.error('[CHATDEBUG] meta: ', {
inboxLocalVersion: m.inboxLocalVersion,
inboxVersion: m.inboxVersion,
maxMsgID: m.maxMsgID,
maxVisibleMsgID: m.maxVisibleMsgID,
offline: m.offline,
readMsgID: m.readMsgID,
status: m.status,
timestamp: m.timestamp,
})
logger.error('[CHATDEBUG] pen: ', [...cs.pendingOutboxToOrdinal.entries()])
logger.error(
'[CHATDEBUG] mm: ',
[...cs.messageMap.entries()].map(([k, v]) => {
const {id, ordinal, submitState, outboxID, type} = v
return {
key: k,
length: type === 'text' ? v.text.stringValue().length : -1,
mid: id,
ordinal,
outboxID,
submitState,
type,
}
})
)
const lines = [...dumpMap.values()]
.reduce((strs, cb) => {
strs.push(cb())
return strs
}, new Array<string>())
.join('\n')
logger.error('[CHATDEBUG]: ', lines)
}
: undefined
export const DebugChatDumpContext = React.createContext({chatDebugDump})
export const useChatDebugDump = chatDebugEnabled
? (key: string, dumpCB: () => string) => {
React.useEffect(() => {
dumpMap.set(key, dumpCB)
return () => {
dumpMap.delete(key)
}
}, [key, dumpCB])
}
: (_key: string, _dumpCB: () => string) => {}