refactor(database): migrate to new modular database layer and unify data access
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 2m44s
Frontend CI / ota-android (push) Successful in 12m51s
Frontend CI / build-android-apk (push) Successful in 1h1m26s

- Remove legacy database.ts, LocalDataSource.ts, and MessageRepository.ts
- Create new src/database/ module with messageRepository, userCacheRepository, conversationRepository, and groupCacheRepository
- Update all consumers to import from @/database instead of services/database
- Add web platform blur handling for modal components to fix focus issues
- Flatten SystemMessageItem and NotificationsScreen styles for consistent design
- Add draggable slider in ChatSettingsScreen and dynamic font size support
- Introduce 9 new chat color themes
- Add profile screens for about, terms, and privacy policy with navigation routes
- Add policy links to login and registration screens
- Fix post share URL format from /posts/ to /post/
This commit is contained in:
lafay
2026-04-04 08:01:45 +08:00
parent 189b977fac
commit 82c2970a85
76 changed files with 3382 additions and 2000 deletions

View File

@@ -22,14 +22,7 @@ import {
CursorPaginationRequest,
CursorPaginationResponse,
} from '../types/dto';
import {
getConversationCache,
getConversationListCache,
saveConversationCache,
saveConversationsWithRelatedCache,
updateConversationCacheUnreadCount,
saveUsersCache,
} from './database';
import { conversationRepository, userCacheRepository } from '@/database';
/** 远端会话列表分页offset / cursor统一结果拉取成功后均已执行本地缓存同步 */
export interface RemoteConversationListPageResult {
@@ -55,7 +48,7 @@ class MessageService {
const groups = list
.map(conv => conv.group)
.filter((group): group is NonNullable<typeof group> => Boolean(group));
await saveConversationsWithRelatedCache(list, users, groups);
await conversationRepository.saveWithRelated(list, users, groups);
}
/** offset 会话列表单页:请求 + 落库 */
@@ -152,12 +145,12 @@ class MessageService {
const response = await api.get<ConversationDetailResponse>(
`/conversations/${encodeURIComponent(id)}`
);
await saveConversationCache(response.data);
await conversationRepository.saveCache(response.data);
if (response.data.participants?.length) {
await saveUsersCache(response.data.participants);
await userCacheRepository.saveBatch(response.data.participants);
}
if (response.data.last_message?.sender) {
await saveUsersCache([response.data.last_message.sender]);
await userCacheRepository.save(response.data.last_message.sender);
}
return response.data;
}
@@ -195,7 +188,7 @@ class MessageService {
): Promise<ConversationListResponse> {
// 如果强制刷新,直接从服务器获取,不使用缓存
if (!forceRefresh) {
const cachedList = await getConversationListCache();
const cachedList = await conversationRepository.getListCache();
if (cachedList.length > 0) {
// 后台刷新数据,但不阻塞当前返回
this.refreshConversationsFromServer(page, pageSize).catch(error => {
@@ -235,9 +228,9 @@ class MessageService {
const response = await api.post<ConversationResponse>('/conversations', {
user_id: userId,
});
await saveConversationCache(response.data);
await conversationRepository.saveCache(response.data);
if (response.data.participants?.length) {
await saveUsersCache(response.data.participants);
await userCacheRepository.saveBatch(response.data.participants);
}
return response.data;
}
@@ -247,7 +240,7 @@ class MessageService {
* GET /api/v1/conversations/:id
*/
async getConversationById(id: string): Promise<ConversationDetailResponse> {
const cached = await getConversationCache(id);
const cached = await conversationRepository.getCache(id);
if (cached) {
this.refreshConversationDetailFromServer(id).catch(error => {
console.error('后台刷新会话详情失败:', error);
@@ -564,7 +557,7 @@ class MessageService {
last_read_seq: Number(seq),
});
// 立即清零本地缓存中的 unread_count并写入已读游标避免冷启动仍显示旧红点
updateConversationCacheUnreadCount(conversationId, 0, Number(seq)).catch(error => {
conversationRepository.updateCacheUnreadCount(conversationId, 0, Number(seq)).catch(error => {
console.error('更新本地会话未读数失败:', error);
});
}