Skip to content

Commit

Permalink
Merge pull request #2830 from GetStream/develop
Browse files Browse the repository at this point in the history
Next Release
  • Loading branch information
isekovanic authored Dec 5, 2024
2 parents b52c1df + 79542d8 commit 3a4f7c7
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 42 deletions.
2 changes: 2 additions & 0 deletions examples/SampleApp/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createStackNavigator } from '@react-navigation/stack';
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
import {
Chat,
MessageType,
OverlayProvider,
QuickSqliteClient,
ThemeProvider,
Expand Down Expand Up @@ -182,6 +183,7 @@ const DrawerNavigatorWrapper: React.FC<{
enableOfflineSupport
// @ts-expect-error
ImageComponent={FastImage}
isMessageAIGenerated={(message: MessageType) => message.ai_generated}
>
<AppOverlayProvider>
<UserSearchProvider>
Expand Down
25 changes: 5 additions & 20 deletions examples/SampleApp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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.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==
stream-chat-react-native-core@5.44.0:
version "5.44.0"
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.44.0.tgz#2d3f8b8ca8a15b6f15fa03bea099e706e4c88e79"
integrity sha512-gN7/aaDvESPc2s7d6xyCTu4vpiok1HCwcNiHxvNC2NlvL0O5xd/7240L+eoSPhECXTPZvCgVJVEra9CWMM4pXw==
dependencies:
"@gorhom/bottom-sheet" "^4.6.4"
dayjs "1.10.5"
Expand All @@ -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.45.1"
stream-chat "8.46.0"

"stream-chat-react-native-core@link:../../package":
version "0.0.0"
Expand All @@ -6863,21 +6863,6 @@ [email protected]:
version "0.0.0"
uid ""

[email protected]:
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"
"@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.46.0"
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-8.46.0.tgz#416b325e05b144d0937a3527d1e622463113d605"
Expand Down
8 changes: 7 additions & 1 deletion package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { useCreateTypingContext } from './hooks/useCreateTypingContext';

import { useTargetedMessage } from './hooks/useTargetedMessage';

import { MessageContextValue } from '../../contexts';
import { ChannelContextValue, ChannelProvider } from '../../contexts/channelContext/ChannelContext';
import type { UseChannelStateValue } from '../../contexts/channelsStateContext/useChannelState';
import { useChannelState } from '../../contexts/channelsStateContext/useChannelState';
Expand Down Expand Up @@ -338,6 +339,7 @@ export type ChannelPropsWithContext<
| 'StreamingMessageView'
>
> &
Partial<Pick<MessageContextValue<StreamChatGenerics>, 'isMessageAIGenerated'>> &
Partial<Pick<ThreadContextValue<StreamChatGenerics>, 'allowThreadMessagesInChannel'>> & {
shouldSyncChannel: boolean;
thread: ThreadType<StreamChatGenerics>;
Expand Down Expand Up @@ -532,6 +534,7 @@ const ChannelWithContext = <
InputGiphySearch = InputGiphyCommandInputDefault,
InputReplyStateHeader = InputReplyStateHeaderDefault,
isAttachmentEqual,
isMessageAIGenerated = () => false,
keyboardBehavior,
KeyboardCompatibleView = KeyboardCompatibleViewDefault,
keyboardVerticalOffset,
Expand Down Expand Up @@ -2424,6 +2427,7 @@ const ChannelWithContext = <
InlineDateSeparator,
InlineUnreadIndicator,
isAttachmentEqual,
isMessageAIGenerated,
legacyImageViewerSwipeBehaviour,
markdownRules,
Message,
Expand Down Expand Up @@ -2559,7 +2563,8 @@ export const Channel = <
>(
props: PropsWithChildren<ChannelProps<StreamChatGenerics>>,
) => {
const { client, enableOfflineSupport } = useChatContext<StreamChatGenerics>();
const { client, enableOfflineSupport, isMessageAIGenerated } =
useChatContext<StreamChatGenerics>();
const { t } = useTranslationContext();

const threadFromProps = props?.thread;
Expand Down Expand Up @@ -2605,6 +2610,7 @@ export const Channel = <
{...props}
shouldSyncChannel={shouldSyncChannel}
{...{
isMessageAIGenerated,
members,
messages: props.messages || messages,
read,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const useCreateMessagesContext = <
InlineDateSeparator,
InlineUnreadIndicator,
isAttachmentEqual,
isMessageAIGenerated,
legacyImageViewerSwipeBehaviour,
markdownRules,
Message,
Expand Down Expand Up @@ -152,6 +153,7 @@ export const useCreateMessagesContext = <
InlineDateSeparator,
InlineUnreadIndicator,
isAttachmentEqual,
isMessageAIGenerated,
legacyImageViewerSwipeBehaviour,
markdownRules,
Message,
Expand Down
9 changes: 8 additions & 1 deletion package/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ init();
export type ChatProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> &
Partial<Pick<ChatContextValue<StreamChatGenerics>, 'ImageComponent' | 'resizableCDNHosts'>> & {
Partial<
Pick<
ChatContextValue<StreamChatGenerics>,
'ImageComponent' | 'resizableCDNHosts' | 'isMessageAIGenerated'
>
> & {
/**
* When false, ws connection won't be disconnection upon backgrounding the app.
* To receive push notifications, its necessary that user doesn't have active
Expand Down Expand Up @@ -149,6 +154,7 @@ const ChatWithContext = <
enableOfflineSupport = false,
i18nInstance,
ImageComponent = Image,
isMessageAIGenerated,
LoadingIndicator = null,
resizableCDNHosts = ['.stream-io-cdn.com'],
style,
Expand Down Expand Up @@ -250,6 +256,7 @@ const ChatWithContext = <
connectionRecovering,
enableOfflineSupport,
ImageComponent,
isMessageAIGenerated,
isOnline,
mutedUsers,
resizableCDNHosts,
Expand Down
2 changes: 2 additions & 0 deletions package/src/components/Chat/hooks/useCreateChatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const useCreateChatContext = <
connectionRecovering,
enableOfflineSupport,
ImageComponent,
isMessageAIGenerated,
isOnline,
mutedUsers,
resizableCDNHosts,
Expand All @@ -33,6 +34,7 @@ export const useCreateChatContext = <
connectionRecovering,
enableOfflineSupport,
ImageComponent,
isMessageAIGenerated,
isOnline,
mutedUsers,
resizableCDNHosts,
Expand Down
23 changes: 18 additions & 5 deletions package/src/components/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,16 @@ export type MessagePropsWithContext<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Pick<ChannelContextValue<StreamChatGenerics>, 'channel' | 'enforceUniqueReaction' | 'members'> &
Pick<KeyboardContextValue, 'dismissKeyboard'> &
Partial<Omit<MessageContextValue<StreamChatGenerics>, 'groupStyles' | 'message'>> &
Pick<MessageContextValue<StreamChatGenerics>, 'groupStyles' | 'message'> &
Partial<
Omit<
MessageContextValue<StreamChatGenerics>,
'groupStyles' | 'message' | 'isMessageAIGenerated'
>
> &
Pick<
MessageContextValue<StreamChatGenerics>,
'groupStyles' | 'message' | 'isMessageAIGenerated'
> &
Pick<
MessagesContextValue<StreamChatGenerics>,
| 'sendReaction'
Expand Down Expand Up @@ -305,6 +313,11 @@ const MessageWithContext = <
threadList = false,
updateMessage,
} = props;
const isMessageAIGenerated = messagesContext.isMessageAIGenerated;
const isAIGenerated = useMemo(
() => isMessageAIGenerated(message),
[message, isMessageAIGenerated],
);
const { client } = chatContext;
const {
theme: {
Expand Down Expand Up @@ -457,7 +470,7 @@ const MessageWithContext = <
case 'poll':
return !!message.poll_id;
case 'ai_text':
return !!message.ai_generated;
return isAIGenerated;
case 'text':
default:
return !!message.text;
Expand Down Expand Up @@ -704,6 +717,7 @@ const MessageWithContext = <
hasReactions,
images: attachments.images,
isEditedMessageOpen,
isMessageAIGenerated,
isMyMessage,
lastGroupMessage: groupStyles?.[0] === 'single' || groupStyles?.[0] === 'bottom',
lastReceivedId,
Expand Down Expand Up @@ -865,8 +879,7 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
prevMessage.text === nextMessage.text &&
prevMessage.pinned === nextMessage.pinned &&
`${prevMessage?.updated_at}` === `${nextMessage?.updated_at}` &&
prevMessage.i18n === nextMessage.i18n &&
prevMessage.ai_generated === nextMessage.ai_generated;
prevMessage.i18n === nextMessage.i18n;

if (!messageEqual) return false;

Expand Down
18 changes: 13 additions & 5 deletions package/src/components/Message/MessageSimple/MessageContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import {
AnimatableNumericValue,
LayoutChangeEvent,
Expand Down Expand Up @@ -82,6 +82,7 @@ export type MessageContentPropsWithContext<
| 'preventPress'
| 'showMessageStatus'
| 'threadList'
| 'isMessageAIGenerated'
> &
Pick<
MessagesContextValue<StreamChatGenerics>,
Expand Down Expand Up @@ -122,6 +123,7 @@ const MessageContentWithContext = <
Gallery,
groupStyles,
hasReactions,
isMessageAIGenerated,
isMyMessage,
lastGroupMessage,
members,
Expand Down Expand Up @@ -186,6 +188,11 @@ const MessageContentWithContext = <
setMessageContentWidth(width);
};

const isAIGenerated = useMemo(
() => isMessageAIGenerated(message),
[message, isMessageAIGenerated],
);

const error = message.type === 'error' || message.status === MessageStatusTypes.FAILED;

const groupStyle = `${alignment}_${groupStyles?.[0]?.toLowerCase?.()}`;
Expand Down Expand Up @@ -396,15 +403,15 @@ const MessageContentWithContext = <
) : null;
}
case 'ai_text':
return message.ai_generated ? (
return isAIGenerated ? (
<StreamingMessageView
key={`ai_message_text_container_${messageContentOrderIndex}`}
/>
) : null;
case 'text':
default:
return (otherAttachments.length && otherAttachments[0].actions) ||
message.ai_generated ? null : (
isAIGenerated ? null : (
<MessageTextContainer<StreamChatGenerics>
key={`message_text_container_${messageContentOrderIndex}`}
/>
Expand Down Expand Up @@ -493,8 +500,7 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
prevMessage.type === nextMessage.type &&
prevMessage.text === nextMessage.text &&
prevMessage.pinned === nextMessage.pinned &&
prevMessage.i18n === nextMessage.i18n &&
prevMessage.ai_generated === nextMessage.ai_generated;
prevMessage.i18n === nextMessage.i18n;
if (!messageEqual) return false;

const isPrevQuotedMessageTypeDeleted = prevMessage.quoted_message?.type === 'deleted';
Expand Down Expand Up @@ -577,6 +583,7 @@ export const MessageContent = <
groupStyles,
hasReactions,
isEditedMessageOpen,
isMessageAIGenerated,
isMyMessage,
lastGroupMessage,
lastReceivedId,
Expand Down Expand Up @@ -624,6 +631,7 @@ export const MessageContent = <
hasReactions,
isAttachmentEqual,
isEditedMessageOpen,
isMessageAIGenerated,
isMyMessage,
lastGroupMessage,
lastReceivedId,
Expand Down
13 changes: 11 additions & 2 deletions package/src/components/Message/MessageSimple/MessageFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { StyleSheet, Text, View } from 'react-native';

import type { Attachment } from 'stream-chat';
Expand Down Expand Up @@ -41,6 +41,7 @@ type MessageFooterPropsWithContext<
| 'otherAttachments'
| 'showMessageStatus'
| 'lastGroupMessage'
| 'isMessageAIGenerated'
> &
Pick<
MessagesContextValue<StreamChatGenerics>,
Expand Down Expand Up @@ -94,6 +95,7 @@ const MessageFooterWithContext = <
formattedDate,
isDeleted,
isEditedMessageOpen,
isMessageAIGenerated,
lastGroupMessage,
members,
message,
Expand All @@ -114,6 +116,11 @@ const MessageFooterWithContext = <
} = useTheme();
const { t } = useTranslationContext();

const isAIGenerated = useMemo(
() => isMessageAIGenerated(message),
[message, isMessageAIGenerated],
);

if (isDeleted) {
return (
<View style={[styles.container, metaContainer]} testID='message-deleted'>
Expand All @@ -129,7 +136,7 @@ const MessageFooterWithContext = <
return null;
}

const isEdited = isEditedMessage(message);
const isEdited = isEditedMessage(message) && !isAIGenerated;

return (
<>
Expand Down Expand Up @@ -267,6 +274,7 @@ export const MessageFooter = <
const {
alignment,
isEditedMessageOpen,
isMessageAIGenerated,
lastGroupMessage,
members,
message,
Expand All @@ -283,6 +291,7 @@ export const MessageFooter = <
alignment,
deletedMessagesVisibilityType,
isEditedMessageOpen,
isMessageAIGenerated,
lastGroupMessage,
members,
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
prevMessage.type === nextMessage.type &&
prevMessage.text === nextMessage.text &&
prevMessage.i18n === nextMessage.i18n &&
prevMessage.pinned === nextMessage.pinned &&
prevMessage.ai_generated === nextMessage.ai_generated;
prevMessage.pinned === nextMessage.pinned;
if (!messageEqual) return false;

const isPrevQuotedMessageTypeDeleted = prevMessage.quoted_message?.type === 'deleted';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useCreateMessageContext = <
hasReactions,
images,
isEditedMessageOpen,
isMessageAIGenerated,
isMyMessage,
lastGroupMessage,
lastReceivedId,
Expand Down Expand Up @@ -78,6 +79,7 @@ export const useCreateMessageContext = <
hasReactions,
images,
isEditedMessageOpen,
isMessageAIGenerated,
isMyMessage,
lastGroupMessage,
lastReceivedId,
Expand Down
Loading

0 comments on commit 3a4f7c7

Please sign in to comment.