def search_messages(self, data): offset = data[VarNames.SEARCH_OFFSET] #// room, offset messages = Message.objects.filter( content__icontains=data[VarNames.SEARCH_STRING], room_id=data[VarNames.ROOM_ID] # access permissions is already checked on top level by ROOM_ID ).order_by('-id')[offset:offset + settings.MESSAGES_PER_SEARCH] content = MessagesCreator.message_models_to_dtos(messages) self.ws_write({ VarNames.CONTENT: content, VarNames.JS_MESSAGE_ID: data[VarNames.JS_MESSAGE_ID], VarNames.HANDLER_NAME: HandlerNames.NULL })
def sync_history(self, in_message): room_ids = in_message[VarNames.ROOM_IDS] message_ids = in_message[VarNames.MESSAGE_IDS] if not set(room_ids).issubset(self.channels): raise ValidationError("This is not a messages in the room you are in") messages = Message.objects.filter( Q(room_id__in=room_ids) & ~Q(id__in=message_ids) & Q(edited_times__gt=get_milliseconds() - in_message[VarNames.LAST_SYNCED]) ) content = MessagesCreator.message_models_to_dtos(messages) self.ws_write({ VarNames.CONTENT: content, VarNames.JS_MESSAGE_ID: in_message[VarNames.JS_MESSAGE_ID], VarNames.HANDLER_NAME: HandlerNames.NULL })