-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2823 from GetStream/develop
Next Release
- Loading branch information
Showing
49 changed files
with
681 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7310,10 +7310,10 @@ [email protected], stream-buffers@~2.2.0: | |
version "0.0.0" | ||
uid "" | ||
|
||
stream-chat-react-native-core@5.42.2: | ||
version "5.42.2" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.42.2.tgz#edb92b490d4beb894ba549c7deefc770f501360c" | ||
integrity sha512-eA2fK3eYdhr2RSbB22s1ha29y4EPbj9yPAskWxGo1aJK+KXwXDlAYqGtJa/8saRSSU4DdV89yG5ihvTFgP+Huw== | ||
stream-chat-react-native-core@5.43.1: | ||
version "5.43.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.43.1.tgz#ec0d5a06e329c8991c46cff5bd0211bc94d2b26f" | ||
integrity sha512-qj/WfjFeCCP2wcp1YZGFJgRYGdSWXd0maG3hn3oURgFR6p/BmO6lDL2g3jnLq0SEkD8x+KZeNBS9cs1gW5Gblw== | ||
dependencies: | ||
"@gorhom/bottom-sheet" "^4.6.4" | ||
dayjs "1.10.5" | ||
|
@@ -7326,27 +7326,12 @@ [email protected]: | |
path "0.12.7" | ||
react-native-markdown-package "1.8.2" | ||
react-native-url-polyfill "^1.3.0" | ||
stream-chat "8.44.0" | ||
stream-chat "8.45.1" | ||
|
||
"stream-chat-react-native-core@link:../../package": | ||
version "0.0.0" | ||
uid "" | ||
|
||
[email protected]: | ||
version "8.44.0" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.44.0.tgz#e48446cf91db786e80a2e7358ac4f1601e5e97f0" | ||
integrity sha512-7HNtimD8sT/51rsFibGcD6uBgKj+vlKyYCZMDzjYQEaEsrLqyAg48dOyNM4L2FTF5aXgo9SlxZr21SPleeA2BA== | ||
dependencies: | ||
"@babel/runtime" "^7.16.3" | ||
"@types/jsonwebtoken" "~9.0.0" | ||
"@types/ws" "^7.4.0" | ||
axios "^1.6.0" | ||
base64-js "^1.5.1" | ||
form-data "^4.0.0" | ||
isomorphic-ws "^4.0.1" | ||
jsonwebtoken "~9.0.0" | ||
ws "^7.5.10" | ||
|
||
[email protected]: | ||
version "8.45.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.45.1.tgz#001f452520602ebffe45f1634b5f5dd1ff036ec5" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6837,10 +6837,10 @@ statuses@~1.5.0: | |
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" | ||
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA== | ||
|
||
stream-chat-react-native-core@5.42.2: | ||
version "5.42.2" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.42.2.tgz#edb92b490d4beb894ba549c7deefc770f501360c" | ||
integrity sha512-eA2fK3eYdhr2RSbB22s1ha29y4EPbj9yPAskWxGo1aJK+KXwXDlAYqGtJa/8saRSSU4DdV89yG5ihvTFgP+Huw== | ||
stream-chat-react-native-core@5.43.2: | ||
version "5.43.2" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.43.2.tgz#b16add60d231509f864d7301ae281c4b4681ff7a" | ||
integrity sha512-pdSaqw1aPHtxH0md7nnw/TLWPIqsb5TKFzGoWYd/cKRAw4pVDvxolSlha8vYSCwz7MmlarfsJPB0TlS9WcGsDQ== | ||
dependencies: | ||
"@gorhom/bottom-sheet" "^4.6.4" | ||
dayjs "1.10.5" | ||
|
@@ -6853,7 +6853,7 @@ [email protected]: | |
path "0.12.7" | ||
react-native-markdown-package "1.8.2" | ||
react-native-url-polyfill "^1.3.0" | ||
stream-chat "8.44.0" | ||
stream-chat "8.45.1" | ||
|
||
"stream-chat-react-native-core@link:../../package": | ||
version "0.0.0" | ||
|
@@ -6863,10 +6863,10 @@ [email protected]: | |
version "0.0.0" | ||
uid "" | ||
|
||
stream-chat@8.44.0: | ||
version "8.44.0" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.44.0.tgz#e48446cf91db786e80a2e7358ac4f1601e5e97f0" | ||
integrity sha512-7HNtimD8sT/51rsFibGcD6uBgKj+vlKyYCZMDzjYQEaEsrLqyAg48dOyNM4L2FTF5aXgo9SlxZr21SPleeA2BA== | ||
stream-chat@8.45.1: | ||
version "8.45.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.45.1.tgz#001f452520602ebffe45f1634b5f5dd1ff036ec5" | ||
integrity sha512-7OMpL2RHUd+PXSWzhTUAIjjXlI9Oqc4HhUBRfc5i6dK+Ug9S5ertb7RvyzGL5N4ITpq/6ZUAwXtTqRaN9+UUkw== | ||
dependencies: | ||
"@babel/runtime" "^7.16.3" | ||
"@types/jsonwebtoken" "~9.0.0" | ||
|
@@ -6878,10 +6878,10 @@ [email protected]: | |
jsonwebtoken "~9.0.0" | ||
ws "^7.5.10" | ||
|
||
stream-chat@8.45.1: | ||
version "8.45.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.45.1.tgz#001f452520602ebffe45f1634b5f5dd1ff036ec5" | ||
integrity sha512-7OMpL2RHUd+PXSWzhTUAIjjXlI9Oqc4HhUBRfc5i6dK+Ug9S5ertb7RvyzGL5N4ITpq/6ZUAwXtTqRaN9+UUkw== | ||
stream-chat@8.46.0: | ||
version "8.46.0" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.46.0.tgz#416b325e05b144d0937a3527d1e622463113d605" | ||
integrity sha512-HQVCRVldrfQFAvsBOHiHR0TKYf+wpsg/cAzRojeZY+buy1vG6eoqk09h6Fl4k2eG3zFLoA0G9W6o7o45jyFE1g== | ||
dependencies: | ||
"@babel/runtime" "^7.16.3" | ||
"@types/jsonwebtoken" "~9.0.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6899,10 +6899,10 @@ statuses@~1.5.0: | |
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" | ||
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA== | ||
|
||
stream-chat-react-native-core@5.42.2: | ||
version "5.42.2" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.42.2.tgz#edb92b490d4beb894ba549c7deefc770f501360c" | ||
integrity sha512-eA2fK3eYdhr2RSbB22s1ha29y4EPbj9yPAskWxGo1aJK+KXwXDlAYqGtJa/8saRSSU4DdV89yG5ihvTFgP+Huw== | ||
stream-chat-react-native-core@5.43.1: | ||
version "5.43.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.43.1.tgz#ec0d5a06e329c8991c46cff5bd0211bc94d2b26f" | ||
integrity sha512-qj/WfjFeCCP2wcp1YZGFJgRYGdSWXd0maG3hn3oURgFR6p/BmO6lDL2g3jnLq0SEkD8x+KZeNBS9cs1gW5Gblw== | ||
dependencies: | ||
"@gorhom/bottom-sheet" "^4.6.4" | ||
dayjs "1.10.5" | ||
|
@@ -6915,7 +6915,7 @@ [email protected]: | |
path "0.12.7" | ||
react-native-markdown-package "1.8.2" | ||
react-native-url-polyfill "^1.3.0" | ||
stream-chat "8.44.0" | ||
stream-chat "8.45.1" | ||
|
||
"stream-chat-react-native-core@link:../../package": | ||
version "0.0.0" | ||
|
@@ -6930,21 +6930,6 @@ stream-chat-react-native-devtools@^1.1.0: | |
version "0.0.0" | ||
uid "" | ||
|
||
[email protected]: | ||
version "8.44.0" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.44.0.tgz#e48446cf91db786e80a2e7358ac4f1601e5e97f0" | ||
integrity sha512-7HNtimD8sT/51rsFibGcD6uBgKj+vlKyYCZMDzjYQEaEsrLqyAg48dOyNM4L2FTF5aXgo9SlxZr21SPleeA2BA== | ||
dependencies: | ||
"@babel/runtime" "^7.16.3" | ||
"@types/jsonwebtoken" "~9.0.0" | ||
"@types/ws" "^7.4.0" | ||
axios "^1.6.0" | ||
base64-js "^1.5.1" | ||
form-data "^4.0.0" | ||
isomorphic-ws "^4.0.1" | ||
jsonwebtoken "~9.0.0" | ||
ws "^7.5.10" | ||
|
||
[email protected]: | ||
version "8.45.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.45.1.tgz#001f452520602ebffe45f1634b5f5dd1ff036ec5" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2929,10 +2929,10 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4" | ||
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg== | ||
|
||
[email protected].1: | ||
version "5.43.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.43.1.tgz#ec0d5a06e329c8991c46cff5bd0211bc94d2b26f" | ||
integrity sha512-qj/WfjFeCCP2wcp1YZGFJgRYGdSWXd0maG3hn3oURgFR6p/BmO6lDL2g3jnLq0SEkD8x+KZeNBS9cs1gW5Gblw== | ||
[email protected].2: | ||
version "5.43.2" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.43.2.tgz#b16add60d231509f864d7301ae281c4b4681ff7a" | ||
integrity sha512-pdSaqw1aPHtxH0md7nnw/TLWPIqsb5TKFzGoWYd/cKRAw4pVDvxolSlha8vYSCwz7MmlarfsJPB0TlS9WcGsDQ== | ||
dependencies: | ||
"@gorhom/bottom-sheet" "^4.6.4" | ||
dayjs "1.10.5" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4244,10 +4244,10 @@ statuses@~1.5.0: | |
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" | ||
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA== | ||
|
||
[email protected].1: | ||
version "5.43.1" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.43.1.tgz#ec0d5a06e329c8991c46cff5bd0211bc94d2b26f" | ||
integrity sha512-qj/WfjFeCCP2wcp1YZGFJgRYGdSWXd0maG3hn3oURgFR6p/BmO6lDL2g3jnLq0SEkD8x+KZeNBS9cs1gW5Gblw== | ||
[email protected].2: | ||
version "5.43.2" | ||
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.43.2.tgz#b16add60d231509f864d7301ae281c4b4681ff7a" | ||
integrity sha512-pdSaqw1aPHtxH0md7nnw/TLWPIqsb5TKFzGoWYd/cKRAw4pVDvxolSlha8vYSCwz7MmlarfsJPB0TlS9WcGsDQ== | ||
dependencies: | ||
"@gorhom/bottom-sheet" "^4.6.4" | ||
dayjs "1.10.5" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
package/src/components/AITypingIndicatorView/AITypingIndicatorView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
|
||
import { StyleSheet, Text, View } from 'react-native'; | ||
|
||
import { Channel } from 'stream-chat'; | ||
|
||
import { AIStates, useAIState } from './hooks/useAIState'; | ||
|
||
import { useChannelContext, useTheme, useTranslationContext } from '../../contexts'; | ||
import type { DefaultStreamChatGenerics } from '../../types/types'; | ||
|
||
export type AITypingIndicatorViewProps< | ||
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, | ||
> = { | ||
channel?: Channel<StreamChatGenerics>; | ||
}; | ||
|
||
export const AITypingIndicatorView = < | ||
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, | ||
>({ | ||
channel: channelFromProps, | ||
}: AITypingIndicatorViewProps<StreamChatGenerics>) => { | ||
const { t } = useTranslationContext(); | ||
const { channel: channelFromContext } = useChannelContext<StreamChatGenerics>(); | ||
const channel = channelFromProps || channelFromContext; | ||
const { aiState } = useAIState(channel); | ||
const allowedStates = { | ||
[AIStates.Thinking]: t('Thinking...'), | ||
[AIStates.Generating]: t('Generating...'), | ||
}; | ||
|
||
const { | ||
theme: { | ||
aiTypingIndicatorView: { container, text }, | ||
colors: { black, grey_gainsboro }, | ||
}, | ||
} = useTheme(); | ||
|
||
return aiState in allowedStates ? ( | ||
<View style={[styles.container, { backgroundColor: grey_gainsboro }, container]}> | ||
<Text style={[{ color: black }, text]}>{allowedStates[aiState]}</Text> | ||
</View> | ||
) : null; | ||
}; | ||
|
||
AITypingIndicatorView.displayName = 'AITypingIndicatorView{messageSimple{content}}'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { paddingHorizontal: 16, paddingVertical: 18 }, | ||
}); |
68 changes: 68 additions & 0 deletions
68
package/src/components/AITypingIndicatorView/hooks/useAIState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { AIState, Channel, Event } from 'stream-chat'; | ||
|
||
import { useChatContext } from '../../../contexts'; | ||
import type { DefaultStreamChatGenerics } from '../../../types/types'; | ||
import { useIsOnline } from '../../Chat/hooks/useIsOnline'; | ||
|
||
export const AIStates = { | ||
Error: 'AI_STATE_ERROR', | ||
ExternalSources: 'AI_STATE_EXTERNAL_SOURCES', | ||
Generating: 'AI_STATE_GENERATING', | ||
Idle: 'AI_STATE_IDLE', | ||
Thinking: 'AI_STATE_THINKING', | ||
}; | ||
|
||
/** | ||
* A hook that returns the current state of the AI. | ||
* @param {Channel} channel - The channel for which we want to know the AI state. | ||
* @returns {{ aiState: AIState }} The current AI state for the given channel. | ||
*/ | ||
export const useAIState = < | ||
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, | ||
>( | ||
channel?: Channel<StreamChatGenerics>, | ||
): { aiState: AIState } => { | ||
const { client } = useChatContext<StreamChatGenerics>(); | ||
const { isOnline } = useIsOnline<StreamChatGenerics>(client); | ||
|
||
const [aiState, setAiState] = useState<AIState>(AIStates.Idle); | ||
|
||
useEffect(() => { | ||
if (!isOnline) { | ||
setAiState(AIStates.Idle); | ||
} | ||
}, [isOnline]); | ||
|
||
useEffect(() => { | ||
if (!channel) { | ||
return; | ||
} | ||
|
||
const indicatorChangedListener = channel.on( | ||
'ai_indicator.update', | ||
(event: Event<StreamChatGenerics>) => { | ||
const { cid } = event; | ||
const state = event.ai_state as AIState; | ||
if (channel.cid === cid) { | ||
setAiState(state); | ||
} | ||
}, | ||
); | ||
|
||
const indicatorClearedListener = channel.on('ai_indicator.clear', (event) => { | ||
const { cid } = event; | ||
if (channel.cid === cid) { | ||
setAiState(AIStates.Idle); | ||
} | ||
}); | ||
|
||
return () => { | ||
indicatorChangedListener.unsubscribe(); | ||
indicatorClearedListener.unsubscribe(); | ||
}; | ||
}, [channel]); | ||
|
||
return { aiState }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './AITypingIndicatorView'; | ||
export * from './hooks/useAIState'; |
Oops, something went wrong.