From ed550b1b058ad884c55369d9116a78ed6900084d Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Wed, 20 Nov 2024 12:58:29 +0100 Subject: [PATCH 1/2] feat: add support for membership customization --- examples/ExpoMessaging/types.ts | 6 +- .../NewDirectMessagingSendButton.tsx | 61 +++++-------------- examples/SampleApp/src/types.ts | 2 + examples/TypeScriptMessaging/App.tsx | 2 + package/src/types/types.ts | 1 + 5 files changed, 24 insertions(+), 48 deletions(-) diff --git a/examples/ExpoMessaging/types.ts b/examples/ExpoMessaging/types.ts index 5128439cb4..6607eb8e63 100644 --- a/examples/ExpoMessaging/types.ts +++ b/examples/ExpoMessaging/types.ts @@ -5,14 +5,16 @@ export type LocalEventType = Record; export type LocalMessageType = Record; export type LocalReactionType = Record; export type LocalUserType = Record; -type LocalPollOptionType = Record; -type LocalPollType = Record; +export type LocalPollOptionType = Record; +export type LocalPollType = Record; +export type LocalMemberType = Record; export type StreamChatGenerics = { attachmentType: LocalAttachmentType; channelType: LocalChannelType; commandType: LocalCommandType; eventType: LocalEventType; + memberType: LocalMemberType; messageType: LocalMessageType; pollOptionType: LocalPollOptionType; pollType: LocalPollType; diff --git a/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx b/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx index a0c8d716aa..78203c5891 100644 --- a/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx +++ b/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx @@ -4,18 +4,11 @@ import { TouchableOpacity } from 'react-native-gesture-handler'; import { useNavigation } from '@react-navigation/core'; import { - DefaultAttachmentType, - DefaultChannelType, - DefaultCommandType, - DefaultEventType, - DefaultMessageType, - DefaultReactionType, - DefaultUserType, + DefaultStreamChatGenerics, MessageInputContextValue, Search, SendRight, SendUp, - UnknownType, useChannelContext, useMessageInputContext, useTheme, @@ -23,30 +16,18 @@ import { import { NewDirectMessagingScreenNavigationProp } from '../screens/NewDirectMessagingScreen'; -import { StreamChatGenerics } from '../types'; +import { StreamChatGenerics as LocalStreamChatGenerics } from '../types'; type NewDirectMessagingSendButtonPropsWithContext< - At extends UnknownType = DefaultAttachmentType, - Ch extends UnknownType = DefaultChannelType, - Co extends string = DefaultCommandType, - Ev extends UnknownType = DefaultEventType, - Me extends UnknownType = DefaultMessageType, - Re extends UnknownType = DefaultReactionType, - Us extends UnknownType = DefaultUserType, -> = Pick, 'giphyActive' | 'sendMessage'> & { + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, +> = Pick, 'giphyActive' | 'sendMessage'> & { /** Disables the button */ disabled: boolean; }; const SendButtonWithContext = < - At extends UnknownType = DefaultAttachmentType, - Ch extends UnknownType = DefaultChannelType, - Co extends string = DefaultCommandType, - Ev extends UnknownType = DefaultEventType, - Me extends UnknownType = DefaultMessageType, - Re extends UnknownType = DefaultReactionType, - Us extends UnknownType = DefaultUserType, + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( - props: NewDirectMessagingSendButtonPropsWithContext, + props: NewDirectMessagingSendButtonPropsWithContext, ) => { const { disabled = false, giphyActive, sendMessage } = props; const { @@ -71,16 +52,10 @@ const SendButtonWithContext = < }; const areEqual = < - At extends UnknownType = DefaultAttachmentType, - Ch extends UnknownType = DefaultChannelType, - Co extends string = DefaultCommandType, - Ev extends UnknownType = DefaultEventType, - Me extends UnknownType = DefaultMessageType, - Re extends UnknownType = DefaultReactionType, - Us extends UnknownType = DefaultUserType, + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, >( - prevProps: NewDirectMessagingSendButtonPropsWithContext, - nextProps: NewDirectMessagingSendButtonPropsWithContext, + prevProps: NewDirectMessagingSendButtonPropsWithContext, + nextProps: NewDirectMessagingSendButtonPropsWithContext, ) => { const { disabled: prevDisabled, @@ -117,23 +92,17 @@ const MemoizedNewDirectMessagingSendButton = React.memo( ) as typeof SendButtonWithContext; export type SendButtonProps< - At extends UnknownType = DefaultAttachmentType, - Ch extends UnknownType = DefaultChannelType, - Co extends string = DefaultCommandType, - Ev extends UnknownType = DefaultEventType, - Me extends UnknownType = DefaultMessageType, - Re extends UnknownType = DefaultReactionType, - Us extends UnknownType = DefaultUserType, -> = Partial>; + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, +> = Partial>; /** * UI Component for send button in MessageInput component. */ -export const NewDirectMessagingSendButton = (props: SendButtonProps) => { +export const NewDirectMessagingSendButton = (props: SendButtonProps) => { const navigation = useNavigation(); - const { channel } = useChannelContext(); + const { channel } = useChannelContext(); - const { giphyActive, text } = useMessageInputContext(); + const { giphyActive, text } = useMessageInputContext(); const sendMessage = async () => { if (!channel) { @@ -152,7 +121,7 @@ export const NewDirectMessagingSendButton = (props: SendButtonProps + {...{ giphyActive, sendMessage }} {...props} {...{ disabled: props.disabled || false }} diff --git a/examples/SampleApp/src/types.ts b/examples/SampleApp/src/types.ts index 25467f87d3..fb95c6a0e4 100644 --- a/examples/SampleApp/src/types.ts +++ b/examples/SampleApp/src/types.ts @@ -17,12 +17,14 @@ export type LocalUserType = { }; type LocalPollOptionType = Record; type LocalPollType = Record; +type LocalMemberType = Record; export type StreamChatGenerics = { attachmentType: LocalAttachmentType; channelType: LocalChannelType; commandType: LocalCommandType; eventType: LocalEventType; + memberType: LocalMemberType; messageType: LocalMessageType; pollOptionType: LocalPollOptionType; pollType: LocalPollType; diff --git a/examples/TypeScriptMessaging/App.tsx b/examples/TypeScriptMessaging/App.tsx index 44bd02155a..7cb110d2af 100644 --- a/examples/TypeScriptMessaging/App.tsx +++ b/examples/TypeScriptMessaging/App.tsx @@ -38,12 +38,14 @@ type LocalReactionType = Record; type LocalUserType = Record; type LocalPollOptionType = Record; type LocalPollType = Record; +type LocalMemberType = Record; type StreamChatGenerics = { attachmentType: LocalAttachmentType; channelType: LocalChannelType; commandType: LocalCommandType; eventType: LocalEventType; + memberType: LocalMemberType; messageType: LocalMessageType; pollOptionType: LocalPollOptionType; pollType: LocalPollType; diff --git a/package/src/types/types.ts b/package/src/types/types.ts index 3ff97c89f6..f9ef9d0ed7 100644 --- a/package/src/types/types.ts +++ b/package/src/types/types.ts @@ -82,6 +82,7 @@ export interface DefaultStreamChatGenerics extends ExtendableGenerics { channelType: DefaultChannelType; commandType: LiteralStringForUnion; eventType: UnknownType; + memberType: UnknownType; messageType: UnknownType; reactionType: UnknownType; userType: DefaultUserType; From 8c39d8697c61b20febaa7d269329b469ce7134ca Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Wed, 20 Nov 2024 13:53:38 +0100 Subject: [PATCH 2/2] fix: lint issues --- .../SampleApp/src/components/NewDirectMessagingSendButton.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx b/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx index 78203c5891..557820c634 100644 --- a/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx +++ b/examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx @@ -51,9 +51,7 @@ const SendButtonWithContext = < ); }; -const areEqual = < - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, ->( +const areEqual = ( prevProps: NewDirectMessagingSendButtonPropsWithContext, nextProps: NewDirectMessagingSendButtonPropsWithContext, ) => {