Skip to content

Commit 5f35c5e

Browse files
authored
Merge pull request #217 from PROCOLLAB-github/dev
attempt to add set offline users event
2 parents 51eaa9d + ac113b5 commit 5f35c5e

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

chats/consumers/chat.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff 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"""

users/serializers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)