diff --git a/app/(app)/Appointments/MessagingAppointment/ChannelList.tsx b/app/(app)/Appointments/MessagingAppointment/ChannelList.tsx index 0f67c08..7baeaf1 100644 --- a/app/(app)/Appointments/MessagingAppointment/ChannelList.tsx +++ b/app/(app)/Appointments/MessagingAppointment/ChannelList.tsx @@ -2,13 +2,16 @@ import React, { useContext, useEffect, useState } from 'react' import { fetchPatientData } from '@/utils/LoggedInUser'; import { AuthContext } from '@/ctx/AuthContext'; import { - ChannelList + ChannelList, + DefaultStreamChatGenerics } from 'stream-chat-expo' import { useAppContext } from '@/ctx/ChatContext'; import { PatientTypes } from '@/constants/Types'; import {useRouter } from 'expo-router'; +import { ChannelSort } from 'stream-chat'; -const ChannelLists = ({appointmentId}:{appointmentId:any}) => { + +const ChannelLists = ({appointmentId, loggedInUserId}:{appointmentId:any, loggedInUserId:string}) => { const { channel, setChannel } = useAppContext(); const [patientData, setPatientData] = useState(null); const { userId, } = useContext(AuthContext); @@ -28,13 +31,13 @@ const ChannelLists = ({appointmentId}:{appointmentId:any}) => { }; } - const sort = {last_message_at: -1,}; + const sort : ChannelSort = { last_message_at: -1 } const handleNavigateToChannel = (channel: any) => { setChannel(channel); router.push({ pathname: "(app)/Appointments/MessagingAppointment/ChannelScreen", - params: { id: channel?.id, appointmentId }, + params: { chanelId: channel?.id, appointmentId, loggedInUserId}, }); }; @@ -45,7 +48,7 @@ const ChannelLists = ({appointmentId}:{appointmentId:any}) => { filters={filters} sort={sort} /> - + ) } diff --git a/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx b/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx index 6e2f29e..ab90580 100644 --- a/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx +++ b/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx @@ -25,22 +25,31 @@ import { supabase } from "@/lib/supabase"; import { useGlobalSearchParams } from "expo-router"; import Typography from "@/constants/Typography"; import { useModal } from "@/ctx/ModalContext"; +import { StreamChat } from "stream-chat"; const ChannelScreen = () => { - const { theme, changeTheme } = useContext(ThemeContext); + const { theme} = useContext(ThemeContext); const [isloading, setIsLoading] = useState(false); const ios = Platform.OS === "ios"; const modal = useModal(); - const {id,appointmentId} = useGlobalSearchParams(); + const {chanelId,appointmentId, loggedInUserId} = useGlobalSearchParams(); const { channel } = useAppContext(); + const API_KEY = process.env.EXPO_PUBLIC_STREAM_API_KEY; + + const chatClient = StreamChat.getInstance(`${API_KEY}`); + + const disableUser = async () => { + try{ + await chatClient.channel('messaging', `${chanelId}`).removeMembers([`${loggedInUserId}`]) + }catch(error){ + console.log("user not deleted",error); + } + } + - // const deleteChannel = async () => { - // try{ - // await client.deleteChannels([id], {hard_delete: true}); - // }catch(error){} - // } const endAppointment = async() => { try { + disableUser(); setIsLoading(true); const { error } = await supabase .from("appointment") @@ -131,7 +140,6 @@ const ChannelScreen = () => { > (false); const [patientData, setPatientData] = useState(null); const [client, setClient] = useState(null); const { channel, setChannel } = useAppContext(); + const [loggedInUserId , setLoggedInUserId] = useState(""); const { userId } = useContext(AuthContext); const CDNURL = "https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/patients/"; @@ -35,6 +35,7 @@ export function Home() { const setupClient = async () => { try { if (patientData && patientData[0]) { + setLoggedInUserId(patientData[0].id); const user = { id: patientData[0].id, name: `${patientData[0].first_name} ${patientData[0].last_name}`, @@ -66,7 +67,7 @@ export function Home() { // if(client){return async()=> await client.disconnectUser()} }, [patientData]); - return ; + return ; } export default Home; diff --git a/utils/LoggedInUser.ts b/utils/LoggedInUser.ts index 572f7b2..ce8a88c 100644 --- a/utils/LoggedInUser.ts +++ b/utils/LoggedInUser.ts @@ -49,7 +49,6 @@ export async function getPatientData(supabase: any, userInfo: any): Promise return; } patentInfo(data); - console.log(data) } catch (error) { console.error("Error while fetching data:", error); return;