Implement profile dialog

This commit is contained in:
2025-10-18 13:32:04 +03:00
Unverified
parent a92f91d791
commit b5b5547927
18 changed files with 735 additions and 590 deletions
@@ -7,8 +7,9 @@ import {
editDmEnvelope,
deleteDmEnvelope
} from "@/core/api/dmApi";
import { fetchUserProfile } from "@/core/api/profileApi";
import type { DmEncryptedJSON, DmEnvelope, DMWebSocketMessage, EncryptedMessageJson, Message } from "@/core/types";
import type { UserState } from "@/pages/chat/state";
import type { UserState, ProfileDialogData } from "@/pages/chat/state";
import { formatDMUsername } from "@/pages/chat/hooks/useDM";
export interface DMPanelData {
@@ -322,7 +323,27 @@ export class DMPanel extends MessagePanel {
});
}
handleProfileClick(): void {}
async getProfile(): Promise<ProfileDialogData | null> {
if (!this.dmData || !this.currentUser.authToken) return null;
try {
const userProfile = await fetchUserProfile(this.currentUser.authToken, this.dmData.username);
if (!userProfile) return null;
return {
userId: userProfile.id,
username: userProfile.username,
profilePicture: userProfile.profile_picture,
bio: userProfile.bio,
memberSince: userProfile.created_at,
online: userProfile.online,
isOwnProfile: false
};
} catch (error) {
console.error("Failed to fetch user profile:", error);
return null;
}
}
updateMessageReactions(dmEnvelopeId: number, reactions: any[]): void {
const messages = this.getMessages();
@@ -1,5 +1,5 @@
import type { Message, WebSocketMessage } from "@/core/types";
import type { UserState } from "@/pages/chat/state";
import type { UserState, ProfileDialogData } from "@/pages/chat/state";
export interface MessagePanelState {
id: string;
@@ -47,6 +47,7 @@ export abstract class MessagePanel {
protected abstract sendMessage(content: string, replyToId?: number, files?: File[]): Promise<void>;
abstract isDm(): boolean;
abstract handleWebSocketMessage(response: WebSocketMessage<any>): Promise<void>;
abstract getProfile(): Promise<ProfileDialogData | null>;
// Common methods
protected updateState(updates: Partial<MessagePanelState>): void {
@@ -349,5 +350,4 @@ export abstract class MessagePanel {
abstract handleEditMessage(messageId: number, content: string): Promise<void>;
abstract handleDeleteMessage(messageId: number): Promise<void>;
abstract handleProfileClick(): void;
}
@@ -3,7 +3,7 @@ import { API_BASE_URL } from "@/core/config";
import { getAuthHeaders } from "@/core/api/authApi";
import { request } from "@/core/websocket";
import type { ChatWebSocketMessage, Message, SendMessageRequest, ReactionUpdateWebSocketMessage } from "@/core/types";
import type { UserState } from "@/pages/chat/state";
import type { UserState, ProfileDialogData } from "@/pages/chat/state";
export class PublicChatPanel extends MessagePanel {
private messagesLoaded: boolean = false;
@@ -197,5 +197,11 @@ export class PublicChatPanel extends MessagePanel {
});
}
handleProfileClick(): void {}
async getProfile(): Promise<ProfileDialogData | null> {
return {
username: "Общий чат",
bio: "Общаемся со всеми пользователями FromChat!",
isOwnProfile: false
};
}
}