From f31b805d82a727e0bd0a93e383a8b90eca556c1c Mon Sep 17 00:00:00 2001 From: Umang Utkarsh <95426993+umangutkarsh@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:09:56 +0530 Subject: [PATCH] User status feature (#537) * getStatus endpoint * status icon online * integrate * refactor status icons * lint fixes --- packages/api/src/EmbeddedChatApi.ts | 17 +++++ .../react/src/components/Icon/icons/Away.js | 14 ++++ .../react/src/components/Icon/icons/Busy.js | 22 ++++++ .../src/components/Icon/icons/Offline.js | 22 ++++++ .../react/src/components/Icon/icons/Online.js | 19 +++++ .../react/src/components/Icon/icons/index.js | 8 ++ .../components/RoomMembers/RoomMemberItem.js | 73 ++++++++++++++++++- 7 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 packages/react/src/components/Icon/icons/Away.js create mode 100644 packages/react/src/components/Icon/icons/Busy.js create mode 100644 packages/react/src/components/Icon/icons/Offline.js create mode 100644 packages/react/src/components/Icon/icons/Online.js diff --git a/packages/api/src/EmbeddedChatApi.ts b/packages/api/src/EmbeddedChatApi.ts index 739996189..17cb1b90b 100644 --- a/packages/api/src/EmbeddedChatApi.ts +++ b/packages/api/src/EmbeddedChatApi.ts @@ -1044,4 +1044,21 @@ export default class EmbeddedChatApi { const data = await response.json(); return data; } + + async getUserStatus(reqUserId: string) { + const { userId, authToken } = (await this.auth.getCurrentUser()) || {}; + const response = await fetch( + `${this.host}/api/v1/users.getStatus?userId=${reqUserId}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-Auth-Token": authToken, + "X-User-Id": userId, + }, + } + ); + const data = response.json(); + return data; + } } diff --git a/packages/react/src/components/Icon/icons/Away.js b/packages/react/src/components/Icon/icons/Away.js new file mode 100644 index 000000000..4cf2740de --- /dev/null +++ b/packages/react/src/components/Icon/icons/Away.js @@ -0,0 +1,14 @@ +import React from 'react'; + +const Away = (props) => ( + + + +); + +export default Away; diff --git a/packages/react/src/components/Icon/icons/Busy.js b/packages/react/src/components/Icon/icons/Busy.js new file mode 100644 index 000000000..74e1e229f --- /dev/null +++ b/packages/react/src/components/Icon/icons/Busy.js @@ -0,0 +1,22 @@ +import React from 'react'; + +const Busy = (props) => ( + + + + + +); + +export default Busy; diff --git a/packages/react/src/components/Icon/icons/Offline.js b/packages/react/src/components/Icon/icons/Offline.js new file mode 100644 index 000000000..4e557dfef --- /dev/null +++ b/packages/react/src/components/Icon/icons/Offline.js @@ -0,0 +1,22 @@ +import React from 'react'; + +const Offline = (props) => ( + + + +); + +export default Offline; diff --git a/packages/react/src/components/Icon/icons/Online.js b/packages/react/src/components/Icon/icons/Online.js new file mode 100644 index 000000000..215f021e7 --- /dev/null +++ b/packages/react/src/components/Icon/icons/Online.js @@ -0,0 +1,19 @@ +import React from 'react'; + +const Online = (props) => ( + +); + +export default Online; diff --git a/packages/react/src/components/Icon/icons/index.js b/packages/react/src/components/Icon/icons/index.js index 091ebe67e..4205df6f2 100644 --- a/packages/react/src/components/Icon/icons/index.js +++ b/packages/react/src/components/Icon/icons/index.js @@ -48,6 +48,10 @@ import ChevronLeft from './ChevronLeft'; import Key from './Key'; import Attachment from './Attachment'; import CircleArrowDown from './CircleArrowDown'; +import Online from './Online'; +import Offline from './Offline'; +import Away from './Away'; +import Busy from './Busy'; const icons = { file: File, @@ -100,6 +104,10 @@ const icons = { key: Key, attachment: Attachment, 'circle-arrow-down': CircleArrowDown, + online: Online, + offline: Offline, + away: Away, + busy: Busy, }; export default icons; diff --git a/packages/react/src/components/RoomMembers/RoomMemberItem.js b/packages/react/src/components/RoomMembers/RoomMemberItem.js index 363105639..6e8199733 100644 --- a/packages/react/src/components/RoomMembers/RoomMemberItem.js +++ b/packages/react/src/components/RoomMembers/RoomMemberItem.js @@ -1,8 +1,28 @@ -import React from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import PropTypes from 'prop-types'; +import RCContext from '../../context/RCInstance'; +import { Icon } from '../Icon'; const RoomMemberItem = ({ user, host }) => { + const { RCInstance } = useContext(RCContext); + const [userStatus, setUserStatus] = useState(''); const avatarUrl = new URL(`avatar/${user.username}`, host).toString(); + + useEffect(() => { + const getStatus = async () => { + try { + const res = await RCInstance.getUserStatus(user._id); + if (res.success) { + setUserStatus(res.status); + } + } catch (err) { + console.error('Error fetching user status', err); + } + }; + + getStatus(); + }, [RCInstance]); + return (
{ paddingBottom: '8px', paddingTop: '8px', display: 'flex', + alignItems: 'center', }} > avatar - {user.username} + + {userStatus === 'online' && ( + + )} + {userStatus === 'offline' && ( + + )} + {userStatus === 'away' && ( + + )} + {userStatus === 'busy' && ( + + )} + {user.username} +
); };