File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,13 +75,15 @@ async def connect(self):
7575
7676 async def disconnect (self , close_code ):
7777 """User disconnected from websocket"""
78- cache .delete (get_user_online_cache_key (self .user ))
7978 online_users = cache .get (get_users_online_cache_key (), set ())
8079 online_users .discard (self .user .id )
8180 cache .set (get_users_online_cache_key (), online_users )
81+ cache .delete (get_user_online_cache_key (self .user ))
82+ room_name = EventGroupType .GENERAL_EVENTS
8283
83- user_cache_key = get_user_online_cache_key (self .user )
84- cache .set (user_cache_key , False , ONE_DAY_IN_SECONDS )
84+ await self .channel_layer .group_send (
85+ room_name , {"type" : EventType .SET_OFFLINE , "user_id" : self .user .pk }
86+ )
8587
8688 async def receive_json (self , content , ** kwargs ):
8789 """Receive message from WebSocket in JSON format"""
Original file line number Diff line number Diff line change @@ -107,8 +107,7 @@ def get_links(cls, user: CustomUser):
107107 @classmethod
108108 def get_is_online (cls , user : CustomUser ):
109109 cache_key = get_user_online_cache_key (user )
110- is_online = cache .get (cache_key , False )
111- return is_online
110+ return cache .get (cache_key , False )
112111
113112 class Meta :
114113 model = CustomUser
You can’t perform that action at this time.
0 commit comments