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,7 +206,7 @@ export default function ChatScreen({ navigation }) {
}).then((response) => {
// console.log(response)
});
setTimeout(() => {
addChats({
message: item.A,
from_user: chatDetails.to_user,
......@@ -215,7 +215,6 @@ export default function ChatScreen({ navigation }) {
}).then((response) => {
// console.log(response)
});
}, 500);
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,11 +408,18 @@ export default function ChatScreen({ navigation }) {
)
}} /> */}
</View>
<View>
<Divider />
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}>
<View
style={{ flexDirection: "row", display: "flex", height: "100%" }}
style={{
padding: 0,
backgroundColor: "white",
minHeight: 20,
justifyContent: "flex-end",
}}
>
<View style={{ flexDirection: "row", display: "flex" }}>
<ScrollView horizontal={true}>
{QandAs.map((item) => (
<TouchableOpacity
......@@ -426,6 +433,7 @@ export default function ChatScreen({ navigation }) {
alignSelf: "center",
padding: 5,
}}
key={item.Q}
>
<Text
style={{ justifyContent: "center", alignSelf: "center" }}
......@@ -438,10 +446,8 @@ export default function ChatScreen({ navigation }) {
</View>
</View>
<Divider />
<View style={{ flex: 0.05, padding: 0, backgroundColor: "white" }}>
<View
style={{ flexDirection: "row", display: "flex", height: "100%" }}
>
<View style={{ padding: 0, backgroundColor: "white", minHeight: 30 }}>
<View style={{ flexDirection: "row", display: "flex" }}>
<SafeAreaView
style={{
flex: 0.8,
......@@ -465,12 +471,12 @@ export default function ChatScreen({ navigation }) {
<View
style={{
flex: 0.2,
height: "100%",
// height: "100%",
flexDirection: "column-reverse",
}}
>
<Button
style={{ width: "100%", height: "100%" }}
style={{ width: "100%" }}
title="Send"
onPress={onSendPress}
/>
......@@ -490,5 +496,6 @@ export default function ChatScreen({ navigation }) {
</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,12 +152,13 @@ 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 \
......@@ -193,15 +195,17 @@ class ChatViewSet(viewsets.ModelViewSet):
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 Chat.objects.filter(**request.data).exists():
# raise serializers.ValidationError('This data already exists')
print(item)
if item.is_valid():
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