refactor(post): consolidate post sync to PostSyncService and remove ProcessPostUseCase
- Replace ProcessPostUseCase with new PostSyncService in src/services/post/ - Add postListStore for state management in src/stores/post/ - Remove deprecated ProcessPostUseCase and ProcessMessageUseCase files - Delete architecture documentation files (ARCHITECTURE_REFACTOR_PLAN.md, architecture-comparison-report.md) - Update all consumers (HomeScreen, PostDetailScreen, SearchScreen, useUserProfile, useDifferentialPosts) - Simplify postService to only contain API layer methods - Remove unused type exports from message stores BREAKING CHANGE: ProcessPostUseCase and ProcessMessageUseCase have been removed. Use postSyncService for post operations instead.
This commit is contained in:
@@ -34,7 +34,7 @@ import type { PostCardAction } from '../../components/business/PostCard';
|
||||
import { Loading, EmptyState, Text, ImageGallery, ImageGridItem, ResponsiveGrid } from '../../components/common';
|
||||
import { useResponsive, useResponsiveSpacing } from '../../hooks/useResponsive';
|
||||
import { useDifferentialPosts } from '../../hooks/useDifferentialPosts';
|
||||
import { processPostUseCase } from '../../core/usecases/ProcessPostUseCase';
|
||||
import { postSyncService } from '../../services/post/PostSyncService';
|
||||
import { SearchScreen } from './SearchScreen';
|
||||
import { CreatePostScreen } from '../create/CreatePostScreen';
|
||||
import * as hrefs from '../../navigation/hrefs';
|
||||
@@ -375,7 +375,7 @@ export const HomeScreen: React.FC = () => {
|
||||
isLoadingMoreRef.current = true;
|
||||
const startedAt = Date.now();
|
||||
try {
|
||||
await processPostUseCase.loadMorePosts(listKey);
|
||||
await postSyncService.loadMorePosts(listKey);
|
||||
console.log('[PostPerf] home loadMore', {
|
||||
listKey,
|
||||
costMs: Date.now() - startedAt,
|
||||
@@ -409,7 +409,7 @@ export const HomeScreen: React.FC = () => {
|
||||
const refresh = useCallback(async () => {
|
||||
try {
|
||||
// 先获取正确类型的帖子
|
||||
await processPostUseCase.fetchPosts(
|
||||
await postSyncService.fetchPosts(
|
||||
{
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
@@ -554,9 +554,9 @@ export const HomeScreen: React.FC = () => {
|
||||
const handleLike = async (post: Post) => {
|
||||
try {
|
||||
if (post.is_liked) {
|
||||
await processPostUseCase.unlikePost(post.id);
|
||||
await postSyncService.unlikePost(post.id);
|
||||
} else {
|
||||
await processPostUseCase.likePost(post.id);
|
||||
await postSyncService.likePost(post.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('点赞操作失败:', error);
|
||||
@@ -567,9 +567,9 @@ export const HomeScreen: React.FC = () => {
|
||||
const handleBookmark = async (post: Post) => {
|
||||
try {
|
||||
if (post.is_favorited) {
|
||||
await processPostUseCase.unfavoritePost(post.id);
|
||||
await postSyncService.unfavoritePost(post.id);
|
||||
} else {
|
||||
await processPostUseCase.favoritePost(post.id);
|
||||
await postSyncService.favoritePost(post.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('收藏操作失败:', error);
|
||||
@@ -582,7 +582,7 @@ export const HomeScreen: React.FC = () => {
|
||||
try {
|
||||
const res = await postService.sharePost(post.id, { channel: 'copy_link' });
|
||||
if (res.ok && res.shares_count != null) {
|
||||
processPostUseCase.applyShareCountUpdate(post.id, res.shares_count);
|
||||
postSyncService.applyShareCountUpdate(post.id, res.shares_count);
|
||||
}
|
||||
} catch (shareError) {
|
||||
console.error('上报分享次数失败:', shareError);
|
||||
|
||||
@@ -37,7 +37,7 @@ import { Post, Comment, VoteResultDTO, VoteOptionDTO } from '../../types';
|
||||
import { useUserStore } from '../../stores';
|
||||
import { useCurrentUser } from '../../stores/authStore';
|
||||
import { postService, commentService, uploadService, authService, showPrompt, voteService } from '../../services';
|
||||
import { processPostUseCase } from '../../core/usecases/ProcessPostUseCase';
|
||||
import { postSyncService } from '../../services/post/PostSyncService';
|
||||
import { useCursorPagination } from '../../hooks/useCursorPagination';
|
||||
import { CommentItem, VoteCard, ReportDialog } from '../../components/business';
|
||||
import { Avatar, Button, Loading, EmptyState, Text, ImageGallery, ImageGrid, ImageGridItem, AdaptiveLayout, AppBackButton } from '../../components/common';
|
||||
@@ -238,7 +238,7 @@ export const PostDetailScreen: React.FC = () => {
|
||||
|
||||
try {
|
||||
// 使用 ProcessPostUseCase 获取帖子详情
|
||||
const postData = await processPostUseCase.fetchPostById(postId);
|
||||
const postData = await postSyncService.fetchPostById(postId);
|
||||
if (postData) {
|
||||
// 类型转换:将 core/entities/Post 转换为 PostDTO 以保持兼容性
|
||||
setPost(postData as unknown as Post);
|
||||
@@ -487,9 +487,9 @@ export const PostDetailScreen: React.FC = () => {
|
||||
|
||||
try {
|
||||
if (originalPost.is_liked) {
|
||||
await processPostUseCase.unlikePost(post.id);
|
||||
await postSyncService.unlikePost(post.id);
|
||||
} else {
|
||||
await processPostUseCase.likePost(post.id);
|
||||
await postSyncService.likePost(post.id);
|
||||
}
|
||||
} catch (error) {
|
||||
handleError(error, { context: '点赞' });
|
||||
@@ -505,9 +505,9 @@ export const PostDetailScreen: React.FC = () => {
|
||||
|
||||
try {
|
||||
if (originalPost.is_favorited) {
|
||||
await processPostUseCase.unfavoritePost(post.id);
|
||||
await postSyncService.unfavoritePost(post.id);
|
||||
} else {
|
||||
await processPostUseCase.favoritePost(post.id);
|
||||
await postSyncService.favoritePost(post.id);
|
||||
}
|
||||
} catch (error) {
|
||||
handleError(error, { context: '收藏' });
|
||||
@@ -526,7 +526,7 @@ export const PostDetailScreen: React.FC = () => {
|
||||
? { ...prev, shares_count: res.shares_count!, sharesCount: res.shares_count! }
|
||||
: null
|
||||
);
|
||||
processPostUseCase.applyShareCountUpdate(post.id, res.shares_count);
|
||||
postSyncService.applyShareCountUpdate(post.id, res.shares_count);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('上报分享次数失败:', error);
|
||||
@@ -635,7 +635,7 @@ export const PostDetailScreen: React.FC = () => {
|
||||
onPress: async () => {
|
||||
setIsDeleting(true);
|
||||
try {
|
||||
await processPostUseCase.deletePost(post.id);
|
||||
await postSyncService.deletePost(post.id);
|
||||
Alert.alert('删除成功', '帖子已删除', [
|
||||
{
|
||||
text: '确定',
|
||||
|
||||
@@ -20,6 +20,7 @@ import { spacing, fontSizes, borderRadius, useAppColors, type AppColors } from '
|
||||
import { Post, User } from '../../types';
|
||||
import { useUserStore } from '../../stores';
|
||||
import { postService, authService } from '../../services';
|
||||
import { postSyncService } from '../../services/post/PostSyncService';
|
||||
import { PostCard, TabBar, SearchBar } from '../../components/business';
|
||||
import type { PostCardAction } from '../../components/business/PostCard';
|
||||
import { Avatar, EmptyState, Text, ResponsiveGrid, Loading } from '../../components/common';
|
||||
@@ -185,19 +186,19 @@ export const SearchScreen: React.FC<SearchScreenProps> = ({ onBack }) => {
|
||||
}
|
||||
break;
|
||||
case 'like':
|
||||
postService.likePost(post.id);
|
||||
postSyncService.likePost(post.id);
|
||||
break;
|
||||
case 'unlike':
|
||||
postService.unlikePost(post.id);
|
||||
postSyncService.unlikePost(post.id);
|
||||
break;
|
||||
case 'comment':
|
||||
handlePostPress(post.id, true);
|
||||
break;
|
||||
case 'bookmark':
|
||||
postService.favoritePost(post.id);
|
||||
postSyncService.favoritePost(post.id);
|
||||
break;
|
||||
case 'unbookmark':
|
||||
postService.unfavoritePost(post.id);
|
||||
postSyncService.unfavoritePost(post.id);
|
||||
break;
|
||||
case 'share':
|
||||
// 搜索页暂不处理分享
|
||||
|
||||
@@ -862,11 +862,9 @@ function createSegmentStyles(colors: AppColors, fontSize: number = 16) {
|
||||
// 容器
|
||||
segmentsContainer: {
|
||||
flexDirection: 'column',
|
||||
width: '100%',
|
||||
},
|
||||
segmentsColumn: {
|
||||
flexDirection: 'column',
|
||||
width: '100%',
|
||||
},
|
||||
inlineChunkBase: {
|
||||
fontSize,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Post, User } from '../../types';
|
||||
import { useUserStore } from '../../stores';
|
||||
import { useCurrentUser } from '../../stores/authStore';
|
||||
import { postService, authService, messageService } from '../../services';
|
||||
import { postSyncService } from '../../services/post/PostSyncService';
|
||||
import { userManager } from '../../stores/userManager';
|
||||
import * as hrefs from '../../navigation/hrefs';
|
||||
import { PostCardAction } from '../../components/business/PostCard';
|
||||
@@ -310,16 +311,23 @@ export const useUserProfile = (options: UseUserProfileOptions): UseUserProfileRe
|
||||
handleUserPress(post.author.id);
|
||||
}
|
||||
break;
|
||||
case 'like':
|
||||
case 'like':
|
||||
case 'unlike':
|
||||
post.is_liked ? postService.unlikePost(post.id) : postService.likePost(post.id);
|
||||
post.is_liked ? postSyncService.unlikePost(post.id) : postSyncService.likePost(post.id);
|
||||
break;
|
||||
case 'comment':
|
||||
handlePostPress(post.id, true);
|
||||
break;
|
||||
case 'bookmark':
|
||||
case 'unbookmark':
|
||||
post.is_favorited ? postService.unfavoritePost(post.id) : postService.favoritePost(post.id);
|
||||
post.is_favorited ? postSyncService.unfavoritePost(post.id) : postSyncService.favoritePost(post.id);
|
||||
break;
|
||||
case 'comment':
|
||||
handlePostPress(post.id, true);
|
||||
break;
|
||||
case 'bookmark':
|
||||
case 'unbookmark':
|
||||
post.is_favorited ? postSyncService.unfavoritePost(post.id) : postSyncService.favoritePost(post.id);
|
||||
break;
|
||||
case 'share':
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user