mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix null issues
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
import { MessagePanel, type MessagePanelCallbacks } from "./MessagePanel";
|
import { MessagePanel, type MessagePanelCallbacks, type MessagePanelState } from "./MessagePanel";
|
||||||
import {
|
import {
|
||||||
fetchDMHistory,
|
fetchDMHistory,
|
||||||
decryptDm,
|
decryptDm,
|
||||||
sendDMViaWebSocket
|
sendDMViaWebSocket
|
||||||
} from "../../api/dmApi";
|
} from "../../api/dmApi";
|
||||||
import type { Message } from "../../core/types";
|
import type { Message, WebSocketMessage } from "../../core/types";
|
||||||
import type { UserState } from "../state";
|
import type { UserState } from "../state";
|
||||||
|
|
||||||
export interface DMPanelData {
|
export interface DMPanelData {
|
||||||
@@ -22,7 +22,7 @@ export class DMPanel extends MessagePanel {
|
|||||||
constructor(
|
constructor(
|
||||||
user: UserState,
|
user: UserState,
|
||||||
callbacks: MessagePanelCallbacks,
|
callbacks: MessagePanelCallbacks,
|
||||||
onStateChange: (state: any) => void
|
onStateChange: (state: MessagePanelState) => void
|
||||||
) {
|
) {
|
||||||
super("dm", user, callbacks, onStateChange);
|
super("dm", user, callbacks, onStateChange);
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ export class DMPanel extends MessagePanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle incoming WebSocket DM messages
|
// Handle incoming WebSocket DM messages
|
||||||
handleWebSocketMessage = async (response: any): Promise<void> => {
|
handleWebSocketMessage = async (response: WebSocketMessage): Promise<void> => {
|
||||||
if (response.type === "dmNew" && this.dmData) {
|
if (response.type === "dmNew" && this.dmData) {
|
||||||
const { senderId, recipientId, ...envelope } = response.data;
|
const { senderId, recipientId, ...envelope } = response.data;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export interface MessagePanelCallbacks {
|
|||||||
export abstract class MessagePanel {
|
export abstract class MessagePanel {
|
||||||
protected state: MessagePanelState;
|
protected state: MessagePanelState;
|
||||||
protected callbacks: MessagePanelCallbacks;
|
protected callbacks: MessagePanelCallbacks;
|
||||||
public onStateChange: (state: MessagePanelState) => void;
|
public onStateChange: ((state: MessagePanelState) => void) | null;
|
||||||
protected currentUser: UserState;
|
protected currentUser: UserState;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -57,8 +57,10 @@ export abstract class MessagePanel {
|
|||||||
// Common methods
|
// Common methods
|
||||||
protected updateState(updates: Partial<MessagePanelState>): void {
|
protected updateState(updates: Partial<MessagePanelState>): void {
|
||||||
this.state = { ...this.state, ...updates };
|
this.state = { ...this.state, ...updates };
|
||||||
|
if (this.onStateChange) {
|
||||||
this.onStateChange(this.state);
|
this.onStateChange(this.state);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected addMessage(message: Message): void {
|
protected addMessage(message: Message): void {
|
||||||
const messageExists = this.state.messages.some(msg => msg.id === message.id);
|
const messageExists = this.state.messages.some(msg => msg.id === message.id);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MessagePanel, type MessagePanelCallbacks } from "./MessagePanel";
|
import { MessagePanel, type MessagePanelCallbacks, type MessagePanelState } from "./MessagePanel";
|
||||||
import { API_BASE_URL } from "../../core/config";
|
import { API_BASE_URL } from "../../core/config";
|
||||||
import { getAuthHeaders } from "../../auth/api";
|
import { getAuthHeaders } from "../../auth/api";
|
||||||
import { request } from "../../core/websocket";
|
import { request } from "../../core/websocket";
|
||||||
@@ -12,7 +12,7 @@ export class PublicChatPanel extends MessagePanel {
|
|||||||
chatName: string,
|
chatName: string,
|
||||||
currentUser: UserState,
|
currentUser: UserState,
|
||||||
callbacks: MessagePanelCallbacks,
|
callbacks: MessagePanelCallbacks,
|
||||||
onStateChange: (state: any) => void
|
onStateChange: (state: MessagePanelState) => void
|
||||||
) {
|
) {
|
||||||
super(`public-${chatName}`, currentUser, callbacks, onStateChange);
|
super(`public-${chatName}`, currentUser, callbacks, onStateChange);
|
||||||
this.updateState({
|
this.updateState({
|
||||||
|
|||||||
Reference in New Issue
Block a user