Skip to content

Commit d4b9f3e

Browse files
authored
Merge pull request #759 from GetStream/typing-stop-background
fix: Clean user's typing state when app goes to background
2 parents b4e0ec1 + 84045be commit d4b9f3e

File tree

6 files changed

+21
-2
lines changed

6 files changed

+21
-2
lines changed

β€Žpackage/src/components/Channel/Channel.tsxβ€Ž

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
MessageResponse,
1010
SendMessageAPIResponse,
1111
StreamChat,
12+
Event as StreamEvent,
1213
Message as StreamMessage,
1314
} from 'stream-chat';
1415

16+
import { useAppStateListener } from '../../hooks/useAppStateListener';
1517
import { useCreateChannelContext } from './hooks/useCreateChannelContext';
1618
import { useCreateInputMessageInputContext } from './hooks/useCreateInputMessageInputContext';
1719
import { useCreateMessagesContext } from './hooks/useCreateMessagesContext';
@@ -608,6 +610,22 @@ const ChannelWithContext = <
608610
}
609611
}, [threadPropsExists]);
610612

613+
const handleAppBackground = useCallback(() => {
614+
if (channel) {
615+
channel.sendEvent({ parent_id: thread?.id, type: 'typing.stop' } as StreamEvent<
616+
At,
617+
Ch,
618+
Co,
619+
Ev,
620+
Me,
621+
Re,
622+
Us
623+
>);
624+
}
625+
}, [thread?.id, channelId]);
626+
627+
useAppStateListener(undefined, handleAppBackground);
628+
611629
/**
612630
* CHANNEL CONSTANTS
613631
*/

β€Žpackage/src/components/Chat/hooks/useIsOnline.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3-
import { useAppStateListener } from './useAppStateListener';
3+
import { useAppStateListener } from '../../../hooks/useAppStateListener';
44
import { NetInfo } from '../../../native';
55

66
import type { NetInfoSubscription } from '@react-native-community/netinfo';

β€Žpackage/src/components/index.tsβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export * from './ChannelPreview/hooks/useChannelPreviewDisplayPresence';
7070
export * from './ChannelPreview/hooks/useLatestMessagePreview';
7171

7272
export * from './Chat/Chat';
73-
export * from './Chat/hooks/useAppStateListener';
7473
export * from './Chat/hooks/useCreateChatContext';
7574
export * from './Chat/hooks/useIsOnline';
7675
export * from './Chat/hooks/useMutedUsers';

β€Žpackage/src/hooks/index.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useAppStateListener';

β€Žpackage/src/index.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './components';
2+
export * from './hooks';
23
export { registerNativeHandlers, NetInfo } from './native';
34
export * from './contexts';
45
export * from './emoji-data/compiled';

0 commit comments

Comments
Β (0)