# Path: django_private_chat/channels_uvloop.py
# def get_new_uvloop_queue():
# 
# Path: django_private_chat/handlers.py
# async def target_message(conn, payload):
# async def fanout_message(connections, payload):
# async def gone_online(stream):
# async def check_online(stream):
# async def gone_offline(stream):
# async def new_messages_handler(stream):
# async def users_changed_handler(stream):
# async def is_typing_handler(stream):
# async def read_message_handler(stream):
# async def main_handler(websocket, path):
# 
# Path: django_private_chat/utils.py
# async def get_user_from_session(session_key):
# def get_dialogs_with_user(user_1, user_2):


import asyncio
import ssl
import websockets
import uvloop
from django.conf import settings
from django.core.management.base import BaseCommand
from django_private_chat import channels_uvloop as channels
from django_private_chat import handlers
from django_private_chat.utils import logger

    def handle(self, *args, **options):
        if options['ssl_cert'] is not None:
            ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
            ssl_context.load_cert_chain(options['ssl_cert'])
        else:
            ssl_context = None
        

        if hasattr(asyncio, "ensure_future"):
            ensure_future = asyncio.ensure_future 
        else:
            ensure_future = getattr(asyncio, "async")

        ensure_future(
            websockets.serve(
                handlers.main_handler,
                settings.CHAT_WS_SERVER_HOST,
                settings.CHAT_WS_SERVER_PORT,
                ssl=ssl_context
            )
        )

        logger.info('Chat server started')

        ensure_future(handlers.new_messages_handler(channels.new_messages))
        ensure_future(handlers.users_changed_handler(channels.users_changed))
       ensure_future(handlers.gone_online(channels.online))
       ensure_future(handlers.check_online(channels.check_online))
       ensure_future(handlers.gone_offline(channels.offline))
       ensure_future(handlers.is_typing_handler(channels.is_typing))

# Path: django_private_chat/channels_uvloop.py
# def get_new_uvloop_queue():
# 
# Path: django_private_chat/handlers.py
# async def target_message(conn, payload):
# async def fanout_message(connections, payload):
# async def gone_online(stream):
# async def check_online(stream):
# async def gone_offline(stream):
# async def new_messages_handler(stream):
# async def users_changed_handler(stream):
# async def is_typing_handler(stream):
# async def read_message_handler(stream):
# async def main_handler(websocket, path):
# 
# Path: django_private_chat/utils.py
# async def get_user_from_session(session_key):
# def get_dialogs_with_user(user_1, user_2):


# Path: django_private_chat/management/commands/run_chat_server_uvloop.py
import asyncio
import ssl
import websockets
import uvloop
from django.conf import settings
from django.core.management.base import BaseCommand
from django_private_chat import channels_uvloop as channels
from django_private_chat import handlers
from django_private_chat.utils import logger

    def handle(self, *args, **options):
        if options['ssl_cert'] is not None:
            ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
            ssl_context.load_cert_chain(options['ssl_cert'])
        else:
            ssl_context = None
        

        if hasattr(asyncio, "ensure_future"):
            ensure_future = asyncio.ensure_future 
        else:
            ensure_future = getattr(asyncio, "async")

        ensure_future(
            websockets.serve(
                handlers.main_handler,
                settings.CHAT_WS_SERVER_HOST,
                settings.CHAT_WS_SERVER_PORT,
                ssl=ssl_context
            )
        )

        logger.info('Chat server started')

        ensure_future(handlers.new_messages_handler(channels.new_messages))
        ensure_future(handlers.users_changed_handler(channels.users_changed))
       ensure_future(handlers.gone_online(channels.online))
       ensure_future(handlers.check_online(channels.check_online))
       ensure_future(handlers.gone_offline(channels.offline))
       ensure_future(handlers.is_typing_handler(channels.is_typing))

       ensure_future(handlers.read_message_handler(channels.read_unread))
