From a48dff9b48a00483510742fee88e1175360b24c4 Mon Sep 17 00:00:00 2001 From: Martin Schoeler Date: Wed, 12 Apr 2023 17:24:58 -0300 Subject: [PATCH 1/2] fix: Livechat notifications not working correctly (#28741) --- .../components/Messages/MessageList/index.js | 20 ++++++- .../src/components/Messages/constants.js | 5 ++ packages/livechat/src/components/helpers.js | 25 +++++++- packages/livechat/src/lib/main.js | 58 +++++++++++++++---- .../livechat/src/routes/Chat/component.js | 1 + .../livechat/src/routes/Chat/container.js | 27 ++++++--- 6 files changed, 113 insertions(+), 23 deletions(-) diff --git a/packages/livechat/src/components/Messages/MessageList/index.js b/packages/livechat/src/components/Messages/MessageList/index.js index f68e7ba4d8cb..b34e50cba510 100644 --- a/packages/livechat/src/components/Messages/MessageList/index.js +++ b/packages/livechat/src/components/Messages/MessageList/index.js @@ -54,6 +54,13 @@ export class MessageList extends MemoizedComponent { const { onScrollTo } = this.props; onScrollTo && onScrollTo(scrollPosition); } + + const { dispatch } = this.props; + const { messageListPosition } = store.state; + + if (messageListPosition !== this.scrollPosition) { + dispatch({ messageListPosition: this.scrollPosition }); + } }; handleResize = () => { @@ -81,7 +88,18 @@ export class MessageList extends MemoizedComponent { } } - componentDidUpdate() { + componentDidUpdate(prevProps) { + const { messages, uid } = this.props; + const { messages: prevMessages } = prevProps; + + if (messages?.length !== prevMessages?.length) { + const lastMessage = messages[messages.length - 1]; + + if (lastMessage?.u?._id && lastMessage.u._id === uid) { + this.scrollPosition = MessageList.SCROLL_AT_BOTTOM; + } + } + if (this.scrollPosition === MessageList.SCROLL_AT_BOTTOM) { this.base.scrollTop = this.base.scrollHeight; return; diff --git a/packages/livechat/src/components/Messages/constants.js b/packages/livechat/src/components/Messages/constants.js index f48482a44b75..830721fd29f1 100644 --- a/packages/livechat/src/components/Messages/constants.js +++ b/packages/livechat/src/components/Messages/constants.js @@ -4,7 +4,12 @@ export const MESSAGE_TYPE_USER_REMOVED = 'ru'; export const MESSAGE_TYPE_USER_JOINED = 'uj'; export const MESSAGE_TYPE_USER_LEFT = 'ul'; export const MESSAGE_TYPE_WELCOME = 'wm'; +export const MESSAGE_TYPE_COMMAND = 'command'; export const MESSAGE_TYPE_LIVECHAT_CLOSED = 'livechat-close'; export const MESSAGE_TYPE_LIVECHAT_STARTED = 'livechat-started'; export const MESSAGE_TYPE_LIVECHAT_TRANSFER_HISTORY = 'livechat_transfer_history'; export const MESSAGE_WEBRTC_CALL = 'livechat_webrtc_video_call'; +export const MESSAGE_VIDEO_CALL = 'livechat_video_call'; +export const MESSAGE_TYPE_PRIORITY_CHANGE = 'omnichannel_priority_change_history'; +export const MESSAGE_TYPE_SLA_CHANGE = 'omnichannel_sla_change_history'; +export const MESSAGE_TYPE_LIVECHAT_NAVIGATION_HISTORY = 'livechat_navigation_history'; diff --git a/packages/livechat/src/components/helpers.js b/packages/livechat/src/components/helpers.js index f7319445ffc6..a72b84c3b8e8 100644 --- a/packages/livechat/src/components/helpers.js +++ b/packages/livechat/src/components/helpers.js @@ -4,6 +4,18 @@ import { Component } from 'preact'; import { Livechat, useSsl } from '../api'; import store from '../store'; +import { + MESSAGE_TYPE_COMMAND, + MESSAGE_TYPE_LIVECHAT_CLOSED, + MESSAGE_TYPE_LIVECHAT_NAVIGATION_HISTORY, + MESSAGE_TYPE_PRIORITY_CHANGE, + MESSAGE_TYPE_SLA_CHANGE, + MESSAGE_TYPE_USER_ADDED, + MESSAGE_TYPE_USER_JOINED, + MESSAGE_TYPE_USER_LEFT, + MESSAGE_VIDEO_CALL, + MESSAGE_WEBRTC_CALL, +} from './Messages/constants'; export function flatMap(arr, mapFunc) { const result = []; @@ -125,7 +137,18 @@ export const setCookies = (rid, token) => { export const getAvatarUrl = (username) => (username ? `${Livechat.client.host}/avatar/${username}` : null); -export const msgTypesNotRendered = ['livechat_video_call', 'livechat_navigation_history', 'au', 'command', 'uj', 'ul', 'livechat-close']; +export const msgTypesNotRendered = [ + MESSAGE_VIDEO_CALL, + MESSAGE_WEBRTC_CALL, + MESSAGE_TYPE_LIVECHAT_NAVIGATION_HISTORY, + MESSAGE_TYPE_USER_ADDED, + MESSAGE_TYPE_COMMAND, + MESSAGE_TYPE_USER_JOINED, + MESSAGE_TYPE_USER_LEFT, + MESSAGE_TYPE_LIVECHAT_CLOSED, + MESSAGE_TYPE_PRIORITY_CHANGE, + MESSAGE_TYPE_SLA_CHANGE, +]; export const canRenderMessage = ({ t }) => !msgTypesNotRendered.includes(t); diff --git a/packages/livechat/src/lib/main.js b/packages/livechat/src/lib/main.js index 9caad8efefd1..413243505890 100644 --- a/packages/livechat/src/lib/main.js +++ b/packages/livechat/src/lib/main.js @@ -68,17 +68,52 @@ export const loadConfig = async () => { }); }; -export const processUnread = async () => { - const { minimized, visible, messages } = store.state; +export const shouldMarkAsUnread = () => { + const { minimized, visible, messageListPosition } = store.state; + return minimized || !visible || (messageListPosition !== undefined && messageListPosition !== 'bottom'); +}; + +export const getLastReadMessage = () => { + const { messages, lastReadMessageId, user } = store.state; + + const renderedMessages = messages.filter((message) => canRenderMessage(message)); + + return lastReadMessageId + ? renderedMessages.find((item) => item._id === lastReadMessageId) + : renderedMessages + .slice() + .reverse() + .find((item) => item.u._id === user._id); +}; + +export const getUnreadMessages = () => { + const { messages, user, lastReadMessageId } = store.state; + + const renderedMessages = messages.filter((message) => canRenderMessage(message)); + const lastReadMessageIndex = lastReadMessageId + ? renderedMessages.findIndex((item) => item._id === lastReadMessageId) + : renderedMessages + .slice() + .reverse() + .findIndex((item) => item.u._id === user._id); - if (minimized || !visible) { - const { alerts, lastReadMessageId } = store.state; - const renderedMessages = messages.filter((message) => canRenderMessage(message)); - const lastReadMessageIndex = renderedMessages.findIndex((item) => item._id === lastReadMessageId); - const unreadMessages = renderedMessages.slice(lastReadMessageIndex + 1); + if (lastReadMessageIndex !== -1) { + const unreadMessages = renderedMessages.slice(lastReadMessageIndex + 1).filter((message) => message.u._id !== user._id); - if (lastReadMessageIndex !== -1) { - const lastReadMessage = renderedMessages[lastReadMessageIndex]; + return unreadMessages; + } + + return []; +}; + +export const processUnread = async () => { + const shouldMarkUnread = shouldMarkAsUnread(); + if (shouldMarkUnread) { + const unreadMessages = getUnreadMessages(); + + if (unreadMessages.length > 0) { + const { alerts } = store.state; + const lastReadMessage = getLastReadMessage(); const alertMessage = i18next.t('count_new_messages_since_since', { count: unreadMessages.length, val: new Date(lastReadMessage.ts), @@ -86,11 +121,10 @@ export const processUnread = async () => { val: { month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }, }, }); + const alert = { id: constants.unreadMessagesAlertId, children: alertMessage, success: true, timeout: 0 }; const newAlerts = alerts.filter((item) => item.id !== constants.unreadMessagesAlertId); - await store.setState({ alerts: (newAlerts.push(alert), newAlerts) }); + await store.setState({ alerts: (newAlerts.push(alert), newAlerts), unread: unreadMessages.length }); } - - await store.setState({ unread: unreadMessages.length }); } }; diff --git a/packages/livechat/src/routes/Chat/component.js b/packages/livechat/src/routes/Chat/component.js index 64ee65dc011c..b7c1d290da49 100644 --- a/packages/livechat/src/routes/Chat/component.js +++ b/packages/livechat/src/routes/Chat/component.js @@ -162,6 +162,7 @@ class Chat extends Component { lastReadMessageId={lastReadMessageId} onScrollTo={this.handleScrollTo} handleEmojiClick={this.handleEmojiClick} + dispatch={dispatch} /> {this.state.emojiPickerActive && ( canRenderMessage(message)); + const lastRenderedMessage = renderedMessages[renderedMessages.length - 1]; + const prevRenderedMessages = prevMessages.filter((message) => canRenderMessage(message)); + + const shouldMarkUnread = shouldMarkAsUnread(); + + if ( + (lastRenderedMessage && lastRenderedMessage.u?._id === user?._id) || + (!shouldMarkUnread && renderedMessages?.length !== prevRenderedMessages?.length) + ) { + const nextLastMessage = lastRenderedMessage; + const lastReadMessage = getLastReadMessage(); + + if (nextLastMessage && nextLastMessage._id !== lastReadMessage?._id) { const newAlerts = prevAlerts.filter((item) => item.id !== constants.unreadMessagesAlertId); dispatch({ alerts: newAlerts, unread: null, lastReadMessageId: nextLastMessage._id }); } @@ -404,6 +411,7 @@ export const ChatConnector = ({ ref, t, ...props }) => ( queueInfo, incomingCallAlert, ongoingCall, + messageListPosition, }) => ( ( limitTextLength={limitTextLength} incomingCallAlert={incomingCallAlert} ongoingCall={ongoingCall} + messageListPosition={messageListPosition} /> )} From 913f7c420889e0c0f519d0487c2e8d6ff6095f4e Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 17 Apr 2023 12:18:23 -0300 Subject: [PATCH 2/2] Bump version to 6.1.3 --- HISTORY.md | 20 ++++++++++++++++++++ apps/meteor/.docker/Dockerfile.rhel | 2 +- apps/meteor/app/utils/rocketchat.info | 2 +- apps/meteor/package.json | 2 +- package.json | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7f3866a0b3c7..e3e54483ddb8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,4 +1,24 @@ +# 6.1.3 +`2023-04-17 ยท 1 ๐Ÿ› ยท 2 ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป` + +### Engine versions +- Node: `14.21.2` +- NPM: `6.14.17` +- MongoDB: `4.4, 5.0, 6.0` +- Apps-Engine: `1.38.1` + +### ๐Ÿ› Bug fixes + + +- Livechat notifications not working correctly ([#28741](https://github.com/RocketChat/Rocket.Chat/pull/28741)) + +### ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป Core Team ๐Ÿค“ + +- [@MartinSchoeler](https://github.com/MartinSchoeler) +- [@tassoevan](https://github.com/tassoevan) + + # 6.1.2 `2023-04-13 ยท 4 ๐Ÿ› ยท 3 ๐Ÿ” ยท 11 ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป` diff --git a/apps/meteor/.docker/Dockerfile.rhel b/apps/meteor/.docker/Dockerfile.rhel index 4fd3d51df934..04a30ec15679 100644 --- a/apps/meteor/.docker/Dockerfile.rhel +++ b/apps/meteor/.docker/Dockerfile.rhel @@ -1,6 +1,6 @@ FROM registry.access.redhat.com/ubi8/nodejs-12 -ENV RC_VERSION 6.1.2 +ENV RC_VERSION 6.1.3 MAINTAINER buildmaster@rocket.chat diff --git a/apps/meteor/app/utils/rocketchat.info b/apps/meteor/app/utils/rocketchat.info index 308fc96ecdbd..3af7adf1c275 100644 --- a/apps/meteor/app/utils/rocketchat.info +++ b/apps/meteor/app/utils/rocketchat.info @@ -1,3 +1,3 @@ { - "version": "6.1.2" + "version": "6.1.3" } diff --git a/apps/meteor/package.json b/apps/meteor/package.json index 6b420828b2f8..b6045d504d13 100644 --- a/apps/meteor/package.json +++ b/apps/meteor/package.json @@ -1,7 +1,7 @@ { "name": "@rocket.chat/meteor", "description": "The Ultimate Open Source WebChat Platform", - "version": "6.1.2", + "version": "6.1.3", "private": true, "author": { "name": "Rocket.Chat", diff --git a/package.json b/package.json index ec1781ab49f4..6fa827358a9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rocket.chat", - "version": "6.1.2", + "version": "6.1.3", "description": "Rocket.Chat Monorepo", "main": "index.js", "private": true,