🚀 Feature: Give Tab Notification on New Message (#9847)
Co-authored-by: Narender Singh <narender2031@gmail.com>
This commit is contained in:
parent
c125ef1dbe
commit
708791f986
2 changed files with 26 additions and 3 deletions
|
|
@ -7,6 +7,7 @@
|
|||
import { h, Component } from 'preact';
|
||||
import PropTypes from 'prop-types';
|
||||
import { setupPusher } from '../utilities/connect';
|
||||
import notifyUser from '../utilities/connect/newMessageNotify';
|
||||
import debounceAction from '../utilities/debounceAction';
|
||||
import { addSnackbarItem } from '../Snackbar';
|
||||
import { processImageUpload } from '../article-form/actions';
|
||||
|
|
@ -452,13 +453,13 @@ export default class Chat extends Component {
|
|||
activeChannelId,
|
||||
scrolled,
|
||||
chatChannels,
|
||||
currentUserId,
|
||||
unopenedChannelIds,
|
||||
} = this.state;
|
||||
|
||||
const receivedChatChannelId = message.chat_channel_id;
|
||||
const messageList = document.getElementById('messagelist');
|
||||
let newMessages = [];
|
||||
|
||||
const nearBottom =
|
||||
messageList.scrollTop + messageList.offsetHeight + 400 >
|
||||
messageList.scrollHeight;
|
||||
|
|
@ -466,7 +467,12 @@ export default class Chat extends Component {
|
|||
if (nearBottom) {
|
||||
scrollToBottom();
|
||||
}
|
||||
// Remove reduntant messages
|
||||
|
||||
// If I'm not sender and tab is not active
|
||||
if (message.user_id !== currentUserId && document.hidden) {
|
||||
notifyUser();
|
||||
}
|
||||
|
||||
if (
|
||||
message.temp_id &&
|
||||
messages[receivedChatChannelId] &&
|
||||
|
|
@ -474,6 +480,7 @@ export default class Chat extends Component {
|
|||
(oldmessage) => oldmessage.temp_id === message.temp_id,
|
||||
) > -1
|
||||
) {
|
||||
// Remove reduntant messages
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -485,7 +492,7 @@ export default class Chat extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
//Show alert if message received and you have scrolled up
|
||||
// Show alert if message received and you have scrolled up
|
||||
const newShowAlert =
|
||||
activeChannelId === receivedChatChannelId
|
||||
? { showAlert: !nearBottom }
|
||||
|
|
|
|||
16
app/javascript/utilities/connect/newMessageNotify.js
Normal file
16
app/javascript/utilities/connect/newMessageNotify.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
export default function notifyUser() {
|
||||
modifyTitle();
|
||||
}
|
||||
|
||||
const modifyTitle = () => {
|
||||
const oldTitle = document.title;
|
||||
const titleAlert = setInterval(() => {
|
||||
if (document.title === oldTitle) document.title = 'New Message 👋';
|
||||
else document.title = oldTitle;
|
||||
}, 2000);
|
||||
|
||||
setTimeout(() => {
|
||||
clearInterval(titleAlert);
|
||||
document.title = oldTitle;
|
||||
}, 12000);
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue