Skip to content

Commit

Permalink
Bugfixes:
Browse files Browse the repository at this point in the history
1. UI improvement: the Opponent username bubble has alignment flex-end to ensure it's in the bottom
2. Cache usernames of all users present in a room to save database queries
  • Loading branch information
ishtiaque06 committed May 29, 2019
1 parent 67b967e commit 05553cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions django_chatter/consumers.py
Expand Up @@ -92,6 +92,8 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
async def connect(self):
self.user = self.scope['user']

self.room_username_list = [] # Cache room usernames to send alerts

self.schema_name = self.scope.get('schema_name', None)
self.multitenant = self.scope.get('multitenant', False)
for param in self.scope['path'].split('/'):
Expand All @@ -114,6 +116,9 @@ async def connect(self):
self.channel_name
)
await self.accept()

for user in self.room.members.all():
self.room_username_list.append(user.username)
else:
await self.disconnect(403)
else:
Expand All @@ -124,6 +129,9 @@ async def connect(self):
self.channel_name
)
await self.accept()

for user in self.room.members.all():
self.room_username_list.append(user.username)
else:
await self.disconnect(403)
except Exception as ex:
Expand Down Expand Up @@ -175,10 +183,10 @@ async def receive_json(self, data):
}
)

for user in self.room.members.all():
if user != self.user:
for username in self.room_username_list:
if username != self.user.username:
await self.channel_layer.group_send(
f'user_{user.username}',
f'user_{username}',
{
'type': 'receive_json',
'message_type': 'text',
Expand Down
3 changes: 2 additions & 1 deletion django_chatter/static/css/chat-window.css
Expand Up @@ -116,7 +116,7 @@ AI-------------------------------------------------------------------

.message-received-container {
display: flex;
align-items: center;
align-items: flex-end;
}

.receiver-bubble {
Expand All @@ -130,6 +130,7 @@ AI-------------------------------------------------------------------
width: 30px;
height: 30px;
margin-left: 10px;
margin-bottom: 10px;
}

/*Messages received by other users in the chat have these settings.*/
Expand Down

0 comments on commit 05553cd

Please sign in to comment.