Skip to content

Commit

Permalink
fix: change quotedMessage type to MessageType or undefined (#2527)
Browse files Browse the repository at this point in the history
* fix: change quotedMessage type to MessageType or undefined

* docs: fix lint issues
  • Loading branch information
khushal87 authored Jun 6, 2024
1 parent 9b0367f commit e9f8a52
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Defined with message type if the user is editing some message within `MessageInput` component else its undefined.

| Type |
| ------- |
| Boolean |
| Type |
| ----------------------- |
| `Message`\| `undefined` |
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Message that is quoted to the original message

| Type |
| --------------------------- |
| `Boolean` \| `Message` type |
| Type |
| ----------------------- |
| `Message`\| `undefined` |
6 changes: 3 additions & 3 deletions package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ const ChannelWithContext = <
const [loadingMore, setLoadingMore] = useState(false);

const [loadingMoreRecent, setLoadingMoreRecent] = useState(false);
const [quotedMessage, setQuotedMessage] = useState<boolean | MessageType<StreamChatGenerics>>(
false,
const [quotedMessage, setQuotedMessage] = useState<MessageType<StreamChatGenerics> | undefined>(
undefined,
);
const [thread, setThread] = useState<ThreadContextValue<StreamChatGenerics>['thread']>(
threadProps || null,
Expand Down Expand Up @@ -1946,7 +1946,7 @@ const ChannelWithContext = <
() => setEditing(undefined);

const clearQuotedMessageState: InputMessageInputContextValue<StreamChatGenerics>['clearQuotedMessageState'] =
() => setQuotedMessage(false);
() => setQuotedMessage(undefined);

/**
* Removes the message from local state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ export const useCreateInputMessageInputContext = <
*/
channelId?: string;
}) => {
const editingDep = typeof editing === 'boolean' ? editing : editing?.id;
const quotedMessageId = quotedMessage
? typeof quotedMessage === 'boolean'
? ''
: quotedMessage.id
: '';
const editingDep = editing ? editing.id : '';
const quotedMessageId = quotedMessage ? quotedMessage.id : '';

const inputMessageInputContext: InputMessageInputContextValue<StreamChatGenerics> = useMemo(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const MessageAvatar = <
const { alignment, lastGroupMessage, message, showAvatar } =
useMessageContext<StreamChatGenerics>();
const { ImageComponent } = useChatContext<StreamChatGenerics>();

return (
<MemoizedMessageAvatar
{...{
Expand Down
4 changes: 2 additions & 2 deletions package/src/components/Reply/Reply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ const ReplyWithContext = <
},
} = useTheme();

const messageText = typeof quotedMessage === 'boolean' ? '' : quotedMessage.text || '';
const messageText = quotedMessage ? quotedMessage.text : '';

const emojiOnlyText = useMemo(() => {
if (!messageText) return false;
return hasOnlyEmojis(messageText);
}, [messageText]);

if (typeof quotedMessage === 'boolean') return null;
if (!quotedMessage) return null;

const lastAttachment = quotedMessage.attachments?.slice(-1)[0] as Attachment<StreamChatGenerics>;
const messageType = lastAttachment && getMessageType(lastAttachment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ export type InputMessageInputContextValue<
MoreOptionsButton: React.ComponentType<MoreOptionsButtonProps<StreamChatGenerics>>;
/** Limit on the number of lines in the text input before scrolling */
numberOfLines: number;
quotedMessage: boolean | MessageType<StreamChatGenerics>;
/**
* Custom UI component for send button.
*
Expand Down Expand Up @@ -457,6 +456,7 @@ export type InputMessageInputContextValue<
* Callback that is called when the text input's text changes. Changed text is passed as a single string argument to the callback handler.
*/
onChangeText?: (newText: string) => void;
quotedMessage?: MessageType<StreamChatGenerics>;
SendMessageDisallowedIndicator?: React.ComponentType;
/**
* ref for input setter function
Expand Down Expand Up @@ -906,8 +906,7 @@ export const MessageInputProvider = <
mentioned_users: uniq(mentionedUsers),
/** Parent message id - in case of thread */
parent_id: thread?.id,
quoted_message_id:
typeof value.quotedMessage === 'boolean' ? undefined : value.quotedMessage.id,
quoted_message_id: value.quotedMessage ? value.quotedMessage.id : undefined,
show_in_channel: sendThreadMessageInChannel || undefined,
text: prevText,
...customMessageData,
Expand Down Expand Up @@ -947,8 +946,7 @@ export const MessageInputProvider = <
attachments,
mentioned_users: [],
parent_id: thread?.id,
quoted_message_id:
typeof value.quotedMessage === 'boolean' ? undefined : value.quotedMessage.id,
quoted_message_id: value.quotedMessage ? value.quotedMessage.id : undefined,
show_in_channel: sendThreadMessageInChannel || undefined,
text: '',
} as unknown as Partial<StreamMessage<StreamChatGenerics>>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ export const useCreateMessageInputContext = <
const imageUploadsValue = imageUploads.map(({ state }) => state).join();
const asyncUploadsValue = Object.keys(asyncUploads).join();
const mentionedUsersLength = mentionedUsers.length;
const quotedMessageId = quotedMessage
? typeof quotedMessage === 'boolean'
? ''
: quotedMessage.id
: '';
const quotedMessageId = quotedMessage ? quotedMessage.id : '';
const threadId = thread?.id;
const asyncIdsLength = asyncIds.length;

Expand Down
2 changes: 1 addition & 1 deletion package/src/contexts/messagesContext/MessagesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export type MessagesContextValue<
ScrollToBottomButton: React.ComponentType<ScrollToBottomButtonProps>;
sendReaction: (type: string, messageId: string) => Promise<void>;
setEditingState: (message?: MessageType<StreamChatGenerics>) => void;
setQuotedMessageState: (message: MessageType<StreamChatGenerics> | boolean) => void;
setQuotedMessageState: (message?: MessageType<StreamChatGenerics>) => void;
supportedReactions: ReactionData[];
/**
* UI component for TypingIndicator
Expand Down

0 comments on commit e9f8a52

Please sign in to comment.