diff --git a/core/mail/notifications.py b/core/mail/notifications.py index 02c46d1..cb7eeb9 100644 --- a/core/mail/notifications.py +++ b/core/mail/notifications.py @@ -1,4 +1,5 @@ from channels.layers import get_channel_layer +from channels.db import database_sync_to_async class NotificationDispatcher: @@ -10,6 +11,10 @@ class NotificationDispatcher: if not self.channel_layer: raise Exception("Could not get channel layer") + @database_sync_to_async + def get_notification_targets(self): + return [] + async def run_forever(self): # Infinite loop to continuously listen for messages print("Listening for messages...") @@ -23,8 +28,12 @@ class NotificationDispatcher: if (message and 'type' in message and message['type'] == 'generic.event' and 'name' in message and message['name'] == 'user_notification'): if 'message' in message and 'event_id' in message: - print("Received message:", message['message'], "with event_id:", message['event_id']) await self.dispatch(message['message'], message['event_id']) + else: + print("Error: Invalid message format") async def dispatch(self, message, event_id): print("Dispatching message:", message, "with event_id:", event_id) + targets = await self.get_notification_targets() + for target in targets: + print("Sending message to target:", target)