feat(content): add rich content rendering with @mentions and vote segments
- Add PostContentRenderer component for rendering posts/comments with segments - Add PostMentionInput component for @mention support in post/comment creation - Add VoteSegmentData and vote segment type for unified post creation API - Update post and comment services to support segments in API requests - Fix auth service to clear tokens before login/register - Improve database initialization with proper close/retry logic - Add verification check before allowing post creation - Add metro web shims for react-native-webrtc full package and requireNativeComponent - Update build config with git hash based version numbers
This commit is contained in:
@@ -141,8 +141,21 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
|
||||
const userId = String(user.id);
|
||||
|
||||
// 2. 初始化用户专属数据库
|
||||
await switchDatabase(userId);
|
||||
// 2. 关闭旧数据库连接后再初始化用户专属数据库
|
||||
try {
|
||||
await closeDatabase();
|
||||
} catch {}
|
||||
try {
|
||||
await switchDatabase(userId);
|
||||
} catch (dbErr) {
|
||||
console.warn('[AuthStore] switchDatabase 失败,将重试:', dbErr);
|
||||
try {
|
||||
await closeDatabase();
|
||||
await switchDatabase(userId);
|
||||
} catch (retryErr) {
|
||||
console.error('[AuthStore] switchDatabase 重试仍失败:', retryErr);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 持久化 userId(供下次冷启动提前初始化 DB 用)
|
||||
await saveUserId(userId);
|
||||
@@ -160,8 +173,10 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
error: null,
|
||||
});
|
||||
|
||||
// 6. 启动 SSE
|
||||
await startRealtime();
|
||||
// 6. 启动 SSE(不阻塞登录结果)
|
||||
startRealtime().catch((err) => {
|
||||
console.warn('[AuthStore] 启动实时服务失败:', err);
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
@@ -187,7 +202,21 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
|
||||
const userId = String(user.id);
|
||||
|
||||
await switchDatabase(userId);
|
||||
try {
|
||||
await closeDatabase();
|
||||
} catch {}
|
||||
try {
|
||||
await switchDatabase(userId);
|
||||
} catch (dbErr) {
|
||||
console.warn('[AuthStore] register switchDatabase 失败,将重试:', dbErr);
|
||||
try {
|
||||
await closeDatabase();
|
||||
await switchDatabase(userId);
|
||||
} catch (retryErr) {
|
||||
console.error('[AuthStore] register switchDatabase 重试仍失败:', retryErr);
|
||||
}
|
||||
}
|
||||
|
||||
await saveUserId(userId);
|
||||
await cacheUser(user);
|
||||
|
||||
@@ -201,7 +230,10 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
error: null,
|
||||
});
|
||||
|
||||
await startRealtime();
|
||||
// 启动 SSE(不阻塞注册结果)
|
||||
startRealtime().catch((err) => {
|
||||
console.warn('[AuthStore] 启动实时服务失败:', err);
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
@@ -275,8 +307,14 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
// 4. 确保 DB 已初始化(如果预初始化失败,这里会重试)
|
||||
const dbReady = isDbInitialized() && getCurrentDbUserId() === userId;
|
||||
if (!dbReady) {
|
||||
await switchDatabase(userId);
|
||||
|
||||
try {
|
||||
await closeDatabase();
|
||||
} catch {}
|
||||
try {
|
||||
await switchDatabase(userId);
|
||||
} catch (dbErr) {
|
||||
console.warn('[AuthStore] fetchCurrentUser switchDatabase 失败:', dbErr);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 更新持久化的 userId
|
||||
@@ -296,8 +334,10 @@ await switchDatabase(userId);
|
||||
isLoading: false,
|
||||
});
|
||||
|
||||
// 8. 启动 SSE
|
||||
await startRealtime();
|
||||
// 8. 启动 SSE(不阻塞状态设置)
|
||||
startRealtime().catch((err) => {
|
||||
console.warn('[AuthStore] 冷启动实时服务失败:', err);
|
||||
});
|
||||
} else {
|
||||
// Token 已失效或不存在
|
||||
await clearUserId();
|
||||
|
||||
Reference in New Issue
Block a user