Skip to content

Commit ca4e979

Browse files
authored
Merge pull request #232 from atlp-rwanda/ft-video-call
Feature: Implement Video Call functionalities
2 parents bf0c16e + 792bbe9 commit ca4e979

File tree

21 files changed

+1158
-1422
lines changed

21 files changed

+1158
-1422
lines changed

app/(app)/ActionMenu/Booking/Doctor_details.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,10 @@ const visibleReviews = reviews.slice(0, 1);
548548
)
549549

550550
) : (
551-
<Text style={[Typography.semiBold.large] }> No available reviews</Text>
552-
)}
551+
<Text style={[Typography.semiBold.large,
552+
{color: theme === "dark" ? Colors.others.white : "#212121",}
553+
] }> No available reviews</Text>
554+
)}
553555
</View>
554556
</View>
555557
</View>

app/(app)/ActionMenu/Booking/Select-package.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const SelectPackage = () => {
2929
const { Doctor_id, hour, date,patient_id } = useLocalSearchParams()
3030
const [selectedPackageTitle, setSelectedPackageTitle] = useState<{ title: string, price: string }>({ title: "Messaging", price: "Rwf20" })
3131
const [selectedDuration, setSelectedDuration] = useState<string>("1 hour")
32-
console.log("this is new:", Doctor_id, hour, date)
3332
const handleNextPress = () => {
3433
if (!selectedPackageTitle||!selectedDuration) {
3534
Alert.alert("Please select both Duration and package")

app/(app)/ActionMenu/Booking/SelectPayment.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export default function SelectPayment() {
2323

2424
const modal = useModal()
2525
const flutterKey = process.env.EXPO_PUBLIC_FLUTTERWAVE_KEY ?? ""
26-
console.log("this is packageprice from slect Payment:",packagePrice)
2726

2827
interface RedirectParams {
2928
status: "successful" | "cancelled";
@@ -138,7 +137,10 @@ const total:number=price*num
138137
></View>
139138
<Button
140139
title="View Appointment"
141-
onPress={successBooking}
140+
onPress={()=> {
141+
successBooking()
142+
router.push("(app)/Appointments")
143+
}}
142144
/>
143145
<TouchableOpacity
144146
onPress={() => {

app/(app)/ActionMenu/Booking/reviewSummary.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export default function Reviewsummary() {
5252
}
5353
fetchDoctordata()
5454
}, [doctor_id])
55-
console.log("this is packagePrice:",packagePrice)
5655
let num:number=1;
5756
if (duration === "30 minutes") {
5857
num=1
@@ -423,4 +422,4 @@ const total:number=price*num
423422
</ScrollView>
424423
</>
425424
);
426-
}
425+
}

app/(app)/Appointments/MessagingAppointment/ChannelList.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React, { useContext, useEffect, useState } from 'react'
22
import { fetchPatientData } from '@/utils/LoggedInUser';
33
import { AuthContext } from '@/ctx/AuthContext';
44
import {
5-
ChannelList
6-
} from 'stream-chat-expo'
5+
ChannelList,
6+
DefaultStreamChatGenerics
7+
} from 'stream-chat-expo'
78
import { useAppContext } from '@/ctx/ChatContext';
89
import { PatientTypes } from '@/constants/Types';
910
import {useRouter } from 'expo-router';
10-
11-
const ChannelLists = ({appointmentId}:{appointmentId:any}) => {
11+
import { ChannelSort } from 'stream-chat';
12+
const ChannelLists = ({appointmentId, loggedInUserId, doctorId}:{appointmentId:any, loggedInUserId:string, doctorId:any}) => {
1213
const { channel, setChannel } = useAppContext();
1314
const [patientData, setPatientData] = useState<PatientTypes[] | null>(null);
1415
const { userId, } = useContext(AuthContext);
@@ -28,14 +29,13 @@ const ChannelLists = ({appointmentId}:{appointmentId:any}) => {
2829
};
2930
}
3031

31-
const sort = {last_message_at: -1,};
32-
32+
const sort : ChannelSort<DefaultStreamChatGenerics> = { last_message_at: -1 }
3333
const handleNavigateToChannel = (channel: any) => {
3434
setChannel(channel);
3535
router.push({
3636
pathname: "(app)/Appointments/MessagingAppointment/ChannelScreen",
37-
params: { id: channel?.id, appointmentId },
38-
});
37+
params: { chanelId: channel?.id, appointmentId, loggedInUserId, doctorId},
38+
});
3939
};
4040

4141
return (
@@ -50,5 +50,4 @@ const ChannelLists = ({appointmentId}:{appointmentId:any}) => {
5050
}
5151

5252

53-
export default ChannelLists
54-
53+
export default ChannelLists

app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,31 @@ import { supabase } from "@/lib/supabase";
2525
import { useGlobalSearchParams } from "expo-router";
2626
import Typography from "@/constants/Typography";
2727
import { useModal } from "@/ctx/ModalContext";
28+
import { StreamChat } from "stream-chat";
2829

2930
const ChannelScreen = () => {
3031
const { theme, changeTheme } = useContext(ThemeContext);
3132
const [isloading, setIsLoading] = useState(false);
3233
const ios = Platform.OS === "ios";
3334
const modal = useModal();
34-
const {appointmentId} = useGlobalSearchParams();
35+
const {chanelId,appointmentId, loggedInUserId, doctorId} = useGlobalSearchParams();
3536
const { channel } = useAppContext();
3637

38+
const API_KEY = process.env.EXPO_PUBLIC_STREAM_API_KEY;
39+
40+
const chatClient = StreamChat.getInstance(`${API_KEY}`);
41+
42+
const disableUser = async () => {
43+
try{
44+
await chatClient.channel('messaging', `${chanelId}`).removeMembers([`${loggedInUserId}`])
45+
}catch(error){
46+
console.log("user not deleted",error);
47+
}
48+
}
49+
3750
const endAppointment = async() => {
3851
try {
52+
disableUser();
3953
setIsLoading(true);
4054
const { error } = await supabase
4155
.from("appointment")
@@ -46,7 +60,10 @@ const ChannelScreen = () => {
4660
console.log(error);
4761
} else {
4862
setIsLoading(false);
49-
handlemodal()
63+
router.push({
64+
pathname: "Appointments/MessagingAppointment/SessionEnded",
65+
params: {id: doctorId}
66+
})
5067
}
5168
} catch (error) {
5269
console.log(error);
@@ -58,65 +75,6 @@ const ChannelScreen = () => {
5875
router.push("/(app)/Appointments");
5976
}
6077

61-
async function handlemodal() {
62-
modal.show({
63-
children: (
64-
<View
65-
style={{
66-
padding: 40,
67-
alignItems: "center",
68-
gap: 20,
69-
borderRadius: 48,
70-
backgroundColor:
71-
theme === "light" ? Colors.others.white : Colors.dark._2,
72-
}}
73-
>
74-
<Image source={require("@/assets/images/cancelimg.png")} />
75-
<View
76-
style={{
77-
gap: 20,
78-
backgroundColor:
79-
theme === "light" ? Colors.others.white : Colors.dark._2,
80-
}}
81-
>
82-
<Text
83-
style={[
84-
Typography.heading._4,
85-
{
86-
color: Colors.main.primary._500,
87-
textAlign: "center",
88-
},
89-
]}
90-
>
91-
Chat ended Successfully!
92-
</Text>
93-
<Text
94-
style={[
95-
Typography.regular.large,
96-
{
97-
textAlign: "center",
98-
color:
99-
theme === "light"
100-
? Colors.grayScale._900
101-
: Colors.others.white,
102-
},
103-
]}
104-
>
105-
Thank you for using our service. Your chat has been ended
106-
please go on and provide a review to the doctor.
107-
</Text>
108-
<TouchableOpacity style={styles.btn} onPress={handlebackhome}>
109-
<Text
110-
style={[Typography.bold.large, { color: Colors.others.white }]}
111-
>
112-
Ok
113-
</Text>
114-
</TouchableOpacity>
115-
</View>
116-
</View>
117-
),
118-
});
119-
}
12078
return (
12179
<View
12280
style={{

app/(app)/Appointments/MessagingAppointment/Home.tsx

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ export function Home() {
2121

2222
const { userId } = useContext(AuthContext);
2323

24-
const {id, appointmentId} = useGlobalSearchParams()
25-
const doctorId = id;
2624
const chatRoomId = "matadores-medica"+uuid.v4();
2725

26+
const [loggedInUserId , setLoggedInUserId] = useState<string>("");
27+
const CDNURL =
28+
"https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/patients/";
29+
const { doctorId, appointmentId } = useGlobalSearchParams();
30+
2831
useEffect(() => {
2932
if (userId) {
3033
fetchPatientData(userId, setPatientData);
@@ -35,44 +38,40 @@ export function Home() {
3538

3639
useEffect(() => {
3740
const setupClient = async () => {
38-
try {
39-
if (patientData && patientData[0]) {
40-
const user = {
41-
id: patientData[0].id,
42-
name: `${patientData[0].first_name} ${patientData[0].last_name}`,
43-
image: "https://i.imgur.com/fR9Jz14.png",
44-
};
45-
46-
await chatClient.connectUser(
47-
user,
48-
chatClient.devToken(user.id));
49-
setClientIsReady(true);
50-
setClient(chatClient);
41+
try {
42+
if (patientData && patientData[0]) {
43+
setLoggedInUserId(patientData[0].id);
44+
const user = {
45+
id: patientData[0].id,
46+
name: `${patientData[0].first_name} ${patientData[0].last_name}`,
47+
image: `${CDNURL + patientData[0]?.image}`,
48+
};
49+
await chatClient.connectUser(user, chatClient.devToken(user.id));
5150

52-
const channel = chatClient.channel("messaging", `${chatRoomId}`, {
53-
image: "https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/doctors/adaptive_icon.png",
54-
name: "Medica Chat Room",
55-
members: [user?.id , `${doctorId}`],
56-
});
57-
await channel.watch();
58-
setChannel(channel);
59-
} else {
60-
console.log("No patient data found");
61-
}
62-
} catch (error) {
63-
console.error("An error occurred while connecting the user:", error);
51+
setClientIsReady(true);
52+
setClient(chatClient);
53+
const channel = chatClient.channel("messaging", `${chatRoomId}`, {
54+
image:
55+
"https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/doctors/adaptive_icon.png",
56+
name: `${user?.name} in the chat`,
57+
members: [user?.id, `${doctorId}`],
58+
});
59+
await channel.watch();
60+
setChannel(channel);
61+
} else {
62+
console.log("No patient data found");
6463
}
64+
} catch (error) {
65+
console.error("An error occurred while connecting the user:", error);
66+
}
6567
};
6668
if (!chatClient.userID) {
6769
setupClient();
6870
}
6971
// if(client){return async()=> await client.disconnectUser()}
7072
}, [patientData]);
7173

72-
return (
73-
<ChannelLists appointmentId={appointmentId}/>
74-
)
74+
return <ChannelLists appointmentId={appointmentId} loggedInUserId={loggedInUserId} doctorId={doctorId}/>
7575
}
7676

77-
export default Home;
78-
77+
export default Home;

0 commit comments

Comments
 (0)