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