o
    ѷ6i                     @   sz   d dl Z d dlmZ d dlmZ d dlmZ ddlmZ ddlm	Z	 e 
eZdd	 Zed
d Zedd Zdd ZdS )    N)Group)channel_session_user)channel_session_user_from_http   )models)app_settingsc                 C   s&   | j jrtjjj| j dS tjj S )z@
    :return: Subscription query for a given message's user
    )settings__user)useris_authenticatedr   Subscriptionobjectsfilternonemessage r   Y/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/django_nyt/consumers.pyget_subscriptions   s   r   c                 C   sR   t d| j | jddi t| D ]}ttj	j|j
jd| j qdS )z(
    Connected to websocket.connect
    z!Adding new connection for user {}acceptTnotification_keyN)loggerdebugformatr	   reply_channelsendr   r   r   NOTIFICATION_CHANNELnotification_typekeyaddr   subscriptionr   r   r   
ws_connect   s   r"   c                 C   sB   t d| j t| D ]}ttjj|jj	d
| j qdS )z+
    Connected to websocket.disconnect
    z,Removing connection for user {} (disconnect)r   N)r   r   r   r	   r   r   r   r   r   r   discardr   r    r   r   r   ws_disconnect'   s   r$   c                 C   s   t d | jddi dS )z
    Receives messages, this is currently just for debugging purposes as there
    is no communication API for the websockets.
    z5Received a message, responding with a non-API messagetextOKN)r   r   r   r   r   r   r   r   
ws_receive5   s   
r'   )loggingchannelsr   channels.authr   r    r   confr   	getLogger__name__r   r   r"   r$   r'   r   r   r   r   <module>   s    



