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:
@@ -657,8 +657,10 @@ export const useChatScreen = (props?: ChatScreenProps) => {
|
||||
|
||||
// 格式化时间
|
||||
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);
|
||||
|
||||
@@ -680,9 +682,10 @@ export const useChatScreen = (props?: ChatScreenProps) => {
|
||||
if (index === 0) return true;
|
||||
const currentMsg = messages[index];
|
||||
const prevMsg = messages[index - 1];
|
||||
const currentTime = new Date(currentMsg.created_at).getTime();
|
||||
const prevTime = new Date(prevMsg.created_at).getTime();
|
||||
return (currentTime - prevTime) > TIME_SEPARATOR_INTERVAL;
|
||||
const currentDate = new Date(currentMsg.created_at);
|
||||
const prevDate = new Date(prevMsg.created_at);
|
||||
if (Number.isNaN(currentDate.getTime()) || Number.isNaN(prevDate.getTime())) return false;
|
||||
return (currentDate.getTime() - prevDate.getTime()) > TIME_SEPARATOR_INTERVAL;
|
||||
}, [messages]);
|
||||
|
||||
// 处理输入变化,检测@符号
|
||||
|
||||
Reference in New Issue
Block a user