refactor(platform): extract blurActiveElement to infrastructure module
- Centralize duplicated Platform.OS === 'web' blur logic across 16 components - Add blurActiveElement utility to src/infrastructure/platform module - Optimize MessageBubble and ImageSegment with React.memo custom comparators - Add useMemo for computed values in MessageSegmentsRenderer - Update DTO types with is_system_notice and notice_content fields - Fix keyboard dismissal order in useChatScreen handleDismiss - Simplify userStore follow/unfollow state updates - Remove unnecessary TypeScript type assertions throughout codebase
This commit is contained in:
@@ -174,9 +174,9 @@ export const useChatScreen = () => {
|
||||
status: (m.status || 'normal') as MessageStatus,
|
||||
category: m.category,
|
||||
created_at: m.created_at,
|
||||
sender: (m as any).sender,
|
||||
is_system_notice: (m as any).is_system_notice,
|
||||
notice_content: (m as any).notice_content,
|
||||
sender: m.sender,
|
||||
is_system_notice: m.is_system_notice,
|
||||
notice_content: m.notice_content,
|
||||
}));
|
||||
}, [messageManagerMessages]);
|
||||
|
||||
@@ -258,7 +258,7 @@ export const useChatScreen = () => {
|
||||
setOtherUser(prev => ({ ...(prev || {}), ...other }));
|
||||
}
|
||||
// 获取对方最后阅读位置
|
||||
setOtherUserLastReadSeq((conversation as any).other_last_read_seq || 0);
|
||||
setOtherUserLastReadSeq(conversation.other_last_read_seq || 0);
|
||||
}
|
||||
}, [conversation, isGroupChat, currentUserId]);
|
||||
|
||||
@@ -273,8 +273,8 @@ export const useChatScreen = () => {
|
||||
const detail = await userManager.getUserById(String(otherUserId), true);
|
||||
if (!detail || cancelled) return;
|
||||
setOtherUser(prev => ({ ...(prev || {}), ...detail }));
|
||||
if (typeof (detail as any).is_following_me === 'boolean') {
|
||||
setIsFollowedByOther((detail as any).is_following_me);
|
||||
if (typeof detail.is_following_me === 'boolean') {
|
||||
setIsFollowedByOther(detail.is_following_me);
|
||||
} else {
|
||||
setIsFollowedByOther(null);
|
||||
}
|
||||
@@ -360,7 +360,7 @@ export const useChatScreen = () => {
|
||||
}, [loading, loadingMore, messages.length, scrollToLatest]);
|
||||
|
||||
// 新消息跟随策略(Telegram/QQ 风格):
|
||||
// 仅当“最新端消息 seq 增长”且用户在底部附近时才跟随;
|
||||
// 仅当"最新端消息 seq 增长"且用户在底部附近时才跟随;
|
||||
// 历史加载只会增加旧消息,不会提升 latest seq,因此不会触发回底。
|
||||
useEffect(() => {
|
||||
const currentCount = messages.length;
|
||||
@@ -371,14 +371,14 @@ export const useChatScreen = () => {
|
||||
|
||||
if (loading || loadingMore) return;
|
||||
if (latestSeq <= prevLatestSeq) return;
|
||||
if (suppressAutoFollowRef.current) return;
|
||||
if (suppressAutoFollowRef.current || isBrowsingHistoryRef.current || isHistoryLoadingLocked()) return;
|
||||
if (!isNearBottom()) return;
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
scrollToLatest(false, false, 'new-message-follow');
|
||||
}, 0);
|
||||
return () => clearTimeout(timer);
|
||||
}, [messages, loading, loadingMore, isNearBottom, scrollToLatest]);
|
||||
}, [messages, loading, loadingMore, isNearBottom, scrollToLatest, isHistoryLoadingLocked]);
|
||||
|
||||
// 获取当前用户信息
|
||||
useEffect(() => {
|
||||
@@ -559,10 +559,10 @@ export const useChatScreen = () => {
|
||||
if (!conversationId) return;
|
||||
if (!conversation) return;
|
||||
|
||||
const unreadCount = Number((conversation as any).unread_count || 0);
|
||||
const unreadCount = Number(conversation.unread_count || 0);
|
||||
if (unreadCount <= 0) return;
|
||||
|
||||
const latestFromConversation = Number((conversation as any).last_seq || 0);
|
||||
const latestFromConversation = Number(conversation.last_seq || 0);
|
||||
const latestFromMessages = messages.length > 0 ? Math.max(...messages.map(m => m.seq || 0)) : 0;
|
||||
const targetSeq = Math.max(latestFromConversation, latestFromMessages);
|
||||
if (targetSeq <= 0) return;
|
||||
@@ -1305,8 +1305,8 @@ export const useChatScreen = () => {
|
||||
|
||||
// 关闭所有面板
|
||||
const handleDismiss = useCallback(() => {
|
||||
Keyboard.dismiss();
|
||||
if (activePanel !== 'none') {
|
||||
Keyboard.dismiss();
|
||||
setActivePanel('none');
|
||||
}
|
||||
}, [activePanel]);
|
||||
|
||||
Reference in New Issue
Block a user