feat(pagination): implement cursor-based pagination across the app

Add useCursorPagination hook and update multiple screens and services
to use cursor-based pagination for better performance and consistency.

- Add useCursorPagination hook with deduplication and caching support
- Add cursor pagination types to infrastructure layer
- Refactor HomeScreen, PostDetailScreen, SearchScreen for posts/comments
- Refactor GroupMembersScreen, JoinGroupScreen for groups/members
- Refactor MessageListScreen, NotificationsScreen for messages
- Update post, message, group, comment, notification services with cursor endpoints
- Add CursorPaginationRequest/Response DTOs
- Remove deprecated OPTIMIZATION_DESIGN.md documentation
This commit is contained in:
lafay
2026-03-20 23:00:27 +08:00
parent a005fb0a15
commit 8a0aea1c59
20 changed files with 2464 additions and 2166 deletions

View File

@@ -15,8 +15,11 @@ import {
UnreadCountResponse,
ConversationUnreadCountResponse,
SystemMessageListResponse,
SystemMessageResponse,
SystemUnreadCountResponse,
MessageSegment,
CursorPaginationRequest,
CursorPaginationResponse,
} from '../types/dto';
import {
getConversationCache,
@@ -555,6 +558,85 @@ class MessageService {
await api.put('/messages/system/read-all');
}
// ==================== 游标分页方法 ====================
/**
* 获取会话列表(游标分页)
* GET /api/v1/conversations/cursor
* @param params 游标分页请求参数
*/
async getConversationsCursor(
params: CursorPaginationRequest = {}
): Promise<CursorPaginationResponse<ConversationResponse>> {
try {
const response = await api.get<CursorPaginationResponse<ConversationResponse>>(
'/conversations/cursor',
{ params }
);
return response.data;
} catch (error) {
console.error('获取会话列表失败:', error);
return {
items: [],
next_cursor: null,
prev_cursor: null,
has_more: false,
};
}
}
/**
* 获取消息列表(游标分页)
* GET /api/v1/conversations/:id/messages/cursor
* @param conversationId 会话ID
* @param params 游标分页请求参数
*/
async getMessagesCursor(
conversationId: string,
params: CursorPaginationRequest = {}
): Promise<CursorPaginationResponse<MessageResponse>> {
try {
const response = await api.get<CursorPaginationResponse<MessageResponse>>(
`/conversations/${encodeURIComponent(conversationId)}/messages/cursor`,
{ params }
);
return response.data;
} catch (error) {
console.error('获取消息列表失败:', error);
return {
items: [],
next_cursor: null,
prev_cursor: null,
has_more: false,
};
}
}
/**
* 获取系统消息列表(游标分页)
* GET /api/v1/messages/system/cursor
* @param params 游标分页请求参数
*/
async getSystemMessagesCursor(
params: CursorPaginationRequest = {}
): Promise<CursorPaginationResponse<SystemMessageResponse>> {
try {
const response = await api.get<CursorPaginationResponse<SystemMessageResponse>>(
'/messages/system/cursor',
{ params }
);
return response.data;
} catch (error) {
console.error('获取系统消息列表失败:', error);
return {
items: [],
next_cursor: null,
prev_cursor: null,
has_more: false,
};
}
}
// ==================== 兼容旧API的方法将逐步废弃 ====================
/**