From aceb1d38c164058dae793feb7c7f2e39a3d8dd96 Mon Sep 17 00:00:00 2001 From: tsygankoviva Date: Tue, 23 Jun 2026 09:29:33 +0300 Subject: [PATCH] =?UTF-8?q?websocket-self-flag:=20=D1=84=D0=BB=D0=B0=D0=B3?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D1=81=D0=B2=D0=B0=D0=B8=D0=B2=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=BF=D0=BE=20websocket,=20=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B5=20user=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/src/api/v1/websocket.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/api/src/api/v1/websocket.py b/api/src/api/v1/websocket.py index ffcb9a1..a9609be 100644 --- a/api/src/api/v1/websocket.py +++ b/api/src/api/v1/websocket.py @@ -154,7 +154,7 @@ class ConnectionManager: async def broadcast_to_other( self, data: dict, - user_id: int, + websocket: WebSocket, con_key: ConnectionKeyEnum, **kwargs, ): @@ -168,7 +168,7 @@ class ConnectionManager: message = dumps(data, default=_convert_error, ensure_ascii=False) for con_info in self.connections[con_key][key]: - if con_info.user_id != user_id: + if con_info.ws != websocket: try: await con_info.ws.send_text(message) except: @@ -178,7 +178,7 @@ class ConnectionManager: self, data: dict, con_key: ConnectionKeyEnum, - user_id: int | None = None, + websocket: WebSocket | None = None, **kwargs, ): key = frozenset(kwargs.items()) @@ -186,7 +186,7 @@ class ConnectionManager: return data = data.copy() - if user_id is None: + if websocket is None: data["is_self"] = None default_message = dumps(data, default=_convert_error, ensure_ascii=False) self_message = None @@ -198,7 +198,7 @@ class ConnectionManager: for con_info in self.connections[con_key][key]: try: - if user_id is not None and con_info.user_id == user_id: + if websocket is not None and con_info.ws == websocket: await con_info.ws.send_text(self_message) else: await con_info.ws.send_text(default_message) @@ -701,7 +701,8 @@ async def process_websocket( ) await manager.broadcast_to_other( data=data, - user_id=user_id, + # user_id=user_id, + websocket=websocket, con_key=con_key, **kwargs_process, ) @@ -719,7 +720,8 @@ async def process_websocket( ) await manager.broadcast_to_other( data=data, - user_id=user_id, + # user_id=user_id, + websocket=websocket, con_key=con_key, **kwargs_process, ) @@ -789,13 +791,15 @@ async def process_websocket( ]: await manager.broadcast_to_all( data=data, - user_id=user_id, + websocket=websocket, + # user_id=user_id, **kwargs ) else: await manager.broadcast_to_other( data=data, - user_id=user_id, + # user_id=user_id, + websocket=websocket, **kwargs, )