mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix DMs
This commit is contained in:
@@ -304,7 +304,8 @@ class MessaggingSocketManager:
|
|||||||
db.add(env)
|
db.add(env)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(env)
|
db.refresh(env)
|
||||||
await self.send_to_user(env.recipient_id, {
|
|
||||||
|
payload = {
|
||||||
"type": "dmNew",
|
"type": "dmNew",
|
||||||
"data": {
|
"data": {
|
||||||
"id": env.id,
|
"id": env.id,
|
||||||
@@ -317,8 +318,11 @@ class MessaggingSocketManager:
|
|||||||
"wrappedMk": env.wrapped_mk_b64,
|
"wrappedMk": env.wrapped_mk_b64,
|
||||||
"timestamp": env.timestamp.isoformat(),
|
"timestamp": env.timestamp.isoformat(),
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
await websocket.send_json({"type": type, "data": {"status": "ok", "id": env.id}})
|
|
||||||
|
await self.send_to_user(env.recipient_id, payload);
|
||||||
|
await websocket.send_json({"type": type, "data": {"status": "ok", "id": env.id}});
|
||||||
|
await self.send_to_user(env.sender_id, payload);
|
||||||
except HTTPException as e:
|
except HTTPException as e:
|
||||||
await self.send_error(websocket, type, e)
|
await self.send_error(websocket, type, e)
|
||||||
elif type == "editMessage":
|
elif type == "editMessage":
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export class DMPanel extends MessagePanel {
|
|||||||
this.addMessage({
|
this.addMessage({
|
||||||
id: envelope.id,
|
id: envelope.id,
|
||||||
content: plaintext,
|
content: plaintext,
|
||||||
username: isAuthor ? "You" : this.dmData.username,
|
username: isAuthor ? this.currentUser.currentUser?.username ?? "You" : this.dmData.username,
|
||||||
timestamp: envelope.timestamp,
|
timestamp: envelope.timestamp,
|
||||||
is_read: false,
|
is_read: false,
|
||||||
is_edited: false
|
is_edited: false
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import type { Message, User, WebSocketMessage } from "../core/types";
|
import type { Message, User, WebSocketMessage } from "../core/types";
|
||||||
import { request, reconnectWebSocket } from "../websocket";
|
import { request } from "../websocket";
|
||||||
import { MessagePanel } from "./panels/MessagePanel";
|
import { MessagePanel } from "./panels/MessagePanel";
|
||||||
import { PublicChatPanel } from "./panels/PublicChatPanel";
|
import { PublicChatPanel } from "./panels/PublicChatPanel";
|
||||||
import { DMPanel, type DMPanelData } from "./panels/DMPanel";
|
import { DMPanel, type DMPanelData } from "./panels/DMPanel";
|
||||||
@@ -151,9 +151,6 @@ export const useAppState = create<AppState>((set, get) => ({
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Reconnect WebSocket with new auth token
|
|
||||||
reconnectWebSocket();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payload: WebSocketMessage = {
|
const payload: WebSocketMessage = {
|
||||||
type: "ping",
|
type: "ping",
|
||||||
|
|||||||
+18
-16
@@ -44,16 +44,26 @@ export function setGlobalMessageHandler(handler: ((response: WebSocketMessage) =
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function request(payload: WebSocketMessage): Promise<WebSocketMessage> {
|
export function request(payload: WebSocketMessage): Promise<WebSocketMessage> {
|
||||||
|
console.log("WebSocket request:", payload);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let listener: ((e: MessageEvent) => void) | null = null;
|
function requestInner() {
|
||||||
listener = (e) => {
|
let listener: ((e: MessageEvent) => void) | null = null;
|
||||||
resolve(JSON.parse(e.data));
|
listener = (e) => {
|
||||||
websocket.removeEventListener("message", listener!);
|
resolve(JSON.parse(e.data));
|
||||||
}
|
websocket.removeEventListener("message", listener!);
|
||||||
websocket.addEventListener("message", listener);
|
}
|
||||||
websocket.send(JSON.stringify(payload))
|
websocket.addEventListener("message", listener);
|
||||||
|
websocket.send(JSON.stringify(payload))
|
||||||
|
|
||||||
setTimeout(() => reject("Request timed out"), 10000);
|
setTimeout(() => reject("Request timed out"), 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (websocket.readyState == 0) {
|
||||||
|
websocket.addEventListener("open", requestInner);
|
||||||
|
setTimeout(() => reject("Request timed out"), 10000);
|
||||||
|
} else {
|
||||||
|
requestInner();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,14 +89,6 @@ async function onError() {
|
|||||||
websocket.addEventListener("error", onError);
|
websocket.addEventListener("error", onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Recreate WebSocket connection (useful when user logs in)
|
|
||||||
*/
|
|
||||||
export function reconnectWebSocket(): void {
|
|
||||||
websocket = create();
|
|
||||||
websocket.addEventListener("error", onError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------
|
// --------------
|
||||||
// Initialization
|
// Initialization
|
||||||
// --------------
|
// --------------
|
||||||
|
|||||||
Reference in New Issue
Block a user