26 lines
690 B
Python
26 lines
690 B
Python
|
|
|
||
|
|
from asgiref.sync import async_to_sync
|
||
|
|
from channels.layers import get_channel_layer
|
||
|
|
|
||
|
|
|
||
|
|
@classmethod
|
||
|
|
def notify_ws_clients(self, message):
|
||
|
|
"""
|
||
|
|
Inform client there is a new message.
|
||
|
|
"""
|
||
|
|
|
||
|
|
notification = {
|
||
|
|
"type": "recieve_group_message",
|
||
|
|
"message": "{}".format(message),
|
||
|
|
}
|
||
|
|
|
||
|
|
channel_layer = get_channel_layer()
|
||
|
|
print("user.id {}".format(self.user.id))
|
||
|
|
print("user.id {}".format(self.recipient.id))
|
||
|
|
|
||
|
|
async_to_sync(channel_layer.group_send)("{}".format(self.user.id), notification)
|
||
|
|
async_to_sync(channel_layer.group_send)(
|
||
|
|
"{}".format(self.recipient.id), notification
|
||
|
|
)
|
||
|
|
|