diff --git a/app/assets/javascripts/initializers/initNotifications.js b/app/assets/javascripts/initializers/initNotifications.js index 5691d1196..57f66a088 100644 --- a/app/assets/javascripts/initializers/initNotifications.js +++ b/app/assets/javascripts/initializers/initNotifications.js @@ -55,10 +55,6 @@ function fetchNotificationsCount() { document.getElementById('notifications-link').href, 'force', ); - InstantClick.preload( - document.getElementById('connect-link').href, - 'force', - ); }, 30); } } diff --git a/app/javascript/chat/chat.jsx b/app/javascript/chat/chat.jsx index 7858375ab..36497f431 100644 --- a/app/javascript/chat/chat.jsx +++ b/app/javascript/chat/chat.jsx @@ -406,6 +406,11 @@ export default class Chat extends Component { unopenedChannelIds, } = this.state; const receivedChatChannelId = message.chat_channel_id; + const messageList = document.getElementById('messagelist') + const nearBottom = (messageList.scrollTop + messageList.offsetHeight + 400 > messageList.scrollHeight) + if (nearBottom) { + scrollToBottom(); + } let newMessages = []; if ( message.temp_id && @@ -424,7 +429,7 @@ export default class Chat extends Component { } } const newShowAlert = - activeChannelId === receivedChatChannelId ? { showAlert: scrolled } : {}; + activeChannelId === receivedChatChannelId ? { showAlert: !nearBottom } : {}; let newMessageChannelIndex = 0; let newMessageChannel = null; const newChannelsObj = chatChannels.map((channel, index) => { @@ -597,7 +602,7 @@ export default class Chat extends Component { }; handleMessageSubmit = (message) => { - const { activeChannelId, activeContent } = this.state; + const { activeChannelId } = this.state; scrollToBottom(); // should check if user has the privilege if (message.startsWith('/code')) { @@ -658,6 +663,7 @@ export default class Chat extends Component { message, mentionedUsersId: this.getMentionedUsers(message), }; + this.setState({scrolled: false, showAlert: false}) sendMessage(messageObject, this.handleSuccess, this.handleFailure); } }; diff --git a/app/javascript/src/utils/getUnopenedChannels.jsx b/app/javascript/src/utils/getUnopenedChannels.jsx index 3a5589427..ecb4b5602 100644 --- a/app/javascript/src/utils/getUnopenedChannels.jsx +++ b/app/javascript/src/utils/getUnopenedChannels.jsx @@ -44,6 +44,11 @@ class UnopenedChannelNotice extends Component { if (unopenedChannels.length > 0) { number.classList.remove('hidden'); number.innerHTML = unopenedChannels.length; + document.getElementById('connect-link').href = '/connect/' + unopenedChannels[0].adjusted_slug; + InstantClick.preload( + document.getElementById('connect-link').href, + 'force', + ); } else { number.classList.add('hidden'); }