refactor(stores): unify data sources pattern and extract BaseManager base class
- Add BaseManager/CachedManager base classes to eliminate duplicate cache logic - Add postListSources.ts with IPostListPagedSource interface - Add groupListSources.ts with IGroupListPagedSource interface - Refactor postManager to use CachedManager and Sources pattern - Refactor groupManager to use CachedManager and Sources pattern - Clean up duplicate methods in groupService.ts - Fix TypeScript errors and remove mock data
This commit is contained in:
@@ -9,17 +9,10 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { showConfirm } from './dialogService';
|
||||
|
||||
// 条件导入原生模块(仅在 Android 上可用)
|
||||
let FileSystem: typeof import('expo-file-system/legacy') | null = null;
|
||||
let IntentLauncher: typeof import('expo-intent-launcher') | null = null;
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
try {
|
||||
FileSystem = require('expo-file-system/legacy');
|
||||
IntentLauncher = require('expo-intent-launcher');
|
||||
} catch (e) {
|
||||
console.warn('Failed to load native modules for APK update:', e);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const FileSystem = Platform.OS === 'android' ? require('expo-file-system/legacy') : null;
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const IntentLauncher = Platform.OS === 'android' ? require('expo-intent-launcher') : null;
|
||||
|
||||
// 更新服务器地址
|
||||
const UPDATES_SERVER_URL = Constants.expoConfig?.extra?.updatesUrl
|
||||
|
||||
@@ -78,7 +78,13 @@ function normalizeAnnouncementCursor(
|
||||
// 群组服务类(纯 API 层)
|
||||
// SQLite/内存缓存编排由 groupManager 统一处理
|
||||
class GroupService {
|
||||
async fetchGroupsFromApi(page = 1, pageSize = 20): Promise<GroupListResponse> {
|
||||
// ==================== 群组管理 ====================
|
||||
|
||||
/**
|
||||
* 获取群组列表
|
||||
* GET /api/v1/groups
|
||||
*/
|
||||
async getGroups(page = 1, pageSize = 20): Promise<GroupListResponse> {
|
||||
const response = await api.get<GroupListResponse>('/groups', {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
@@ -86,16 +92,20 @@ class GroupService {
|
||||
return normalizeGroupListResponse(response.data);
|
||||
}
|
||||
|
||||
async fetchGroupFromApi(id: string): Promise<GroupResponse> {
|
||||
/**
|
||||
* 获取群组详情
|
||||
* GET /api/v1/groups/:id
|
||||
*/
|
||||
async getGroup(id: string): Promise<GroupResponse> {
|
||||
const response = await api.get<GroupResponse>(`/groups/${encodeURIComponent(id)}`);
|
||||
return normalizeGroup(response.data);
|
||||
}
|
||||
|
||||
async fetchMembersFromApi(
|
||||
groupId: string,
|
||||
page = 1,
|
||||
pageSize = 50
|
||||
): Promise<GroupMemberListResponse> {
|
||||
/**
|
||||
* 获取群组成员列表
|
||||
* GET /api/v1/groups/:id/members
|
||||
*/
|
||||
async getMembers(groupId: string, page = 1, pageSize = 50): Promise<GroupMemberListResponse> {
|
||||
const response = await api.get<GroupMemberListResponse>(
|
||||
`/groups/${encodeURIComponent(groupId)}/members`,
|
||||
{
|
||||
@@ -106,8 +116,6 @@ class GroupService {
|
||||
return normalizeMemberListResponse(response.data);
|
||||
}
|
||||
|
||||
// ==================== 群组管理 ====================
|
||||
|
||||
/**
|
||||
* 创建群组
|
||||
* POST /api/v1/groups
|
||||
@@ -117,22 +125,6 @@ class GroupService {
|
||||
return normalizeGroup(response.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取群组列表
|
||||
* GET /api/v1/groups
|
||||
*/
|
||||
async getGroups(page = 1, pageSize = 20): Promise<GroupListResponse> {
|
||||
return this.fetchGroupsFromApi(page, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取群组详情
|
||||
* GET /api/v1/groups/:id
|
||||
*/
|
||||
async getGroup(id: string): Promise<GroupResponse> {
|
||||
return this.fetchGroupFromApi(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户在群组中的成员信息
|
||||
* GET /api/v1/groups/:id/me
|
||||
@@ -211,14 +203,6 @@ class GroupService {
|
||||
await api.post(`/groups/${encodeURIComponent(groupId)}/leave`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取群组成员列表
|
||||
* GET /api/v1/groups/:id/members
|
||||
*/
|
||||
async getMembers(groupId: string, page = 1, pageSize = 50): Promise<GroupMemberListResponse> {
|
||||
return this.fetchMembersFromApi(groupId, page, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除群成员(踢人)
|
||||
* POST /api/v1/groups/:id/members/kick
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
saveConversationCache,
|
||||
saveConversationsWithRelatedCache,
|
||||
updateConversationCacheUnreadCount,
|
||||
saveUsersCache,
|
||||
} from './database';
|
||||
|
||||
/** 远端会话列表分页(offset / cursor)统一结果:拉取成功后均已执行本地缓存同步 */
|
||||
|
||||
Reference in New Issue
Block a user