Skip to content

Commit 5de1c41

Browse files
authored
Merge pull request #446 from PROCOLLAB-github/fix/directs-error
fix error
2 parents 573f772 + 325173f commit 5de1c41

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

chats/views.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ def get(self, request, *args, **kwargs):
4343
chats = self.get_queryset()
4444
serialized_chats = []
4545
for chat in chats:
46-
user1_id, _ = map(int, chat.id.split("_"))
47-
# TODO сделать проверку на удаление профиля
48-
if user1_id == request.user.id:
49-
opponent = chat.users.all()[1]
50-
else:
51-
opponent = chat.users.first()
52-
53-
context = {"opponent": opponent}
54-
serialized_chat = DirectChatListSerializer(chat, context=context).data
55-
serialized_chats.append(serialized_chat)
46+
try:
47+
user1_id, _ = map(int, chat.id.split("_"))
48+
# TODO сделать проверку на удаление профиля
49+
if user1_id == request.user.id:
50+
opponent = chat.users.all()[1]
51+
else:
52+
opponent = chat.users.first()
53+
54+
context = {"opponent": opponent}
55+
serialized_chat = DirectChatListSerializer(chat, context=context).data
56+
serialized_chats.append(serialized_chat)
57+
except IndexError:
58+
pass
5659
return Response(serialized_chats, status=status.HTTP_200_OK)
5760

5861

0 commit comments

Comments
 (0)