Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for membership customization #2802

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -38,12 +38,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 @@ -82,6 +82,7 @@ export interface DefaultStreamChatGenerics extends ExtendableGenerics {
channelType: DefaultChannelType;
commandType: LiteralStringForUnion;
eventType: UnknownType;
memberType: UnknownType;
messageType: UnknownType;
reactionType: UnknownType;
userType: DefaultUserType;
Expand Down
Loading