mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix ping on credential restoration
This commit is contained in:
@@ -242,8 +242,28 @@ class MessaggingSocketManager:
|
|||||||
current_user = get_current_user_inner()
|
current_user = get_current_user_inner()
|
||||||
if current_user:
|
if current_user:
|
||||||
self.user_by_ws[websocket] = current_user.id
|
self.user_by_ws[websocket] = current_user.id
|
||||||
|
else:
|
||||||
|
await websocket.send_json({
|
||||||
|
"type": "ping",
|
||||||
|
"data": {
|
||||||
|
"status": "error",
|
||||||
|
"error": {
|
||||||
|
"detail": "Failed to authorize",
|
||||||
|
"code": 401
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
pass
|
await websocket.send_json({
|
||||||
|
"type": "ping",
|
||||||
|
"data": {
|
||||||
|
"status": "error",
|
||||||
|
"error": {
|
||||||
|
"detail": "Failed to authorize",
|
||||||
|
"code": 401
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
await websocket.send_json({"type": "ping", "data": {"status": "success"}})
|
await websocket.send_json({"type": "ping", "data": {"status": "success"}})
|
||||||
elif type == "getMessages":
|
elif type == "getMessages":
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import type { Message, User, WebSocketMessage } from "../core/types";
|
import type { Message, User } from "../core/types";
|
||||||
import { request } from "../core/websocket";
|
import { request } from "../core/websocket";
|
||||||
import { MessagePanel } from "./panels/MessagePanel";
|
import { MessagePanel } from "./panels/MessagePanel";
|
||||||
import { PublicChatPanel } from "./panels/PublicChatPanel";
|
import { PublicChatPanel } from "./panels/PublicChatPanel";
|
||||||
@@ -166,16 +166,14 @@ export const useAppState = create<AppState>((set, get) => ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payload: WebSocketMessage = {
|
request({
|
||||||
type: "ping",
|
type: "ping",
|
||||||
credentials: {
|
credentials: {
|
||||||
scheme: "Bearer",
|
scheme: "Bearer",
|
||||||
credentials: token
|
credentials: token
|
||||||
},
|
},
|
||||||
data: {}
|
data: {}
|
||||||
}
|
}).then(() => {
|
||||||
|
|
||||||
request(payload).then(() => {
|
|
||||||
console.log("Ping succeeded")
|
console.log("Ping succeeded")
|
||||||
})
|
})
|
||||||
} catch {}
|
} catch {}
|
||||||
@@ -218,6 +216,19 @@ export const useAppState = create<AppState>((set, get) => ({
|
|||||||
currentPage: "chat"
|
currentPage: "chat"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
request({
|
||||||
|
type: "ping",
|
||||||
|
credentials: {
|
||||||
|
scheme: "Bearer",
|
||||||
|
credentials: token
|
||||||
|
},
|
||||||
|
data: {}
|
||||||
|
}).then(() => {
|
||||||
|
console.log("Ping succeeded")
|
||||||
|
})
|
||||||
|
} catch {}
|
||||||
|
|
||||||
// Initialize notifications after successful credential restoration
|
// Initialize notifications after successful credential restoration
|
||||||
try {
|
try {
|
||||||
if (isSupported()) {
|
if (isSupported()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user