Commit 16633fca authored by Malsha Rathnasiri's avatar Malsha Rathnasiri

fix issues mobile app

parent 7c5f12fd
...@@ -165,7 +165,7 @@ export default function ChatScreen({ navigation }) { ...@@ -165,7 +165,7 @@ export default function ChatScreen({ navigation }) {
useEffect(() => { useEffect(() => {
const interval = setInterval(() => { const interval = setInterval(() => {
loadChats(); loadChats();
}, 1000); }, 2000);
return () => { return () => {
clearInterval(interval); clearInterval(interval);
}; };
...@@ -206,16 +206,15 @@ export default function ChatScreen({ navigation }) { ...@@ -206,16 +206,15 @@ export default function ChatScreen({ navigation }) {
}).then((response) => { }).then((response) => {
// console.log(response) // console.log(response)
}); });
setTimeout(() => {
addChats({ addChats({
message: item.A, message: item.A,
from_user: chatDetails.to_user, from_user: chatDetails.to_user,
to_user: chatDetails.from_user, to_user: chatDetails.from_user,
conversation: chatDetails.id, conversation: chatDetails.id,
}).then((response) => { }).then((response) => {
// console.log(response) // console.log(response)
}); });
}, 500);
setLoading(true); setLoading(true);
setInput(""); setInput("");
...@@ -282,11 +281,11 @@ export default function ChatScreen({ navigation }) { ...@@ -282,11 +281,11 @@ export default function ChatScreen({ navigation }) {
<EditScreenInfo path="/screens/TabOneScreen.tsx" /> */} <EditScreenInfo path="/screens/TabOneScreen.tsx" /> */}
<View style={{ flex: 1, width: "100%" }}> <View style={{ flex: 1, width: "100%", justifyContent: "space-between" }}>
<View <View
style={{ style={{
display: "flex", display: "flex",
flex: 0.9, flex: 1,
justifyContent: "space-between", justifyContent: "space-between",
}} }}
> >
...@@ -296,6 +295,7 @@ export default function ChatScreen({ navigation }) { ...@@ -296,6 +295,7 @@ export default function ChatScreen({ navigation }) {
<ActivityIndicator /> <ActivityIndicator />
) : ( ) : (
<SectionList <SectionList
style={{ flex: 1 }}
refreshing={loading} refreshing={loading}
onRefresh={() => { onRefresh={() => {
// loadChatDetails() //remove // loadChatDetails() //remove
...@@ -408,84 +408,91 @@ export default function ChatScreen({ navigation }) { ...@@ -408,84 +408,91 @@ export default function ChatScreen({ navigation }) {
) )
}} /> */} }} /> */}
</View> </View>
<Divider />
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}> <View>
<Divider />
<View <View
style={{ flexDirection: "row", display: "flex", height: "100%" }} style={{
padding: 0,
backgroundColor: "white",
minHeight: 20,
justifyContent: "flex-end",
}}
> >
<ScrollView horizontal={true}> <View style={{ flexDirection: "row", display: "flex" }}>
{QandAs.map((item) => ( <ScrollView horizontal={true}>
<TouchableOpacity {QandAs.map((item) => (
onPress={() => onDefaultMessagePressed(item)} <TouchableOpacity
style={{ onPress={() => onDefaultMessagePressed(item)}
marginVertical: 5, style={{
marginHorizontal: 5, marginVertical: 5,
backgroundColor: "gray", marginHorizontal: 5,
borderRadius: 5, backgroundColor: "gray",
justifyContent: "center", borderRadius: 5,
alignSelf: "center", justifyContent: "center",
padding: 5, alignSelf: "center",
}} padding: 5,
> }}
<Text key={item.Q}
style={{ justifyContent: "center", alignSelf: "center" }}
> >
{item.Q} <Text
</Text> style={{ justifyContent: "center", alignSelf: "center" }}
</TouchableOpacity> >
))} {item.Q}
</ScrollView> </Text>
</TouchableOpacity>
))}
</ScrollView>
</View>
</View> </View>
</View> <Divider />
<Divider /> <View style={{ padding: 0, backgroundColor: "white", minHeight: 30 }}>
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}> <View style={{ flexDirection: "row", display: "flex" }}>
<View <SafeAreaView
style={{ flexDirection: "row", display: "flex", height: "100%" }}
>
<SafeAreaView
style={{
flex: 0.8,
height: "100%",
flexDirection: "column-reverse",
}}
>
{/* <TextInput
style={{ borderWidth: 2, borderColor: 'gray', color: 'black', marginHorizontal: 5, paddingHorizontal: 10, borderRadius: 5 }}
defaultValue={input}
onChange={(e) => setInput(e.target.value)}></TextInput> */}
<Input
style={{ height: 30 }}
value={input}
w="100%"
onChangeText={setInput}
placeholder=""
/>
</SafeAreaView>
{input ? (
<View
style={{ style={{
flex: 0.2, flex: 0.8,
height: "100%", height: "100%",
flexDirection: "column-reverse", flexDirection: "column-reverse",
}} }}
> >
<Button {/* <TextInput
style={{ width: "100%", height: "100%" }} style={{ borderWidth: 2, borderColor: 'gray', color: 'black', marginHorizontal: 5, paddingHorizontal: 10, borderRadius: 5 }}
title="Send" defaultValue={input}
onPress={onSendPress} onChange={(e) => setInput(e.target.value)}></TextInput> */}
<Input
style={{ height: 30 }}
value={input}
w="100%"
onChangeText={setInput}
placeholder=""
/> />
</View> </SafeAreaView>
) : ( {input ? (
<View <View
style={{ style={{
flex: 0.2, flex: 0.2,
height: "100%", // height: "100%",
flexDirection: "column-reverse", flexDirection: "column-reverse",
}} }}
> >
<AudioRecorder setDetectedText={setInput} /> <Button
</View> style={{ width: "100%" }}
)} title="Send"
onPress={onSendPress}
/>
</View>
) : (
<View
style={{
flex: 0.2,
height: "100%",
flexDirection: "column-reverse",
}}
>
<AudioRecorder setDetectedText={setInput} />
</View>
)}
</View>
</View> </View>
</View> </View>
</View> </View>
......
...@@ -13,6 +13,7 @@ export const styles = StyleSheet.create({ ...@@ -13,6 +13,7 @@ export const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
backgroundColor: COLOR1, backgroundColor: COLOR1,
height: '100%'
}, },
loginContainer: { loginContainer: {
alignItems: 'center', alignItems: 'center',
......
...@@ -32,11 +32,12 @@ from pydub import AudioSegment ...@@ -32,11 +32,12 @@ from pydub import AudioSegment
import numpy as np import numpy as np
#Custom Viewset to get auth token # Custom Viewset to get auth token
class ObtainTokenPairWithUserView(TokenObtainPairView): class ObtainTokenPairWithUserView(TokenObtainPairView):
permission_classes = (permissions.AllowAny,) permission_classes = (permissions.AllowAny,)
serializer_class = MyTokenObtainPairSerializer serializer_class = MyTokenObtainPairSerializer
class UserViewSet(viewsets.ModelViewSet): class UserViewSet(viewsets.ModelViewSet):
""" """
API endpoint that allows users to be viewed or edited. API endpoint that allows users to be viewed or edited.
...@@ -71,7 +72,7 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -71,7 +72,7 @@ class MlModelViewSet(viewsets.ViewSet):
permission_classes = [permissions.AllowAny] permission_classes = [permissions.AllowAny]
parser_classes = [MultiPartParser] parser_classes = [MultiPartParser]
#Custom api to add sample chats # Custom api to add sample chats
@action(detail=False) @action(detail=False)
def addChats(*args, **kwargs): def addChats(*args, **kwargs):
admin = User.objects.get(username='admin') admin = User.objects.get(username='admin')
...@@ -107,7 +108,7 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -107,7 +108,7 @@ class MlModelViewSet(viewsets.ViewSet):
conversation=convo, from_user_id=chat['from'], to_user_id=chat['to'], messsage=chat['message']) conversation=convo, from_user_id=chat['from'], to_user_id=chat['to'], messsage=chat['message'])
object.save() object.save()
#Custom api to train the model # Custom api to train the model
@action(detail=False) @action(detail=False)
def train(*args, **kwargs): def train(*args, **kwargs):
print('Function ran') print('Function ran')
...@@ -115,7 +116,7 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -115,7 +116,7 @@ class MlModelViewSet(viewsets.ViewSet):
print(results) print(results)
return Response({'success': True}) return Response({'success': True})
#Custom api to convert audio to text # Custom api to convert audio to text
@action(detail=False, methods=["POST"]) @action(detail=False, methods=["POST"])
def detect(self, request, *args, **kwargs): def detect(self, request, *args, **kwargs):
print('Function ran') print('Function ran')
...@@ -151,18 +152,19 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -151,18 +152,19 @@ class MlModelViewSet(viewsets.ViewSet):
print(results) print(results)
return Response({'success': True, 'result': results}) return Response({'success': True, 'result': results})
class ChatViewSet(viewsets.ModelViewSet): class ChatViewSet(viewsets.ModelViewSet):
queryset = Chat.objects.all().order_by('-timestamp') queryset = Chat.objects.all().order_by('-timestamp')
serializer_class = ChatSerializer serializer_class = ChatSerializer
permission_classes = [permissions.IsAuthenticated] permission_classes = [permissions.IsAuthenticated]
#ovveride defualt list action to get chats of specific user conversation # ovveride defualt list action to get chats of specific user conversation
def list(self, request, pk=None): def list(self, request, pk=None):
if pk == None: if pk == None:
chats = Chat.objects \ chats = Chat.objects \
.filter(conversation_id=1) \ .filter(conversation_id=1) \
.filter(Q(from_user_id=request.user.id) | Q( .filter(Q(from_user_id=request.user.id) | Q(
to_user_id=request.user.id)) to_user_id=request.user.id))
else: else:
chats = Chat.objects.get(id=pk) chats = Chat.objects.get(id=pk)
...@@ -187,21 +189,23 @@ class ChatViewSet(viewsets.ModelViewSet): ...@@ -187,21 +189,23 @@ class ChatViewSet(viewsets.ModelViewSet):
return Response({'success': True}) return Response({'success': True})
except(e): except(e):
return Response({'success': False}) return Response({'success': False})
@action(methods=['POST'], detail=False) @action(methods=['POST'], detail=False)
def add_chats(self, request): def add_chats(self, request):
item = ChatSerializer(data=request.data) item = ChatSerializer(data=request.data)
# validating for already existing data # validating for already existing data
if Chat.objects.filter(**request.data).exists(): # if Chat.objects.filter(**request.data).exists():
raise serializers.ValidationError('This data already exists') # raise serializers.ValidationError('This data already exists')
print(item)
if item.is_valid():
if item.is_valid() or True:
item.save() item.save()
return Response(item.data) return Response(item.data)
else: else:
return Response(status=Status.HTTP_404_NOT_FOUND) return Response(status=Status.HTTP_404_NOT_FOUND)
class ConversationViewSet(viewsets.ModelViewSet): class ConversationViewSet(viewsets.ModelViewSet):
queryset = Conversation.objects.all().order_by('id') queryset = Conversation.objects.all().order_by('id')
serializer_class = ConversationSerializer serializer_class = ConversationSerializer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment