File tree 3 files changed +6047
-297
lines changed
app/conversations/[conversationId]/components
3 files changed +6047
-297
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ const Body: React.FC<BodyProps> = ({ initialMessages }) => {
31
31
// Body component will listen for new messages and update the state whenever a new message is received through the socket
32
32
33
33
useEffect ( ( ) => {
34
+ //getting the notification permission
35
+ Notification . requestPermission ( ) ;
34
36
// Update the message receive in the current message
35
37
const updateMessageHandler = ( newMessage : FullMessageType ) => {
36
38
// Update the message in the state only if the message belongs to the current conversation
@@ -63,6 +65,10 @@ const Body: React.FC<BodyProps> = ({ initialMessages }) => {
63
65
// Render received message from server only if it belongs to the current conversation
64
66
if ( message . conversationId === conversationId ) {
65
67
// Add the new message to the state
68
+ console . log ( Notification . permission ) ;
69
+ if ( document . visibilityState === 'hidden' ) {
70
+ new Notification ( `${ message . sender . name } sent a msg` ) ;
71
+ }
66
72
setMessages ( ( current ) => {
67
73
if ( find ( current , { id : message . id } ) ) {
68
74
return current ;
You can’t perform that action at this time.
0 commit comments