This commit is contained in:
2025-10-19 20:31:29 +03:00
Unverified
parent 66f0b756a0
commit f5527ca14e
67 changed files with 891 additions and 902 deletions
+42 -42
View File
@@ -27,7 +27,7 @@ export interface ProfileDialogData {
}
interface ActiveDM {
userId: number;
userId: number;
username: string;
publicKey: string | null
}
@@ -89,7 +89,7 @@ interface AppState {
applyPendingPanel: () => void;
switchToPublicChat: (chatName: string) => Promise<void>;
switchToDM: (dmData: DMPanelData) => Promise<void>;
// Call state
startCall: (userId: number, username: string) => void;
endCall: () => void;
@@ -104,17 +104,17 @@ interface AppState {
setRemoteVideoEnabled: (enabled: boolean) => void;
setRemoteScreenSharing: (enabled: boolean) => void;
toggleCallMinimized: () => void;
// User state
user: UserState;
setUser: (token: string, user: User) => void;
logout: () => void;
restoreUserFromStorage: () => Promise<void>;
// Profile dialog state
setProfileDialog: (data: ProfileDialogData | null) => void;
closeProfileDialog: () => void;
// Online status and typing state
updateOnlineStatus: (userId: number, online: boolean, lastSeen: string) => void;
addTypingUser: (userId: number, username: string) => void;
@@ -168,7 +168,7 @@ export const useAppState = create<AppState>((set, get) => ({
if (messageExists) {
return state; // Return unchanged state if message already exists
}
return {
chat: {
...state.chat,
@@ -179,7 +179,7 @@ export const useAppState = create<AppState>((set, get) => ({
updateMessage: (messageId: number, updatedMessage: Partial<Message>) => set((state) => ({
chat: {
...state.chat,
messages: state.chat.messages.map(msg =>
messages: state.chat.messages.map(msg =>
msg.id === messageId ? { ...msg, ...updatedMessage } : msg
)
}
@@ -220,7 +220,7 @@ export const useAppState = create<AppState>((set, get) => ({
activeDm: dm
}
})),
// User state
user: {
currentUser: null,
@@ -284,7 +284,7 @@ export const useAppState = create<AppState>((set, get) => ({
restoreUserFromStorage: async () => {
try {
const token = localStorage.getItem('authToken');
if (token) {
const response = await fetch(`${API_BASE_URL}/user/profile`, {
headers: getAuthHeaders(token)
@@ -324,7 +324,7 @@ export const useAppState = create<AppState>((set, get) => ({
const initialized = await initialize();
if (initialized) {
await subscribe(token);
// For Electron, start the notification receiver
if (isElectron) {
await startElectronReceiver();
@@ -345,7 +345,7 @@ export const useAppState = create<AppState>((set, get) => ({
localStorage.removeItem('currentUser');
}
},
// Panel management
setActivePanel: (panel: MessagePanel | null) => set((state) => ({
chat: {
@@ -377,15 +377,15 @@ export const useAppState = create<AppState>((set, get) => ({
pendingPanel: null
}
})),
switchToPublicChat: async (chatName: string) => {
const { user, chat } = get();
if (!user.authToken) return;
// Start chat switching animation
chat.setIsSwitching(true);
// Create or get public chat panel
let publicChatPanel = chat.publicChatPanel;
if (!publicChatPanel) {
@@ -396,10 +396,10 @@ export const useAppState = create<AppState>((set, get) => ({
// Reset messages for the new chat
publicChatPanel.clearMessages();
}
// Activate panel
await publicChatPanel.activate();
// Defer panel swap until animation switch-out completes
set((state) => ({
chat: {
@@ -408,19 +408,19 @@ export const useAppState = create<AppState>((set, get) => ({
activeTab: "chats"
}
}));
// Let MessagePanelRenderer handle the animation timing completely
// It will set isChatSwitching to false when the fadeInDown animation completes
},
switchToDM: async (dmData: DMPanelData) => {
const { user, chat } = get();
if (!user.authToken) return;
// Start chat switching animation
chat.setIsSwitching(true);
// Create or get DM panel
let dmPanel = chat.dmPanel;
if (!dmPanel) {
@@ -430,13 +430,13 @@ export const useAppState = create<AppState>((set, get) => ({
// Reset messages for the new DM
dmPanel.clearMessages();
}
// Set DM data
dmPanel.setDMData(dmData);
// Activate panel
await dmPanel.activate();
// Defer panel swap until animation switch-out completes
set((state) => ({
chat: {
@@ -450,7 +450,7 @@ export const useAppState = create<AppState>((set, get) => ({
activeTab: "chats"
}
}));
// Let MessagePanelRenderer handle the animation timing completely
// It will set isChatSwitching to false when the fadeInDown animation completes
},
@@ -477,7 +477,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
endCall: () => set((state) => ({
chat: {
...state.chat,
@@ -499,7 +499,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
setCallStatus: (status: CallStatus) => set((state) => ({
chat: {
...state.chat,
@@ -510,7 +510,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
toggleMute: () => set((state) => ({
chat: {
...state.chat,
@@ -520,7 +520,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
toggleCallMinimize: () => set((state) => ({
chat: {
...state.chat,
@@ -552,7 +552,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
setCallEncryption: (sessionKeyHash: string, encryptionEmojis: string[]) => set((state) => ({
chat: {
...state.chat,
@@ -563,7 +563,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
setCallSessionKeyHash: (sessionKeyHash: string) => set((state) => ({
chat: {
...state.chat,
@@ -573,7 +573,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
toggleVideo: () => set((state) => ({
chat: {
...state.chat,
@@ -583,7 +583,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
toggleScreenShare: () => set((state) => ({
chat: {
...state.chat,
@@ -593,7 +593,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
setRemoteVideoEnabled: (enabled: boolean) => set((state) => ({
chat: {
...state.chat,
@@ -603,7 +603,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
setRemoteScreenSharing: (enabled: boolean) => set((state) => ({
chat: {
...state.chat,
@@ -622,7 +622,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
}
})),
// Profile dialog state management
setProfileDialog: (data: ProfileDialogData | null) => set((state) => ({
chat: {
@@ -630,14 +630,14 @@ export const useAppState = create<AppState>((set, get) => ({
profileDialog: data
}
})),
closeProfileDialog: () => set((state) => ({
chat: {
...state.chat,
profileDialog: null
}
})),
// Online status and typing state management
updateOnlineStatus: (userId: number, online: boolean, lastSeen: string) => set((state) => ({
chat: {
@@ -645,14 +645,14 @@ export const useAppState = create<AppState>((set, get) => ({
onlineStatuses: new Map(state.chat.onlineStatuses).set(userId, { online, lastSeen })
}
})),
addTypingUser: (userId: number, username: string) => set((state) => ({
chat: {
...state.chat,
typingUsers: new Map(state.chat.typingUsers).set(userId, username)
}
})),
removeTypingUser: (userId: number) => set((state) => {
const newTypingUsers = new Map(state.chat.typingUsers);
newTypingUsers.delete(userId);
@@ -663,7 +663,7 @@ export const useAppState = create<AppState>((set, get) => ({
}
};
}),
setDmTypingUser: (userId: number, isTyping: boolean) => set((state) => {
const newDmTypingUsers = new Map(state.chat.dmTypingUsers);
if (isTyping) {