Implement live last message update

This commit is contained in:
2025-10-17 15:52:12 +03:00
Unverified
parent dd946e7466
commit a92f91d791
14 changed files with 518 additions and 258 deletions
@@ -9,6 +9,7 @@ import {
} from "@/core/api/dmApi";
import type { DmEncryptedJSON, DmEnvelope, DMWebSocketMessage, EncryptedMessageJson, Message } from "@/core/types";
import type { UserState } from "@/pages/chat/state";
import { formatDMUsername } from "@/pages/chat/hooks/useDM";
export interface DMPanelData {
userId: number;
@@ -48,8 +49,12 @@ export class DMPanel extends MessagePanel {
private async parseTextPayload(env: DmEnvelope, decryptedMessages: Message[]) {
const plaintext = await decryptDm(env, this.dmData!.publicKey);
const isAuthor = env.senderId !== this.dmData!.userId;
const username = isAuthor ? this.currentUser.currentUser?.username ?? "You" : this.dmData!.username;
const username = formatDMUsername(
env.senderId,
env.recipientId,
this.currentUser.currentUser?.id!,
this.dmData!.username
);
// Try parse JSON payload { type: "text", data: { content, files?, reply_to_id? } }
let content = plaintext;
@@ -168,6 +173,7 @@ export class DMPanel extends MessagePanel {
});
}
// Handle incoming WebSocket DM messages
async handleWebSocketMessage(response: DMWebSocketMessage): Promise<void> {
if (response.type === "dmNew" && this.dmData) {