Exemplo n.º 1
0
 def get_offline_messages(self, user_rooms, was_online, with_history):
     q_objects = get_history_message_query(
         self.get_argument('messages', None), user_rooms, with_history)
     if was_online:
         off_messages = []
     else:
         off_messages = Message.objects.filter(
             id__gt=F('room__roomusers__last_read_message_id'),
             room__roomusers__user_id=self.user_id)
     off = {}
     history = {}
     if len(q_objects.children) > 0:
         history_messages = Message.objects.filter(q_objects)
         all = list(chain(off_messages, history_messages))
         self.logger.info("Offline messages IDs: %s, history messages: %s",
                          [m.id for m in off_messages],
                          [m.id for m in history_messages])
     else:
         history_messages = []
         all = off_messages
     if self.restored_connection:
         off_messages = all
         history_messages = []
     imv = get_message_images_videos(all)
     self.set_video_images_messages(imv, off_messages, off)
     self.set_video_images_messages(imv, history_messages, history)
     return off, history
Exemplo n.º 2
0
    def message_models_to_dtos(cls, messages):
        imv = get_message_images_videos(messages)
        tags = get_message_tags(messages)

        def message_to_dto(message):
            files = cls.prepare_img_video(imv, message.id)
            prep_tags = cls.prepare_tags(tags, message.id)
            return cls.create_message(message, files, prep_tags)

        return list(map(message_to_dto, messages))
Exemplo n.º 3
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
Exemplo n.º 4
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')
Exemplo n.º 5
0
    def process_get_messages(self, data):
        """
		:type data: dict
		"""
        header_id = data.get(VarNames.GET_MESSAGES_HEADER_ID, None)
        count = int(data.get(VarNames.GET_MESSAGES_COUNT, 10))
        room_id = data[VarNames.ROOM_ID]
        self.logger.info('!! Fetching %d messages starting from %s', count,
                         header_id)
        if header_id is None:
            messages = Message.objects.filter(
                room_id=room_id).order_by('-pk')[:count]
        else:
            messages = Message.objects.filter(
                Q(id__lt=header_id),
                Q(room_id=room_id)).order_by('-pk')[:count]
        imv = get_message_images_videos(messages)
        response = self.get_messages(messages, room_id, imv,
                                     MessagesCreator.prepare_img_video,
                                     data[VarNames.JS_MESSAGE_ID])
        self.ws_write(response)