Merge pull request 'websocket-self-flag: флаг присваивается по websocket, а не user_id' (#66) from websocket-self-flag into test

Reviewed-on: #66
Reviewed-by: Raykov-MS <RaykovMS@avt.rshb.ru>
This commit is contained in:
tsygankoviva 2026-06-23 11:16:44 +03:00
commit eaad37ded7

View File

@ -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,
)