Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Story 33 - Chat between Medical Staff/Patient #169

Merged
merged 30 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6ef1241
WIP
KrisTheCanadian Mar 25, 2022
0ecbe3a
WIP
KrisTheCanadian Mar 25, 2022
f09ccd4
#33 css adjustments for chat
gkillick Mar 27, 2022
c5ddbdd
WIP
KrisTheCanadian Mar 27, 2022
d04a8ee
WIP
KrisTheCanadian Mar 27, 2022
365a6dc
removed useless import
KrisTheCanadian Mar 27, 2022
555b9b3
#33 chatroom refactored
gkillick Mar 28, 2022
6a720ed
#33 fixed props
gkillick Mar 28, 2022
cc4cdd3
#33 messages saving to firebase
gkillick Mar 28, 2022
84713ce
#33 package fix
gkillick Mar 29, 2022
25b69ce
#33 - Fixed Package Lock
martinsenecal Mar 29, 2022
9b20a24
#33 implementing chat in medical view
gkillick Mar 29, 2022
e2ede01
#33 styling chat
gkillick Mar 29, 2022
43b5680
#33 styling chat
gkillick Mar 30, 2022
f748c1f
#33 styling chat
gkillick Mar 30, 2022
2621efb
#33 styling and refactor of chat
gkillick Mar 30, 2022
944a5c4
#33 connected chat with patient
gkillick Mar 31, 2022
36b6af4
#33 fix medical chat
gkillick Mar 31, 2022
4423fe4
#33 padding fix
gkillick Mar 31, 2022
c8c3309
#33 added read/unread status and cloud function
gkillick Mar 31, 2022
4d79de2
#33 use cloud function for message notification
gkillick Mar 31, 2022
e8326f8
#33 remove user notifications for conversation entered
gkillick Mar 31, 2022
0219f43
#33 fixed tests
gkillick Mar 31, 2022
c85069e
#33 fix for build
gkillick Mar 31, 2022
4e2e5a3
#33 fix build
gkillick Mar 31, 2022
f588a70
Run Cypress on ubuntu-latest
AhmadHashems Mar 31, 2022
f306ad4
#33 fix console log, added new line to package.json
gkillick Apr 1, 2022
f650df7
Disable node.js.yml
AhmadHashems Apr 1, 2022
6b33aff
Merge branch 'dev' into STORY-33-Chat
AhmadHashems Apr 1, 2022
60e5da5
Update cypress.yml
AhmadHashems Apr 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ jobs:
# - uses: actions/upload-artifact@master
# with:
# name: videos
# path: cypress/videos
# path: cypress/videos
12 changes: 12 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ service cloud.firestore {
allow read, write: if false;
}

match /messages/{docID} {
allow read: if request.auth.uid != null;
allow create: if canCreateMessage();
}

match /users/{userId} {
allow read: if isLoggedIn()
&& (belongsTo(userId) || hasRole('admin') || hasRole('medical'));
Expand All @@ -29,6 +34,13 @@ service cloud.firestore {
allow update: if isLoggedIn() && (request.auth.uid == resource.data.uid || hasRole('admin') || hasRole('medical'));
}

function canCreateMessage() {
let isSignedIn = request.auth.uid != null;
let isOwner = request.auth.uid == request.resource.data.uid;

return isSignedIn && isOwner;
}

function getUserById(userid) {
return get(/databases/$(database)/documents/users/$(userid));
}
Expand Down
1 change: 1 addition & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
},
"private": true
}

58 changes: 58 additions & 0 deletions functions/src/callable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const sendNotification = functions.https.onCall(async (_data) => {
message: _data.message,
date: admin.firestore.Timestamp.now(),
read: false,
conversationID: null,
};
const userId = _data.userId;
const userRef = db.doc(`users/${userId}`);
Expand All @@ -96,3 +97,60 @@ interface UserNotification {
read: boolean;
}


// send notification if user is marked as unread in conversation
export const sendNotificationForConversation = functions.https.onCall(async (_data) => {
// get doctor with available slots
const message: UserNotification = {
conversationID: _data.conversationID,
title: _data.title,
message: _data.message,
date: admin.firestore.Timestamp.now(),
read: false,
};
const recipientID = _data.recipientID;
const conversationID = _data.conversationID;

// allow 2 seconds for user to mark as read
await delay(2000);

// check to see if user is unread in conversation
const conversationRef = db.doc(`chats/${conversationID}`);
const conversationDoc = await conversationRef.get();
const conversation = conversationDoc.data();
if (conversation && conversation.unreadUserIds && conversation.unreadUserIds.includes(recipientID)) {
// filter out notifications that already exist for conversation
const userRef = db.doc(`users/${recipientID}`);
const recipientDoc = await userRef.get();
const recipient = recipientDoc.data();
let notifications: UserNotification[] = [];
if (recipient && recipient.notifications) {
// remove notifications for same conversationID
notifications = recipient.notifications.filter((n: UserNotification) => n.conversationID !== conversationID);
}

// send notification
return userRef.update({
notifications: [...notifications, message],
});
}
// or do nothing if not unread
return null;
});

interface UserNotification {
title: string;
message: string;
date: admin.firestore.Timestamp;
read: boolean;
conversationID: string | null;
}

// time is in milliseconds
const delay = (time:number) => {
return new Promise((res) => {
setTimeout(() => {
res("VALUE TO RESOLVE");
}, time);
});
};
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {requestDoctor, dispatchDoctor, sendNotification} from "./callable";
export {requestDoctor, dispatchDoctor, sendNotification, sendNotificationForConversation} from "./callable";


// // Start writing Firebase Functions
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@
"prettier": "^2.5.1",
"prettier-eslint": "^13.0.0"
}
}
}
martinsenecal marked this conversation as resolved.
Show resolved Hide resolved
64 changes: 64 additions & 0 deletions src/components/chat/chatroom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.received{
display: flex;
align-items: center;
}
.message p{
margin-right: 5px;
margin-left: 5px;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
background: #e5e5e5;
border-radius: 17px;
}
.sent p{
background: #434ce6;
color:white;

}
p{
margin:0px;
margin-bottom: 3px;
margin-right:5px;
}
.no-avatar-spacing{
margin-bottom: 5px;
}
.sent{
display: flex;
align-items: center;
flex-direction: row-reverse;
}
.message-input{
padding: 20px;
width: 100%;
border-radius: 20px;
border-top-right-radius: 0px;
border-top-left-radius: 0;
border: 1px solid transparent;
background: #ffffff;
border-top: 1px solid #e7e7e7;
outline: none;
}
.messages-container{
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0;
padding-left: 5px;
margin-right: -20px;
padding-right: 25px;
padding-top: 5px;
}

.send-message-button{
position:absolute;
background: none;
right:3px;
top:15px;
color: #434ce6;
border:none;
}

.scroll-to{
height:5px
}
Loading