Skip to content

Commit

Permalink
fix: create new channel bug
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal87 committed Dec 17, 2024
1 parent f060df9 commit 098df49
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
import { NewDirectMessagingScreenNavigationProp } from '../screens/NewDirectMessagingScreen';

import { StreamChatGenerics as LocalStreamChatGenerics } from '../types';
import { useUserSearchContext } from '../context/UserSearchContext';
import { useAppContext } from '../context/AppContext';

type NewDirectMessagingSendButtonPropsWithContext<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
Expand Down Expand Up @@ -97,24 +99,36 @@ export type SendButtonProps<
* UI Component for send button in MessageInput component.
*/
export const NewDirectMessagingSendButton = (props: SendButtonProps<LocalStreamChatGenerics>) => {
const { chatClient } = useAppContext();
const navigation = useNavigation<NewDirectMessagingScreenNavigationProp>();
const { channel } = useChannelContext<LocalStreamChatGenerics>();
const { selectedUserIds, reset } = useUserSearchContext();

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

const sendMessage = async () => {
if (!channel) {
return;
}
if (!chatClient || !chatClient.user) {
return;
}
const members = [chatClient.user.id, ...selectedUserIds];
channel.initialized = false;
await channel.query({});
const newChannel = chatClient.channel('messaging', {
members,
});
try {
await channel.sendMessage({ text });
await newChannel.watch();
await newChannel.sendMessage({ text });
navigation.replace('ChannelScreen', {
channelId: channel.id,
channelId: newChannel.id,
});
reset();
} catch (e) {
Alert.alert('Error sending a message');
if (e instanceof Error) {
Alert.alert('Error sending a message', e.message);
}
}
};

Expand Down

0 comments on commit 098df49

Please sign in to comment.