diff --git a/e2e/testcafe-devextreme/tests/chat/messageList.ts b/e2e/testcafe-devextreme/tests/chat/messageList.ts index c566d53eab2c..a1027ab05d41 100644 --- a/e2e/testcafe-devextreme/tests/chat/messageList.ts +++ b/e2e/testcafe-devextreme/tests/chat/messageList.ts @@ -104,7 +104,7 @@ test('Messagelist appearance with scrollbar', async (t) => { user: userSecond, width: 400, height: 600, - showDateHeaders: false, + showDayHeaders: false, }); }); diff --git a/packages/devextreme/js/__internal/ui/chat/chat.ts b/packages/devextreme/js/__internal/ui/chat/chat.ts index d623e2d1f359..db482233792d 100644 --- a/packages/devextreme/js/__internal/ui/chat/chat.ts +++ b/packages/devextreme/js/__internal/ui/chat/chat.ts @@ -21,7 +21,7 @@ import MessageList from './messagelist'; const CHAT_CLASS = 'dx-chat'; const TEXTEDITOR_INPUT_CLASS = 'dx-texteditor-input'; -type Properties = ChatProperties & { title: string; showDateHeaders: boolean }; +type Properties = ChatProperties & { title: string; showDayHeaders: boolean }; class Chat extends Widget { _chatHeader?: ChatHeader; @@ -43,7 +43,7 @@ class Chat extends Widget { dataSource: null, user: { id: new Guid().toString() }, onMessageSend: undefined, - showDateHeaders: true, + showDayHeaders: true, }; } @@ -99,7 +99,7 @@ class Chat extends Widget { } _renderMessageList(): void { - const { items = [], user, showDateHeaders } = this.option(); + const { items = [], user, showDayHeaders } = this.option(); const currentUserId = user?.id; const $messageList = $('
'); @@ -109,7 +109,7 @@ class Chat extends Widget { this._messageList = this._createComponent($messageList, MessageList, { items, currentUserId, - showDateHeaders, + showDayHeaders, }); } @@ -217,7 +217,8 @@ class Chat extends Widget { case 'onMessageSend': this._createMessageSendAction(); break; - case 'showDateHeaders': + case 'showDayHeaders': + this._messageList.option(name, value); break; default: super._optionChanged(args); diff --git a/packages/devextreme/js/__internal/ui/chat/messagelist.ts b/packages/devextreme/js/__internal/ui/chat/messagelist.ts index 1eb570bd5a37..d29227498e03 100644 --- a/packages/devextreme/js/__internal/ui/chat/messagelist.ts +++ b/packages/devextreme/js/__internal/ui/chat/messagelist.ts @@ -24,7 +24,7 @@ const CHAT_MESSAGELIST_EMPTY_VIEW_CLASS = 'dx-chat-messagelist-empty-view'; const CHAT_MESSAGELIST_EMPTY_IMAGE_CLASS = 'dx-chat-messagelist-empty-image'; const CHAT_MESSAGELIST_EMPTY_MESSAGE_CLASS = 'dx-chat-messagelist-empty-message'; const CHAT_MESSAGELIST_EMPTY_PROMPT_CLASS = 'dx-chat-messagelist-empty-prompt'; -const CHAT_MESSAGELIST_DATE_HEADER_CLASS = 'dx-chat-messagelist-date-header'; +const CHAT_MESSAGELIST_DAY_HEADER_CLASS = 'dx-chat-messagelist-day-header'; const SCROLLABLE_CONTAINER_CLASS = 'dx-scrollable-container'; export const MESSAGEGROUP_TIMEOUT = 5 * 1000 * 60; @@ -32,13 +32,13 @@ export const MESSAGEGROUP_TIMEOUT = 5 * 1000 * 60; export interface Properties extends WidgetOptions { items: Message[]; currentUserId: number | string | undefined; - showDateHeaders: boolean; + showDayHeaders: boolean; } class MessageList extends Widget { private _messageGroups?: MessageGroup[]; - private _messageDate?: null | string | number | Date; + private _lastMessageDate?: null | string | number | Date; private _containerClientHeight!: number; @@ -49,7 +49,7 @@ class MessageList extends Widget { ...super._getDefaultOptions(), items: [], currentUserId: '', - showDateHeaders: true, + showDayHeaders: true, }; } @@ -57,7 +57,7 @@ class MessageList extends Widget { super._init(); this._messageGroups = []; - this._messageDate = null; + this._lastMessageDate = null; } _initMarkup(): void { @@ -176,9 +176,9 @@ class MessageList extends Widget { }); } - _shouldAddDateHeader(timestamp: undefined | string | number | Date): boolean { - const { showDateHeaders } = this.option(); - if (timestamp === undefined || !showDateHeaders) { + _shouldAddDayHeader(timestamp: undefined | string | number | Date): boolean { + const { showDayHeaders } = this.option(); + if (timestamp === undefined || !showDayHeaders) { return false; } @@ -188,18 +188,14 @@ class MessageList extends Widget { return false; } - return !dateUtils.sameDate(this._messageDate, deserializedDate); + return !dateUtils.sameDate(this._lastMessageDate, deserializedDate); } - _createMessageDateHeader(timestamp: string | number | Date | undefined): void { - if (timestamp === undefined) { - return; - } - + _createDayHeader(timestamp: string | number | Date | undefined): void { const deserializedDate = dateSerialization.deserializeDate(timestamp); const today = new Date(); const yesterday = new Date(new Date().setDate(today.getDate() - 1)); - this._messageDate = deserializedDate; + this._lastMessageDate = deserializedDate; let headerDate = deserializedDate.toLocaleDateString(undefined, { day: '2-digit', @@ -216,7 +212,7 @@ class MessageList extends Widget { } $('
') - .addClass(CHAT_MESSAGELIST_DATE_HEADER_CLASS) + .addClass(CHAT_MESSAGELIST_DAY_HEADER_CLASS) .text(headerDate) .appendTo(this._$content()); } @@ -236,12 +232,12 @@ class MessageList extends Widget { items.forEach((item, index) => { const newMessageGroupItem = item ?? {}; const id = newMessageGroupItem.author?.id; - const shouldCreateDateHeader = this._shouldAddDateHeader(item?.timestamp); + const shouldCreateDayHeader = this._shouldAddDayHeader(item?.timestamp); const isTimeoutExceeded = this._isTimeoutExceeded( currentMessageGroupItems[currentMessageGroupItems.length - 1] ?? {}, item, ); - const shouldCreateMessageGroup = (shouldCreateDateHeader && currentMessageGroupItems.length) + const shouldCreateMessageGroup = (shouldCreateDayHeader && currentMessageGroupItems.length) || isTimeoutExceeded || id !== currentMessageGroupUserId; @@ -255,8 +251,8 @@ class MessageList extends Widget { currentMessageGroupItems.push(newMessageGroupItem); } - if (shouldCreateDateHeader) { - this._createMessageDateHeader(item?.timestamp); + if (shouldCreateDayHeader) { + this._createDayHeader(item?.timestamp); } if (items.length - 1 === index) { @@ -269,7 +265,7 @@ class MessageList extends Widget { const { author, timestamp } = message; const lastMessageGroup = this._messageGroups?.[this._messageGroups.length - 1]; - const shouldCreateDateHeader = this._shouldAddDateHeader(timestamp); + const shouldCreateDayHeader = this._shouldAddDayHeader(timestamp); if (lastMessageGroup) { const { items } = lastMessageGroup.option(); @@ -277,7 +273,7 @@ class MessageList extends Widget { const lastMessageGroupUserId = lastMessageGroupItem.author?.id; const isTimeoutExceeded = this._isTimeoutExceeded(lastMessageGroupItem, message); - if (author?.id === lastMessageGroupUserId && !isTimeoutExceeded && !shouldCreateDateHeader) { + if (author?.id === lastMessageGroupUserId && !isTimeoutExceeded && !shouldCreateDayHeader) { lastMessageGroup.renderMessage(message); this._scrollContentToLastMessage(); @@ -285,8 +281,8 @@ class MessageList extends Widget { } } - if (shouldCreateDateHeader) { - this._createMessageDateHeader(timestamp); + if (shouldCreateDayHeader) { + this._createDayHeader(timestamp); } this._createMessageGroupComponent([message], author?.id); @@ -389,7 +385,8 @@ class MessageList extends Widget { case 'items': this._processItemsUpdating(value ?? [], previousValue ?? []); break; - case 'showDateHeaders': + case 'showDayHeaders': + this._invalidate(); break; default: super._optionChanged(args);