def get(self, request): """List all chats in which the currently logged in user is involved. The chats are in descending order of the most recent message time; this means that the first element of the chats list is the chat with the most recent activity. The most recent message is included. --- tags: - Chat responses: 200: description: A list of all the chats the logged in user is involved. schema: type: object required: - chats properties: chats: type: array items: $ref: '#/definitions/chat_information' ... :type request: HttpRequest """ chats = ChatModel.objects \ .filter(participants__id__in=[request.user.id]) \ .annotate(latest_message_time=Max('messages__created_at')) \ .order_by('-latest_message_time') return self.success( {'chats': [serializers.chat(chat) for chat in chats]})
def get(self, request): """List all chats in which the currently logged in user is involved. The chats are in descending order of the most recent message time; this means that the first element of the chats list is the chat with the most recent activity. The most recent message is included. --- tags: - Chat responses: 200: description: A list of all the chats the logged in user is involved. schema: type: object required: - chats properties: chats: type: array items: $ref: '#/definitions/chat_information' ... :type request: HttpRequest """ chats = ChatModel.objects \ .filter(participants__id__in=[request.user.id]) \ .annotate(latest_message_time=Max('messages__created_at')) \ .order_by('-latest_message_time') return self.success({'chats': [serializers.chat(chat) for chat in chats]})
def put(self, request, chat): """Update details about specific chat --- tags: - Chat parameters: - in: body name: body schema: id: modify_chat required: - name properties: name: type: string example: Peter's chat description: User defined name of chat responses: 200: description: Chat modified schema: $ref: '#/definitions/chat_information' 403: description: The logged in user is not part of the conversation schema: $ref: '#/definitions/result_error_forbidden' 404: description: the chat does not exist ... :type request: HttpRequest :type chat: ChatModel """ chat.name = request.body['name'] chat.save() return self.success(serializers.chat(chat))