Skip to content

Commit

Permalink
Merge pull request #217 from PROCOLLAB-github/dev
Browse files Browse the repository at this point in the history
attempt to add set offline users event
  • Loading branch information
VeryBigSad authored Oct 20, 2023
2 parents 51eaa9d + ac113b5 commit 5f35c5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 5 additions & 3 deletions chats/consumers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ async def connect(self):

async def disconnect(self, close_code):
"""User disconnected from websocket"""
cache.delete(get_user_online_cache_key(self.user))
online_users = cache.get(get_users_online_cache_key(), set())
online_users.discard(self.user.id)
cache.set(get_users_online_cache_key(), online_users)
cache.delete(get_user_online_cache_key(self.user))
room_name = EventGroupType.GENERAL_EVENTS

user_cache_key = get_user_online_cache_key(self.user)
cache.set(user_cache_key, False, ONE_DAY_IN_SECONDS)
await self.channel_layer.group_send(
room_name, {"type": EventType.SET_OFFLINE, "user_id": self.user.pk}
)

async def receive_json(self, content, **kwargs):
"""Receive message from WebSocket in JSON format"""
Expand Down
3 changes: 1 addition & 2 deletions users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def get_links(cls, user: CustomUser):
@classmethod
def get_is_online(cls, user: CustomUser):
cache_key = get_user_online_cache_key(user)
is_online = cache.get(cache_key, False)
return is_online
return cache.get(cache_key, False)

class Meta:
model = CustomUser
Expand Down

0 comments on commit 5f35c5e

Please sign in to comment.