Skip to content

Commit 10fdae5

Browse files
committed
early return of nonSelfUsers in order to avoid too much optional chaining on filterTypingUsers
1 parent 7ce726e commit 10fdae5

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/components/MessageList/utils/filterTypingUsers.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ChatContextValue } from '../../../contexts/chatContext/ChatContext';
2-
import type { TypingContextValue } from '../../../contexts/typingContext/TypingContext';
32
import type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';
3+
import type { TypingContextValue } from '../../../contexts/typingContext/TypingContext';
44
import type {
55
DefaultAttachmentType,
66
DefaultChannelType,
@@ -37,24 +37,29 @@ export const filterTypingUsers = <
3737
thread,
3838
typing,
3939
}: FilterTypingUsersParams<At, Ch, Co, Ev, Me, Re, Us>) => {
40-
const typingKeys = Object.keys(typing);
4140
const nonSelfUsers: string[] = [];
41+
42+
if (!client || !client.user || !typing) return nonSelfUsers;
43+
44+
const typingKeys = Object.keys(typing);
45+
4246
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) {
4551
return;
4652
}
4753

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;
5056

51-
// filters different threads events
57+
/** filters different threads events */
5258
if (!isRegularEvent && !isCurrentThreadEvent) {
5359
return;
5460
}
5561

56-
const user =
57-
typing?.[typingKey]?.user?.name || typing?.[typingKey]?.user?.id;
62+
const user = typing[typingKey].user?.name || typing[typingKey].user?.id;
5863
if (user) {
5964
nonSelfUsers.push(user);
6065
}

0 commit comments

Comments
 (0)