From 72933993531aa69285b76a2bb63a0965deaa7e3f Mon Sep 17 00:00:00 2001 From: urec56 Date: Sat, 13 Jul 2024 15:03:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=20long=20polling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chat/websocket.py | 4 +-- app/tasks/email_templates.py | 70 ++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/app/chat/websocket.py b/app/chat/websocket.py index b3de545..52ac8a7 100644 --- a/app/chat/websocket.py +++ b/app/chat/websocket.py @@ -18,7 +18,7 @@ from app.users.schemas import SUser class ConnectionManager: def __init__(self): - self.active_connections: dict[int, list[WebSocket]] = {} + self.active_connections: dict[int, list[WebSocket]] = defaultdict(list) self.message_methods = { "send": self.send, "delete": self.delete, @@ -29,8 +29,6 @@ class ConnectionManager: async def connect(self, chat_id: int, websocket: WebSocket, subprotocol: str | None = None): await websocket.accept(subprotocol=subprotocol) - if chat_id not in self.active_connections: - self.active_connections[chat_id] = [] self.active_connections[chat_id].append(websocket) async def disconnect(self, chat_id: int, websocket: WebSocket, code_and_reason: tuple[int, str] | None = None): diff --git a/app/tasks/email_templates.py b/app/tasks/email_templates.py index d763e81..9ee2443 100644 --- a/app/tasks/email_templates.py +++ b/app/tasks/email_templates.py @@ -16,9 +16,73 @@ def create_registration_confirmation_template( email.set_content( f""" -

{username}, лови аптечку

- {confirmation_link} - {confirmation_code} + + + + + + + Pegr + + + + +
+ +

Код подтверждения для {username}

+
+ +

Код {confirmation_code}

+
+ +

или

+ + + +

перейдите по ссылке

+
+
+ + + """, subtype="html", )