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:
@@ -245,8 +245,10 @@ export const MessageListScreen: React.FC = () => {
|
||||
|
||||
// 格式化时间(稳定引用,配合会话行 memo)
|
||||
const formatTime = useCallback((dateString: string): string => {
|
||||
if (!dateString) return '';
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
const now = new Date();
|
||||
const diffInHours = (now.getTime() - date.getTime()) / (1000 * 60 * 60);
|
||||
|
||||
@@ -483,7 +485,10 @@ export const MessageListScreen: React.FC = () => {
|
||||
const aPinned = a.is_pinned ? 1 : 0;
|
||||
const bPinned = b.is_pinned ? 1 : 0;
|
||||
if (aPinned !== bPinned) return bPinned - aPinned;
|
||||
return new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime();
|
||||
const aTime = new Date(a.updated_at || 0).getTime();
|
||||
const bTime = new Date(b.updated_at || 0).getTime();
|
||||
if (Number.isNaN(aTime) || Number.isNaN(bTime)) return 0;
|
||||
return bTime - aTime;
|
||||
});
|
||||
|
||||
const listConvRef = useRef(new Map<string, ConversationResponse>());
|
||||
|
||||
Reference in New Issue
Block a user