fix(message): add robust NaN validation for date handling across components
Add comprehensive date validation using Number.isNaN() checks to prevent crashes when timestamps are invalid or empty. Apply defensive formatting across CommentItem, SystemMessageItem, MessageBubble, LongPressMenu, and store utilities. Refine message bubble styling: move sender name display to both sides in group chat with distinct `mySenderName` styling, adjust bubble corner radius to top-right for consistent arrow placement, and align message rows to flex-start for improved layout. Simplify group avatar rendering in ConversationListRow.
This commit is contained in:
@@ -137,7 +137,9 @@ export class WSMessageHandler implements IWSMessageHandler {
|
||||
if (message.created_at) {
|
||||
const store = useMessageStore.getState();
|
||||
const currentLast = store.lastSystemMessageAt;
|
||||
if (!currentLast || new Date(message.created_at) > new Date(currentLast)) {
|
||||
const msgDate = new Date(message.created_at);
|
||||
if (Number.isNaN(msgDate.getTime())) return;
|
||||
if (!currentLast || msgDate > new Date(currentLast)) {
|
||||
store.setLastSystemMessageAt(message.created_at);
|
||||
}
|
||||
}
|
||||
@@ -335,7 +337,7 @@ export class WSMessageHandler implements IWSMessageHandler {
|
||||
content: textContent,
|
||||
type: segments?.find((s: any) => s.type === 'image') ? 'image' : 'text',
|
||||
isRead: isActiveConversation,
|
||||
createdAt: new Date(created_at).toISOString(),
|
||||
createdAt: (() => { const d = new Date(created_at); return Number.isNaN(d.getTime()) ? new Date().toISOString() : d.toISOString(); })(),
|
||||
seq,
|
||||
status: 'normal',
|
||||
segments,
|
||||
@@ -451,7 +453,7 @@ export class WSMessageHandler implements IWSMessageHandler {
|
||||
: [],
|
||||
status: 'normal',
|
||||
category: 'notification',
|
||||
created_at: new Date(timestamp || Date.now()).toISOString(),
|
||||
created_at: (() => { const d = new Date(timestamp || Date.now()); return Number.isNaN(d.getTime()) ? new Date().toISOString() : d.toISOString(); })(),
|
||||
};
|
||||
|
||||
const updatedMessages = [...existingMessages, systemNoticeMessage].sort((a, b) => a.seq - b.seq);
|
||||
|
||||
@@ -134,6 +134,7 @@ function sortConversationList(conversations: Map<string, ConversationResponse>):
|
||||
}
|
||||
const aTime = new Date(a.last_message_at || a.updated_at || 0).getTime();
|
||||
const bTime = new Date(b.last_message_at || b.updated_at || 0).getTime();
|
||||
if (Number.isNaN(aTime) || Number.isNaN(bTime)) return 0;
|
||||
return bTime - aTime;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user