stash
This commit is contained in:
parent
06ebd4bd8f
commit
79fec60229
1 changed files with 10 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
from channels.layers import get_channel_layer
|
from channels.layers import get_channel_layer
|
||||||
|
from channels.db import database_sync_to_async
|
||||||
|
|
||||||
|
|
||||||
class NotificationDispatcher:
|
class NotificationDispatcher:
|
||||||
|
@ -10,6 +11,10 @@ class NotificationDispatcher:
|
||||||
if not self.channel_layer:
|
if not self.channel_layer:
|
||||||
raise Exception("Could not get channel layer")
|
raise Exception("Could not get channel layer")
|
||||||
|
|
||||||
|
@database_sync_to_async
|
||||||
|
def get_notification_targets(self):
|
||||||
|
return []
|
||||||
|
|
||||||
async def run_forever(self):
|
async def run_forever(self):
|
||||||
# Infinite loop to continuously listen for messages
|
# Infinite loop to continuously listen for messages
|
||||||
print("Listening 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
|
if (message and 'type' in message and message['type'] == 'generic.event' and 'name' in message and
|
||||||
message['name'] == 'user_notification'):
|
message['name'] == 'user_notification'):
|
||||||
if 'message' in message and 'event_id' in message:
|
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'])
|
await self.dispatch(message['message'], message['event_id'])
|
||||||
|
else:
|
||||||
|
print("Error: Invalid message format")
|
||||||
|
|
||||||
async def dispatch(self, message, event_id):
|
async def dispatch(self, message, event_id):
|
||||||
print("Dispatching message:", message, "with event_id:", 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)
|
||||||
|
|
Loading…
Reference in a new issue