Skip to content

Commit

Permalink
Merge pull request #2800 from GetStream/feat/membership-customization…
Browse files Browse the repository at this point in the history
…-extension

feat: add support for membership customization
  • Loading branch information
isekovanic authored Nov 20, 2024
2 parents 6568ff8 + 14e003f commit d4dbb2b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 48 deletions.
6 changes: 4 additions & 2 deletions examples/ExpoMessaging/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ export type LocalEventType = Record<string, unknown>;
export type LocalMessageType = Record<string, unknown>;
export type LocalReactionType = Record<string, unknown>;
export type LocalUserType = Record<string, unknown>;
type LocalPollOptionType = Record<string, unknown>;
type LocalPollType = Record<string, unknown>;
export type LocalPollOptionType = Record<string, unknown>;
export type LocalPollType = Record<string, unknown>;
export type LocalMemberType = Record<string, unknown>;

export type StreamChatGenerics = {
attachmentType: LocalAttachmentType;
channelType: LocalChannelType;
commandType: LocalCommandType;
eventType: LocalEventType;
memberType: LocalMemberType;
messageType: LocalMessageType;
pollOptionType: LocalPollOptionType;
pollType: LocalPollType;
Expand Down
61 changes: 15 additions & 46 deletions examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,30 @@ 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,
} from 'stream-chat-react-native';

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<MessageInputContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'giphyActive' | 'sendMessage'> & {
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Pick<MessageInputContextValue<StreamChatGenerics>, '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<At, Ch, Co, Ev, Me, Re, Us>,
props: NewDirectMessagingSendButtonPropsWithContext<StreamChatGenerics>,
) => {
const { disabled = false, giphyActive, sendMessage } = props;
const {
Expand All @@ -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<At, Ch, Co, Ev, Me, Re, Us>,
nextProps: NewDirectMessagingSendButtonPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
prevProps: NewDirectMessagingSendButtonPropsWithContext<StreamChatGenerics>,
nextProps: NewDirectMessagingSendButtonPropsWithContext<StreamChatGenerics>,
) => {
const {
disabled: prevDisabled,
Expand Down Expand Up @@ -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<NewDirectMessagingSendButtonPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>>;
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Partial<NewDirectMessagingSendButtonPropsWithContext<StreamChatGenerics>>;

/**
* UI Component for send button in MessageInput component.
*/
export const NewDirectMessagingSendButton = (props: SendButtonProps<StreamChatGenerics>) => {
export const NewDirectMessagingSendButton = (props: SendButtonProps<LocalStreamChatGenerics>) => {
const navigation = useNavigation<NewDirectMessagingScreenNavigationProp>();
const { channel } = useChannelContext<StreamChatGenerics>();
const { channel } = useChannelContext<LocalStreamChatGenerics>();

const { giphyActive, text } = useMessageInputContext<StreamChatGenerics>();
const { giphyActive, text } = useMessageInputContext<LocalStreamChatGenerics>();

const sendMessage = async () => {
if (!channel) {
Expand All @@ -152,7 +121,7 @@ export const NewDirectMessagingSendButton = (props: SendButtonProps<StreamChatGe
};

return (
<MemoizedNewDirectMessagingSendButton<StreamChatGenerics>
<MemoizedNewDirectMessagingSendButton<LocalStreamChatGenerics>
{...{ giphyActive, sendMessage }}
{...props}
{...{ disabled: props.disabled || false }}
Expand Down
2 changes: 2 additions & 0 deletions examples/SampleApp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export type LocalUserType = {
};
type LocalPollOptionType = Record<string, unknown>;
type LocalPollType = Record<string, unknown>;
type LocalMemberType = Record<string, unknown>;

export type StreamChatGenerics = {
attachmentType: LocalAttachmentType;
channelType: LocalChannelType;
commandType: LocalCommandType;
eventType: LocalEventType;
memberType: LocalMemberType;
messageType: LocalMessageType;
pollOptionType: LocalPollOptionType;
pollType: LocalPollType;
Expand Down
2 changes: 2 additions & 0 deletions examples/TypeScriptMessaging/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ type LocalReactionType = Record<string, unknown>;
type LocalUserType = Record<string, unknown>;
type LocalPollOptionType = Record<string, unknown>;
type LocalPollType = Record<string, unknown>;
type LocalMemberType = Record<string, unknown>;

type StreamChatGenerics = {
attachmentType: LocalAttachmentType;
channelType: LocalChannelType;
commandType: LocalCommandType;
eventType: LocalEventType;
memberType: LocalMemberType;
messageType: LocalMessageType;
pollOptionType: LocalPollOptionType;
pollType: LocalPollType;
Expand Down
1 change: 1 addition & 0 deletions package/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface DefaultStreamChatGenerics extends ExtendableGenerics {
channelType: DefaultChannelType;
commandType: LiteralStringForUnion;
eventType: UnknownType;
memberType: UnknownType;
messageType: UnknownType;
reactionType: UnknownType;
userType: DefaultUserType;
Expand Down

0 comments on commit d4dbb2b

Please sign in to comment.