|
1 | 1 | import type { ChatContextValue } from '../../../contexts/chatContext/ChatContext'; |
2 | | -import type { TypingContextValue } from '../../../contexts/typingContext/TypingContext'; |
3 | 2 | import type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext'; |
| 3 | +import type { TypingContextValue } from '../../../contexts/typingContext/TypingContext'; |
4 | 4 | import type { |
5 | 5 | DefaultAttachmentType, |
6 | 6 | DefaultChannelType, |
@@ -37,24 +37,29 @@ export const filterTypingUsers = < |
37 | 37 | thread, |
38 | 38 | typing, |
39 | 39 | }: FilterTypingUsersParams<At, Ch, Co, Ev, Me, Re, Us>) => { |
40 | | - const typingKeys = Object.keys(typing); |
41 | 40 | const nonSelfUsers: string[] = []; |
| 41 | + |
| 42 | + if (!client || !client.user || !typing) return nonSelfUsers; |
| 43 | + |
| 44 | + const typingKeys = Object.keys(typing); |
| 45 | + |
42 | 46 | typingKeys.forEach((typingKey) => { |
43 | | - // removes own typing events |
44 | | - if (client?.user?.id === typing?.[typingKey]?.user?.id) { |
| 47 | + if (!typing[typingKey]) return; |
| 48 | + |
| 49 | + /** removes own typing events */ |
| 50 | + if (client.user?.id === typing[typingKey].user?.id) { |
45 | 51 | return; |
46 | 52 | } |
47 | 53 |
|
48 | | - const isRegularEvent = !typing?.[typingKey].parent_id && !thread?.id; |
49 | | - const isCurrentThreadEvent = typing?.[typingKey].parent_id === thread?.id; |
| 54 | + const isRegularEvent = !typing[typingKey].parent_id && !thread?.id; |
| 55 | + const isCurrentThreadEvent = typing[typingKey].parent_id === thread?.id; |
50 | 56 |
|
51 | | - // filters different threads events |
| 57 | + /** filters different threads events */ |
52 | 58 | if (!isRegularEvent && !isCurrentThreadEvent) { |
53 | 59 | return; |
54 | 60 | } |
55 | 61 |
|
56 | | - const user = |
57 | | - typing?.[typingKey]?.user?.name || typing?.[typingKey]?.user?.id; |
| 62 | + const user = typing[typingKey].user?.name || typing[typingKey].user?.id; |
58 | 63 | if (user) { |
59 | 64 | nonSelfUsers.push(user); |
60 | 65 | } |
|
0 commit comments