Skip to content

Commit

Permalink
add a callback to message sending
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Nov 28, 2024
1 parent 4d07c6b commit f35d781
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nightwatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.11.1"
__version__ = "0.11.2"

import re
HEX_COLOR_REGEX = re.compile(r"^[A-Fa-f0-9]{6}$")
9 changes: 8 additions & 1 deletion nightwatch/rics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from fastapi.responses import JSONResponse
from starlette.websockets import WebSocketDisconnect, WebSocketState

from nightwatch import __version__
from nightwatch.config import fetch_config

# Load config data
Expand Down Expand Up @@ -65,7 +66,7 @@ async def send(self, payload: dict) -> None:
return

try:
if self._callback is not None:
if self._callback is not None and payload["type"] != "message":
payload["data"] = payload.get("data", {}) | {"callback": self._callback}
self._callback = None

Expand Down Expand Up @@ -164,6 +165,8 @@ async def connect_endpoint(
continue

await app.state.broadcast({"type": "message", "data": {"user": client.serialize(), "message": message}})
if client._callback is not None:
await client.send({"type": "response"})

case {"type": "user-list", "data": _}:
await client.send({"type": "response", "data": {
Expand All @@ -180,6 +183,10 @@ async def connect_endpoint(
await app.state.broadcast({"type": "leave", "data": {"user": client.serialize()}})
await app.state.broadcast({"type": "message", "data": {"message": f"{client.username} has left the server."}})

@app.get("/api/version")
async def route_version() -> JSONResponse:
return JSONResponse({"code": 200, "data": {"version": __version__}})

# Load additional routes
from nightwatch.rics.routing import ( # noqa: E402
files, # noqa: F401
Expand Down

0 comments on commit f35d781

Please sign in to comment.