Esempio n. 1
0
	def search_messages(self, data, room, offset):
		offset = int(offset)
		if not RoomUsers.objects.filter(room_id=room, user_id=self.user_id).exists():
			raise ValidationError("You can't access this room")
		messages = Message.objects.filter(content__icontains=data, room_id=room).order_by('-id')[
					  offset:offset + settings.MESSAGES_PER_SEARCH]
		imv = get_message_images_videos(messages)
		result = []
		for message in messages:
			files = MessagesCreator.prepare_img_video(imv, message.id)
			prep_m = MessagesCreator.create_message(message, files)
			result.append(prep_m)
		return result
Esempio n. 2
0
def search_messages(request):
    data = request.POST['data']
    room_id = request.POST['room']
    offset = int(request.POST['offset'])
    if not RoomUsers.objects.filter(room_id=room_id,
                                    user_id=request.user.id).exists():
        raise ValidationError("You can't access this room")
    messages = Message.objects.filter(
        content__icontains=data,
        room_id=room_id).order_by('-id')[offset:offset +
                                         settings.MESSAGES_PER_SEARCH]
    imv = get_message_images_videos(messages)
    result = []
    for message in messages:
        files = MessagesCreator.prepare_img_video(imv, message.id)
        prep_m = MessagesCreator.create_message(message, files)
        result.append(prep_m)
    response = json.dumps(result)
    return HttpResponse(response, content_type='application/json')