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
21820ebf
Commit
21820ebf
authored
Aug 18, 2022
by
Malsha Rathnasiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP chat
parent
cf4c555d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
102 additions
and
17 deletions
+102
-17
MobileApp/api/constants.js
MobileApp/api/constants.js
+2
-1
MobileApp/screens/TabOneScreen.jsx
MobileApp/screens/TabOneScreen.jsx
+28
-13
backend/backend/asgi.py
backend/backend/asgi.py
+13
-2
backend/backend/cms/migrations/0003_chat_is_detected.py
backend/backend/cms/migrations/0003_chat_is_detected.py
+18
-0
backend/backend/cms/models.py
backend/backend/cms/models.py
+1
-0
backend/backend/consumers.py
backend/backend/consumers.py
+30
-0
backend/backend/routing.py
backend/backend/routing.py
+6
-0
backend/backend/settings.py
backend/backend/settings.py
+4
-1
backend/db.sqlite3
backend/db.sqlite3
+0
-0
No files found.
MobileApp/api/constants.js
View file @
21820ebf
// export const BACKEND_URL = "http://192.168.8.103:8000"
export
const
BACKEND_URL
=
"
https://675d-123-231-127-199.in.ngrok.io
"
\ No newline at end of file
export
const
BACKEND_ADDRESS
=
"
0be4-123-231-126-225.in.ngrok.io
"
export
const
BACKEND_URL
=
`https:/
${
BACKEND_ADDRESS
}
`
\ No newline at end of file
MobileApp/screens/TabOneScreen.jsx
View file @
21820ebf
...
...
@@ -7,37 +7,44 @@ import EditScreenInfo from '../components/EditScreenInfo';
import
{
Text
,
View
}
from
'
../components/Themed
'
;
import
{
RootTabScreenProps
}
from
'
../types
'
;
import
{
create
,
getList
}
from
'
../api/api
'
;
import
{
BACKEND_ADDRESS
}
from
'
../api/constants
'
;
import
Ionicons
from
'
@expo/vector-icons/Ionicons
'
;
export
default
function
ChatScreen
({
navigation
})
{
const
currentTime
=
new
Date
()
const
defaultChatData
=
[{
from
:
'
esh
'
,
to
:
"
dri
"
,
message
:
'
msg1
'
,
time
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
1
)
},
{
from
:
'
esh
'
,
to
:
"
dri
"
,
message
:
'
msg2
'
,
time
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
2
)
},
{
from
:
'
dri
'
,
to
:
"
esh
"
,
message
:
'
msg3
'
,
time
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
3
)
},
{
from
:
'
esh
'
,
to
:
"
dri
"
,
message
:
'
msg4
'
,
time
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
4
)
},
{
from
:
'
dri
'
,
to
:
"
esh
"
,
message
:
'
msg5
'
,
time
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
5
)
},
{
from
:
'
esh
'
,
to
:
"
dri
"
,
message
:
'
msg1
'
,
time
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
1
)
},
{
from
:
'
esh
'
,
to
:
"
dri
"
,
message
:
'
msg2
'
,
time
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
2
)
},
{
from
:
'
dri
'
,
to
:
"
esh
"
,
message
:
'
msg3
'
,
time
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
3
)
},
{
from
:
'
esh
'
,
to
:
"
dri
"
,
message
:
'
msg4
'
,
time
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
4
)
},
{
from
:
'
dri
'
,
to
:
"
esh
"
,
message
:
'
msg5
'
,
time
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
5
)
},
const
defaultChatData
=
[{
from
_user
:
1
,
to_user
:
2
,
message
:
'
msg1
'
,
timestamp
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
1
)
},
{
from
_user
:
1
,
to_user
:
2
,
message
:
'
msg2
'
,
timestamp
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
2
)
},
{
from
_user
:
2
,
to_user
:
1
,
message
:
'
msg3
'
,
timestamp
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
3
),
is_detected
:
false
},
{
from
_user
:
1
,
to_user
:
2
,
message
:
'
left
'
,
timestamp
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
4
),
is_detected
:
true
},
{
from
_user
:
2
,
to_user
:
1
,
message
:
'
msg5
'
,
timestamp
:
currentTime
.
setMinutes
(
currentTime
.
getMinutes
()
-
5
)
},
{
from
_user
:
1
,
to_user
:
2
,
message
:
'
msg1
'
,
timestamp
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
1
)
},
{
from
_user
:
1
,
to_user
:
2
,
message
:
'
msg2
'
,
timestamp
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
2
)
},
{
from
_user
:
2
,
to_user
:
1
,
message
:
'
msg3
'
,
timestamp
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
3
)
},
{
from
_user
:
1
,
to_user
:
2
,
message
:
'
msg4
'
,
timestamp
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
4
)
},
{
from
_user
:
2
,
to_user
:
1
,
message
:
'
msg5
'
,
timestamp
:
currentTime
.
setDate
(
currentTime
.
getDate
()
-
5
)
},
]
const
[
detectedText
,
setDetectedText
]
=
useState
(
""
)
const
[
chatDetails
,
setChatDetails
]
=
useState
({
from_user
:
1
,
to_user
:
2
,
conversation_id
:
1
})
const
[
chats
,
setChats
]
=
useState
([])
const
[
input
,
setInput
]
=
useState
(
'
test
'
)
const
[
loading
,
setLoading
]
=
useState
(
true
)
const
ws
=
new
WebSocket
(
'
ws://localhost:3000/ws
'
)
const
ws
=
new
WebSocket
(
`ws://
${
BACKEND_ADDRESS
}
/chatSocket/`
)
useEffect
(()
=>
{
loadChats
()
//
loadChats()
// startWebsocket()
loadSampleChats
()
setLoading
(
false
)
},
[])
const
startWebsocket
=
()
=>
{
...
...
@@ -61,6 +68,14 @@ export default function ChatScreen({ navigation }) {
}
const
loadSampleChats
=
()
=>
{
const
chats_
=
defaultChatData
//res.results
const
sections
=
[...
new
Set
(
chats_
.
map
(
chat
=>
new
Date
(
chat
.
timestamp
).
setHours
(
0
,
0
,
0
,
0
)))];
const
sectionChats
=
sections
.
map
(
section
=>
({
title
:
section
,
data
:
chats
.
filter
(
chat
=>
new
Date
(
chat
.
timestamp
).
setHours
(
0
,
0
,
0
,
0
)
==
section
)
}))
setChats
(
sectionChats
)
console
.
log
({
chats
})
}
const
loadChats
=
async
()
=>
{
await
getList
(
'
chats
'
).
then
(
res
=>
{
return
res
.
json
()
...
...
backend/backend/asgi.py
View file @
21820ebf
...
...
@@ -11,6 +11,17 @@ import os
from
django.core.asgi
import
get_asgi_application
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'backend.settings'
)
#
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
application
=
get_asgi_application
()
# application = get_asgi_application()
from
channels.routing
import
ProtocolTypeRouter
,
URLRouter
# noqa isort:skip
from
.routing
import
websocket_urlpatterns
# noqa isort:skip
application
=
ProtocolTypeRouter
(
{
"http"
:
get_asgi_application
(),
"websocket"
:
URLRouter
(
websocket_urlpatterns
),
}
)
backend/backend/cms/migrations/0003_chat_is_detected.py
0 → 100644
View file @
21820ebf
# Generated by Django 4.1 on 2022-08-18 03:33
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'cms'
,
'0002_conversation_chat'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'chat'
,
name
=
'is_detected'
,
field
=
models
.
BooleanField
(
default
=
False
),
),
]
backend/backend/cms/models.py
View file @
21820ebf
...
...
@@ -32,3 +32,4 @@ class Chat(models.Model):
User
,
related_name
=
'to_convo'
,
on_delete
=
models
.
PROTECT
)
message
=
models
.
TextField
()
timestamp
=
models
.
DateTimeField
(
auto_now
=
True
)
is_detected
=
models
.
BooleanField
(
default
=
False
)
backend/backend/consumers.py
0 → 100644
View file @
21820ebf
from
channels.generic.websocket
import
JsonWebsocketConsumer
class
ChatConsumer
(
JsonWebsocketConsumer
):
"""
This consumer is used to show user's online status,
and send notifications.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
args
,
kwargs
)
self
.
room_name
=
None
def
connect
(
self
):
print
(
"Connected!"
)
self
.
room_name
=
"home"
self
.
accept
()
self
.
send_json
(
{
"type"
:
"welcome_message"
,
"message"
:
"Hey there! You've successfully connected!"
,
}
)
def
disconnect
(
self
,
code
):
print
(
"Disconnected!"
)
return
super
()
.
disconnect
(
code
)
def
receive_json
(
self
,
content
,
**
kwargs
):
print
(
content
)
return
super
()
.
receive_json
(
content
,
**
kwargs
)
\ No newline at end of file
backend/backend/routing.py
0 → 100644
View file @
21820ebf
from
django.urls
import
path
from
backend.consumers
import
ChatConsumer
websocket_urlpatterns
=
[
path
(
"/chatSocket"
,
ChatConsumer
.
as_asgi
())
]
\ No newline at end of file
backend/backend/settings.py
View file @
21820ebf
...
...
@@ -42,6 +42,7 @@ INSTALLED_APPS = [
'rest_framework'
,
'backend.cms'
,
'corsheaders'
,
'channels'
]
MIDDLEWARE
=
[
...
...
@@ -159,4 +160,6 @@ SIMPLE_JWT = {
'SLIDING_TOKEN_REFRESH_LIFETIME'
:
datetime
.
timedelta
(
days
=
1
),
}
CORS_ORIGIN_ALLOW_ALL
=
True
\ No newline at end of file
CORS_ORIGIN_ALLOW_ALL
=
True
ASGI_APPLICATION
=
"backend.asgi.application"
\ No newline at end of file
backend/db.sqlite3
View file @
21820ebf
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