Skip to content

Commit

Permalink
Merge pull request #28917 from RocketChat/release-6.1.3
Browse files Browse the repository at this point in the history
Release 6.1.3
  • Loading branch information
sampaiodiego authored Apr 17, 2023
2 parents 7507d14 + 913f7c4 commit f280bc3
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 27 deletions.
20 changes: 20 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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 👩‍💻👨‍💻`

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/.docker/Dockerfile.rhel
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/utils/rocketchat.info
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "6.1.2"
"version": "6.1.3"
}
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rocket.chat",
"version": "6.1.2",
"version": "6.1.3",
"description": "Rocket.Chat Monorepo",
"main": "index.js",
"private": true,
Expand Down
20 changes: 19 additions & 1 deletion packages/livechat/src/components/Messages/MessageList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions packages/livechat/src/components/Messages/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
25 changes: 24 additions & 1 deletion packages/livechat/src/components/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);

Expand Down
58 changes: 46 additions & 12 deletions packages/livechat/src/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,63 @@ 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),
formatParams: {
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 });
}
};
1 change: 1 addition & 0 deletions packages/livechat/src/routes/Chat/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class Chat extends Component {
lastReadMessageId={lastReadMessageId}
onScrollTo={this.handleScrollTo}
handleEmojiClick={this.handleEmojiClick}
dispatch={dispatch}
/>
{this.state.emojiPickerActive && (
<Picker
Expand Down
27 changes: 18 additions & 9 deletions packages/livechat/src/routes/Chat/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ModalManager } from '../../components/Modal';
import { debounce, getAvatarUrl, canRenderMessage, throttle, upsert } from '../../components/helpers';
import { normalizeQueueAlert } from '../../lib/api';
import constants from '../../lib/constants';
import { loadConfig, processUnread } from '../../lib/main';
import { getLastReadMessage, loadConfig, processUnread, shouldMarkAsUnread } from '../../lib/main';
import { parentCall, runCallbackEventEmitter } from '../../lib/parentCall';
import { createToken } from '../../lib/random';
import { initRoom, closeChat, loadMessages, loadMoreMessages, defaultRoomParams, getGreetingMessages } from '../../lib/room';
Expand Down Expand Up @@ -321,16 +321,23 @@ class ChatContainer extends Component {
}

async componentDidUpdate(prevProps) {
const { messages, visible, minimized, dispatch } = this.props;
const { messages, dispatch, user } = this.props;
const { messages: prevMessages, alerts: prevAlerts } = prevProps;

if (messages && prevMessages && messages.length !== prevMessages.length && visible && !minimized) {
const nextLastMessage = messages[messages.length - 1];
const lastMessage = prevMessages[prevMessages.length - 1];
if (
(nextLastMessage && lastMessage && nextLastMessage._id !== lastMessage._id) ||
(messages.length === 1 && prevMessages.length === 0)
) {
const renderedMessages = messages.filter((message) => 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 });
}
Expand Down Expand Up @@ -404,6 +411,7 @@ export const ChatConnector = ({ ref, t, ...props }) => (
queueInfo,
incomingCallAlert,
ongoingCall,
messageListPosition,
}) => (
<ChatContainer
ref={ref}
Expand Down Expand Up @@ -471,6 +479,7 @@ export const ChatConnector = ({ ref, t, ...props }) => (
limitTextLength={limitTextLength}
incomingCallAlert={incomingCallAlert}
ongoingCall={ongoingCall}
messageListPosition={messageListPosition}
/>
)}
</Consumer>
Expand Down

0 comments on commit f280bc3

Please sign in to comment.