refactor: migrate post operations to use case architecture with differential updates
Migrate post-related operations from direct service/store calls to a new use case architecture featuring differential updates. Key changes include: (1) introduce ProcessPostUseCase to handle like, unlike, favorite, unfavorite, delete, and fetch operations with proper state management, (2) add useDifferentialPosts hook for efficient list rendering with minimal re-renders, (3) add PostDiffCalculator and PostUpdateBatcher in infrastructure layer for incremental updates, (4) deprecate NotificationItem component in favor of SystemMessageItem, (5) remove deprecated interactive methods from userStore, (6) add posts_cache table to local datasource, (7) clean up legacy MessageDTO and ConversationDTO types, (8) remove deprecated hook useBreakpointCheck, (9) refactor MessageBubble to use measureInWindow directly for better React Native compatibility
This commit is contained in:
@@ -403,17 +403,6 @@ class GroupService {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 兼容旧API的方法(将逐步废弃) ====================
|
||||
|
||||
/**
|
||||
* @deprecated 使用 setGroupName 代替
|
||||
*/
|
||||
async updateGroup(id: number, data: { name: string }): Promise<GroupResponse> {
|
||||
await this.setGroupName(id, data.name);
|
||||
return this.getGroup(id);
|
||||
}
|
||||
}
|
||||
|
||||
// 导出群组服务实例
|
||||
export const groupService = new GroupService();
|
||||
|
||||
|
||||
@@ -671,32 +671,6 @@ class MessageService {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 兼容旧API的方法(将逐步废弃) ====================
|
||||
|
||||
/**
|
||||
* @deprecated 使用 getConversations 代替
|
||||
*/
|
||||
async getConversation(conversationId: string): Promise<ConversationDetailResponse | null> {
|
||||
try {
|
||||
return await this.getConversationById(conversationId);
|
||||
} catch (error) {
|
||||
console.error('获取会话详情失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 使用 createConversation(userId: string) 代替
|
||||
*/
|
||||
async createConversationByString(userId: string): Promise<ConversationResponse | null> {
|
||||
try {
|
||||
return await this.createConversation(userId);
|
||||
} catch (error) {
|
||||
console.error('创建会话失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出消息服务实例
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
/**
|
||||
* 帖子服务
|
||||
* 处理帖子的增删改查、点赞、收藏等功能
|
||||
*
|
||||
* @deprecated 此服务已弃用,请使用 ProcessPostUseCase 代替
|
||||
* 互动操作(点赞、收藏)已委托给 processPostUseCase
|
||||
*/
|
||||
|
||||
import { api, PaginatedData } from './api';
|
||||
import { Post, CreatePostInput } from '../types';
|
||||
import { CursorPaginationRequest, CursorPaginationResponse } from '../types/dto';
|
||||
import { processPostUseCase } from '../core/usecases/ProcessPostUseCase';
|
||||
import type { Post as PostEntity } from '../core/entities/Post';
|
||||
|
||||
// 帖子列表响应
|
||||
interface PostListResponse {
|
||||
@@ -129,14 +134,12 @@ class PostService {
|
||||
}
|
||||
|
||||
// 点赞帖子
|
||||
// @deprecated 请使用 processPostUseCase.likePost() 代替
|
||||
async likePost(postId: string): Promise<Post | null> {
|
||||
try {
|
||||
const response = await api.post<Post>(`/posts/${postId}/like`);
|
||||
if (response.code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
console.warn('[postService] likePost failed, code:', response.code);
|
||||
return null;
|
||||
const post = await processPostUseCase.likePost(postId);
|
||||
// 转换为旧版 Post 类型以保持向后兼容
|
||||
return post as unknown as Post;
|
||||
} catch (error) {
|
||||
console.error('[postService] likePost error:', error);
|
||||
return null;
|
||||
@@ -144,14 +147,11 @@ class PostService {
|
||||
}
|
||||
|
||||
// 取消点赞帖子
|
||||
// @deprecated 请使用 processPostUseCase.unlikePost() 代替
|
||||
async unlikePost(postId: string): Promise<Post | null> {
|
||||
try {
|
||||
const response = await api.delete<Post>(`/posts/${postId}/like`);
|
||||
if (response.code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
console.warn('[postService] unlikePost failed, code:', response.code);
|
||||
return null;
|
||||
const post = await processPostUseCase.unlikePost(postId);
|
||||
return post as unknown as Post;
|
||||
} catch (error) {
|
||||
console.error('[postService] unlikePost error:', error);
|
||||
return null;
|
||||
@@ -159,14 +159,11 @@ class PostService {
|
||||
}
|
||||
|
||||
// 收藏帖子
|
||||
// @deprecated 请使用 processPostUseCase.favoritePost() 代替
|
||||
async favoritePost(postId: string): Promise<Post | null> {
|
||||
try {
|
||||
const response = await api.post<Post>(`/posts/${postId}/favorite`);
|
||||
if (response.code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
console.warn('[postService] favoritePost failed, code:', response.code);
|
||||
return null;
|
||||
const post = await processPostUseCase.favoritePost(postId);
|
||||
return post as unknown as Post;
|
||||
} catch (error) {
|
||||
console.error('[postService] favoritePost error:', error);
|
||||
return null;
|
||||
@@ -174,14 +171,11 @@ class PostService {
|
||||
}
|
||||
|
||||
// 取消收藏帖子
|
||||
// @deprecated 请使用 processPostUseCase.unfavoritePost() 代替
|
||||
async unfavoritePost(postId: string): Promise<Post | null> {
|
||||
try {
|
||||
const response = await api.delete<Post>(`/posts/${postId}/favorite`);
|
||||
if (response.code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
console.warn('[postService] unfavoritePost failed, code:', response.code);
|
||||
return null;
|
||||
const post = await processPostUseCase.unfavoritePost(postId);
|
||||
return post as unknown as Post;
|
||||
} catch (error) {
|
||||
console.error('[postService] unfavoritePost error:', error);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user