Skip to content

Commit 2624ae6

Browse files
authored
Merge pull request #222 from PROCOLLAB-github/dev
Dev
2 parents 74e3160 + 362fef3 commit 2624ae6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

chats/consumers/chat.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,21 @@ async def connect(self):
7070
# notify everyone that this user is online
7171
await self.channel_layer.group_send(
7272
EventGroupType.GENERAL_EVENTS,
73-
{"type": EventType.SET_OFFLINE, "user": {"id": self.user.id}},
73+
{"type": EventType.SET_ONLINE, "content": {"user_id": self.user.id}},
7474
)
7575

76+
# add to group to listen for general events, like online/offline
7677
await self.channel_layer.group_add(
7778
EventGroupType.GENERAL_EVENTS, self.channel_name
7879
)
7980
await self.accept()
8081

8182
async def disconnect(self, close_code):
8283
"""User disconnected from websocket"""
84+
if not self.user or self.user.is_anonymous:
85+
# don't need to proccess logic for disconnect
86+
# if we are not logged in!
87+
return
8388
online_users = cache.get(get_users_online_cache_key(), set())
8489
online_users.discard(self.user.id)
8590
cache.set(get_users_online_cache_key(), online_users)
@@ -88,7 +93,8 @@ async def disconnect(self, close_code):
8893

8994
# TODO: add a User extra-small serializer for this?
9095
await self.channel_layer.group_send(
91-
room_name, {"type": EventType.SET_OFFLINE, "user": {"id": self.user.id}}
96+
room_name,
97+
{"type": EventType.SET_OFFLINE, "content": {"user_id": self.user.id}},
9298
)
9399

94100
async def receive_json(self, content, **kwargs):

0 commit comments

Comments
 (0)