Skip to content

Commit

Permalink
refactor(chat): Rename && Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Sep 26, 2024
1 parent 924bcf1 commit 04bd795
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/devextreme/js/__internal/ui/chat/messagelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ class MessageList extends Widget<Properties> {
const newMessageGroupItem = item ?? {};
const id = newMessageGroupItem.author?.id;

const isTimeoutExpired = this._isTimeoutExpired(
const isTimeoutExceeded = this._isTimeoutExceeded(
currentMessageGroupItems[currentMessageGroupItems.length - 1] ?? {},
item,
);

if (id === currentMessageGroupUserId && !isTimeoutExpired) {
if (id === currentMessageGroupUserId && !isTimeoutExceeded) {
currentMessageGroupItems.push(newMessageGroupItem);
} else {
this._createMessageGroupComponent(currentMessageGroupItems, currentMessageGroupUserId);
Expand All @@ -167,9 +167,9 @@ class MessageList extends Widget<Properties> {
const lastMessageGroupItem = lastMessageGroup.option('items')[0];
const lastMessageGroupUserId = lastMessageGroupItem.author?.id;

const isTimeoutExpired = this._isTimeoutExpired(lastMessageGroupItem, message);
const isTimeoutExceeded = this._isTimeoutExceeded(lastMessageGroupItem, message);

if (sender?.id === lastMessageGroupUserId && !isTimeoutExpired) {
if (sender?.id === lastMessageGroupUserId && !isTimeoutExceeded) {
lastMessageGroup.renderMessage(message);

this.update();
Expand Down Expand Up @@ -234,18 +234,20 @@ class MessageList extends Widget<Properties> {
}
}

_isTimeoutExpired(lastMessage: Message, currentMessage: Message): boolean {
const lastTimestamp = lastMessage.timestamp;
const currentTimestamp = currentMessage.timestamp;
_isTimeoutExceeded(lastMessage: Message, newMessage: Message): boolean {
const lastMessageTimestamp = lastMessage?.timestamp;
const newMessageTimestamp = newMessage?.timestamp;

if (!lastTimestamp || !currentTimestamp) {
if (!lastMessageTimestamp || !newMessageTimestamp) {
return false;
}

const convertedLastTimestamp = new Date(lastTimestamp).getTime();
const convertedCurrentTimestamp = new Date(currentTimestamp).getTime();
const lastMessageTimestampInMs = new Date(lastMessageTimestamp).getTime();
const newMessageTimestampInMs = new Date(newMessageTimestamp).getTime();

return convertedCurrentTimestamp - convertedLastTimestamp > MESSAGEGROUP_TIMEOUT;
const result = newMessageTimestampInMs - lastMessageTimestampInMs > MESSAGEGROUP_TIMEOUT;

return result;
}

_optionChanged(args: OptionChanged<Properties>): void {
Expand Down

0 comments on commit 04bd795

Please sign in to comment.