websocket-self-flag: флаг присваивается по websocket, а не user_id
This commit is contained in:
parent
a2841d8c83
commit
aceb1d38c1
@ -154,7 +154,7 @@ class ConnectionManager:
|
|||||||
async def broadcast_to_other(
|
async def broadcast_to_other(
|
||||||
self,
|
self,
|
||||||
data: dict,
|
data: dict,
|
||||||
user_id: int,
|
websocket: WebSocket,
|
||||||
con_key: ConnectionKeyEnum,
|
con_key: ConnectionKeyEnum,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
@ -168,7 +168,7 @@ class ConnectionManager:
|
|||||||
message = dumps(data, default=_convert_error, ensure_ascii=False)
|
message = dumps(data, default=_convert_error, ensure_ascii=False)
|
||||||
|
|
||||||
for con_info in self.connections[con_key][key]:
|
for con_info in self.connections[con_key][key]:
|
||||||
if con_info.user_id != user_id:
|
if con_info.ws != websocket:
|
||||||
try:
|
try:
|
||||||
await con_info.ws.send_text(message)
|
await con_info.ws.send_text(message)
|
||||||
except:
|
except:
|
||||||
@ -178,7 +178,7 @@ class ConnectionManager:
|
|||||||
self,
|
self,
|
||||||
data: dict,
|
data: dict,
|
||||||
con_key: ConnectionKeyEnum,
|
con_key: ConnectionKeyEnum,
|
||||||
user_id: int | None = None,
|
websocket: WebSocket | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
key = frozenset(kwargs.items())
|
key = frozenset(kwargs.items())
|
||||||
@ -186,7 +186,7 @@ class ConnectionManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
data = data.copy()
|
data = data.copy()
|
||||||
if user_id is None:
|
if websocket is None:
|
||||||
data["is_self"] = None
|
data["is_self"] = None
|
||||||
default_message = dumps(data, default=_convert_error, ensure_ascii=False)
|
default_message = dumps(data, default=_convert_error, ensure_ascii=False)
|
||||||
self_message = None
|
self_message = None
|
||||||
@ -198,7 +198,7 @@ class ConnectionManager:
|
|||||||
|
|
||||||
for con_info in self.connections[con_key][key]:
|
for con_info in self.connections[con_key][key]:
|
||||||
try:
|
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)
|
await con_info.ws.send_text(self_message)
|
||||||
else:
|
else:
|
||||||
await con_info.ws.send_text(default_message)
|
await con_info.ws.send_text(default_message)
|
||||||
@ -701,7 +701,8 @@ async def process_websocket(
|
|||||||
)
|
)
|
||||||
await manager.broadcast_to_other(
|
await manager.broadcast_to_other(
|
||||||
data=data,
|
data=data,
|
||||||
user_id=user_id,
|
# user_id=user_id,
|
||||||
|
websocket=websocket,
|
||||||
con_key=con_key,
|
con_key=con_key,
|
||||||
**kwargs_process,
|
**kwargs_process,
|
||||||
)
|
)
|
||||||
@ -719,7 +720,8 @@ async def process_websocket(
|
|||||||
)
|
)
|
||||||
await manager.broadcast_to_other(
|
await manager.broadcast_to_other(
|
||||||
data=data,
|
data=data,
|
||||||
user_id=user_id,
|
# user_id=user_id,
|
||||||
|
websocket=websocket,
|
||||||
con_key=con_key,
|
con_key=con_key,
|
||||||
**kwargs_process,
|
**kwargs_process,
|
||||||
)
|
)
|
||||||
@ -789,13 +791,15 @@ async def process_websocket(
|
|||||||
]:
|
]:
|
||||||
await manager.broadcast_to_all(
|
await manager.broadcast_to_all(
|
||||||
data=data,
|
data=data,
|
||||||
user_id=user_id,
|
websocket=websocket,
|
||||||
|
# user_id=user_id,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await manager.broadcast_to_other(
|
await manager.broadcast_to_other(
|
||||||
data=data,
|
data=data,
|
||||||
user_id=user_id,
|
# user_id=user_id,
|
||||||
|
websocket=websocket,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user