diff --git a/mobile/src/components/features/chat-space/ChatInterface.tsx b/mobile/src/components/features/chat-space/ChatInterface.tsx index f09350fb9..af69ae2d6 100644 --- a/mobile/src/components/features/chat-space/ChatInterface.tsx +++ b/mobile/src/components/features/chat-space/ChatInterface.tsx @@ -1,6 +1,6 @@ import { IonHeader, IonFooter, IonContent, useIonViewWillEnter, IonBackButton, IonButton, IonIcon, IonSpinner } from '@ionic/react' import { useFrappeGetCall } from 'frappe-react-sdk' -import { useMemo, useRef, createContext, useState } from 'react' +import { useMemo, useRef, createContext, useState, useContext } from 'react' import { ErrorBanner } from '../../layout' import { ChatInput } from '../chat-input' import { ChatHeader } from './chat-header' @@ -15,6 +15,8 @@ import { useInView } from 'react-intersection-observer' import { DateSeparator } from './chat-view/DateSeparator' import { MessageBlockItem } from './chat-view/MessageBlock' import ChatViewFirstMessage from './chat-view/ChatViewFirstMessage' +import { UserContext } from '@/utils/auth/UserProvider' +import JoinChannelButton from './JoinChannelButton' export type ChannelMembersMap = Record export const ChannelMembersContext = createContext({}) @@ -76,7 +78,7 @@ export const ChatInterface = ({ channel }: { channel: ChannelListItem | DMChanne const { data: channelMembers } = useFrappeGetCall<{ message: ChannelMembersMap }>('raven.api.chat.get_channel_members', { channel_id: channel.name - }, undefined, { + }, `raven.api.chat.get_channel_members.${channel.name}`, { revalidateOnFocus: false, revalidateIfStale: false, revalidateOnReconnect: false @@ -101,6 +103,16 @@ export const ChatInterface = ({ channel }: { channel: ChannelListItem | DMChanne const [isScrolling, setIsScrolling] = useState(false) + const { currentUser } = useContext(UserContext) + const isUserInChannel = useMemo(() => { + if (currentUser && channelMembers) { + return currentUser in channelMembers.message + } + return false + }, [currentUser, channelMembers]) + + const isDM = channel?.is_direct_message === 1 || channel?.is_self_message === 1 + return ( <> @@ -199,8 +211,11 @@ export const ChatInterface = ({ channel }: { channel: ChannelListItem | DMChanne hidden={!!error} className='block relative z-10 order-1 w-full' > -
: + +
- -
+ > + +
+ } diff --git a/mobile/src/components/features/chat-space/JoinChannelButton.tsx b/mobile/src/components/features/chat-space/JoinChannelButton.tsx new file mode 100644 index 000000000..66c2b61bc --- /dev/null +++ b/mobile/src/components/features/chat-space/JoinChannelButton.tsx @@ -0,0 +1,51 @@ +import { ChannelListItem } from "@/utils/channel/ChannelListProvider" +import { useFrappeCreateDoc, useSWRConfig } from "frappe-react-sdk" +import { Box, Flex, Text, Button } from "@radix-ui/themes" +import { ErrorBanner } from "@/components/layout" +import { useContext } from "react" +import { UserContext } from "@/utils/auth/UserProvider" +interface JoinChannelBoxProps { + channelData: ChannelListItem, +} + +const JoinChannelButton = ({ channelData }: JoinChannelBoxProps) => { + + const { currentUser } = useContext(UserContext) + const { mutate } = useSWRConfig() + const { createDoc, error, loading } = useFrappeCreateDoc() + + const joinChannel = async () => { + return createDoc('Raven Channel Member', { + channel_id: channelData?.name, + user_id: currentUser + }).then(() => { + + mutate(`raven.api.chat.get_channel_members.${channelData.name}`) + }) + } + + return ( + + + + You are not a member of this channel. + + + + ) +} + +export default JoinChannelButton \ No newline at end of file