Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
240
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
U.D.C.S.WIJESOORIYA
240
Commits
95824fb9
Commit
95824fb9
authored
Oct 06, 2022
by
Malsha Rathnasiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes
parent
16228ea8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
12 deletions
+38
-12
MobileApp/api/Authentication.js
MobileApp/api/Authentication.js
+1
-0
MobileApp/api/api.js
MobileApp/api/api.js
+6
-1
MobileApp/api/constants.js
MobileApp/api/constants.js
+1
-1
MobileApp/screens/TabOneScreen.jsx
MobileApp/screens/TabOneScreen.jsx
+17
-3
backend/backend/cms/views.py
backend/backend/cms/views.py
+11
-4
backend/backend/settings.py
backend/backend/settings.py
+2
-3
backend/db.sqlite3
backend/db.sqlite3
+0
-0
No files found.
MobileApp/api/Authentication.js
View file @
95824fb9
...
...
@@ -88,6 +88,7 @@ export const login = async (username, password) => {
// Actions.main();
})
.
catch
(
error
=>
{
console
.
log
(
'
error in login authentication
'
)
throw
Error
(
error
)
});
...
...
MobileApp/api/api.js
View file @
95824fb9
...
...
@@ -13,12 +13,17 @@ const getHeaders = async () => {
var
token
=
await
AsyncStorage
.
getItem
(
'
access_token
'
)
return
{
Authorization
:
`JWT
${
token
}
`
,
'
Content-Type
'
:
'
application/json
'
,
// "Access-Control-Allow-Methods": "DELETE, POST, GET, OPTIONS",
// "Access-Control-Allow-Headers": "Content-Type, Authorization, Access-Control-Allow-Methods",
// "Access-Control-Allow-Origin": "*",
}
}
export
const
create
=
async
(
resource
,
values
)
=>
{
const
headers
=
getHeaders
()
const
headers
=
await
getHeaders
()
console
.
log
({
headers
},
'
create
'
)
console
.
log
({
values
})
try
{
return
fetch
(
`
${
BACKEND_URL
}
/
${
resource
}
/`
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
values
),
headers
})
// return Axios.post(`${BACKEND_URL}/${resource}/`, values)
...
...
MobileApp/api/constants.js
View file @
95824fb9
// export const BACKEND_URL = "http://192.168.8.103:8000"
import
{
Platform
}
from
'
react-native
'
export
const
BACKEND_ADDRESS
=
Platform
.
OS
==
'
web
'
?
"
127.0.0.1:8000
"
:
"
93e8-2401-dd00-10-20-e170-748c-b618-e8f5.in
.ngrok.io
"
export
const
BACKEND_ADDRESS
=
Platform
.
OS
==
'
web
'
?
"
127.0.0.1:8000
"
:
"
0afe-112-134-223-169.ap
.ngrok.io
"
export
const
BACKEND_URL
=
`http://
${
BACKEND_ADDRESS
}
`
MobileApp/screens/TabOneScreen.jsx
View file @
95824fb9
...
...
@@ -15,6 +15,7 @@ import Slider from '@react-native-community/slider';
import
{
PlayMessage
}
from
'
../components/PlayMessage
'
;
import
{
Toast
}
from
'
native-base
'
;
import
{
ERROR_TOAST_PROPS
}
from
'
../util/util
'
;
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
export
default
function
ChatScreen
({
navigation
})
{
...
...
@@ -97,7 +98,20 @@ export default function ChatScreen({ navigation }) {
return
res
.
json
()
}).
then
(
res
=>
{
console
.
log
(
res
)
setChatDetails
(
res
)
AsyncStorage
.
getItem
(
'
user_id
'
).
then
((
user_id
)
=>
{
console
.
log
(
'
chat details
'
,
user_id
)
//change from user and to user depending on the current user
if
(
res
.
from_user
==
user_id
)
{
setChatDetails
(
res
)
}
else
{
const
n_res
=
{
...
res
,
from_user
:
res
.
to_user
,
to_user
:
res
.
from_user
}
setChatDetails
(
n_res
)
}
})
})
}
...
...
@@ -117,7 +131,7 @@ export default function ChatScreen({ navigation }) {
const
onSendPress
=
()
=>
{
try
{
create
(
'
chats
'
,
{
message
:
input
,
from_user
:
chatDetails
.
from_user
,
to_user
:
chatDetails
.
to_user
,
conversation
:
chatDetails
.
conversation_
id
}).
then
(
response
=>
{
create
(
'
chats
'
,
{
message
:
input
,
from_user
:
chatDetails
.
from_user
,
to_user
:
chatDetails
.
to_user
,
conversation
:
chatDetails
.
id
}).
then
(
response
=>
{
// console.log(response)
})
setLoading
(
true
)
...
...
@@ -151,7 +165,7 @@ export default function ChatScreen({ navigation }) {
inverted
sections=
{
chats
}
keyExtractor=
{
(
item
,
index
)
=>
item
+
index
}
renderItem=
{
({
item
})
=>
{
// console.log(
{
item
})
const
timeString
=
new
Date
(
item
.
timestamp
).
toLocaleTimeString
()
...
...
backend/backend/cms/views.py
View file @
95824fb9
...
...
@@ -178,12 +178,17 @@ class MlModelViewSet(viewsets.ViewSet):
class
ChatViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Chat
.
objects
.
all
()
.
order_by
(
'-timestamp'
)
serializer_class
=
ChatSerializer
permission_classes
=
[
permissions
.
IsAuthenticated
]
permission_classes
=
[
permissions
.
IsAuthenticated
]
#change to permissions.isAutheniticated
@
action
(
methods
=
'POST'
,
detail
=
True
)
def
getChats
(
self
,
request
,
*
args
,
**
kwargs
):
chats
=
Chat
.
objects
.
filter
(
Q
(
from_user__user_id
=
request
.
user
.
id
)
|
Q
(
to_user__user_id
=
request
.
user
.
id
))
.
order_by
(
'-timestamp'
)
.
values
()
#conversation_id hardcoded as we dont have many conversations at the moment
chats
=
Chat
.
objects
\
.
filter
(
conversation_id
=
1
)
\
.
filter
(
(
Q
(
from_user__user_id
=
request
.
user
.
id
)
|
Q
(
to_user__user_id
=
request
.
user
.
id
))
)
.
order_by
(
'-timestamp'
)
.
values
()
return
Response
({
chats
})
...
...
@@ -191,7 +196,9 @@ class ChatViewSet(viewsets.ModelViewSet):
if
pk
==
None
:
chats
=
Chat
.
objects
.
filter
(
Q
(
from_user_id
=
request
.
user
.
id
)
|
Q
(
chats
=
Chat
.
objects
\
.
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
)
...
...
backend/backend/settings.py
View file @
95824fb9
...
...
@@ -46,13 +46,12 @@ INSTALLED_APPS = [
]
MIDDLEWARE
=
[
'corsheaders.middleware.CorsMiddleware'
,
'django.middleware.security.SecurityMiddleware'
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
'django.middleware.common.CommonMiddleware'
,
'django.middleware.csrf.CsrfViewMiddleware'
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
'corsheaders.middleware.CorsMiddleware'
,
'django.contrib.messages.middleware.MessageMiddleware'
,
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
...
...
@@ -133,7 +132,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
REST_FRAMEWORK
=
{
'DEFAULT_PAGINATION_CLASS'
:
'rest_framework.pagination.PageNumberPagination'
,
'PAGE_SIZE'
:
10
,
'PAGE_SIZE'
:
10
0
,
'DEFAULT_AUTHENTICATION_CLASSES'
:
[
'rest_framework_simplejwt.authentication.JWTAuthentication'
,
'rest_framework.authentication.SessionAuthentication'
,
...
...
backend/db.sqlite3
View file @
95824fb9
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment