def add_preview_file_to_comment(comment_id, person_id, task_id, revision=0): """ Add a preview to comment preview list. Auto set the revision field (add 1 if it's a new preview, keep the preview revision in other cases). """ comment = get_comment_raw(comment_id) news = News.get_by(comment_id=comment_id) task = Task.get(comment.object_id) project_id = str(task.project_id) position = 1 if revision == 0 and len(comment.previews) == 0: revision = get_next_preview_revision(task_id) elif revision == 0: revision = comment.previews[0].revision position = get_next_position(task_id, revision) else: position = get_next_position(task_id, revision) preview_file = files_service.create_preview_file_raw(str( uuid.uuid4())[:13], revision, task_id, person_id, position=position) events.emit("preview-file:new", { "preview_file_id": preview_file.id, "comment_id": comment_id, }, project_id=project_id) comment.previews.append(preview_file) comment.save() if news is not None: news.update({"preview_file_id": preview_file.id}) events.emit("comment:update", {"comment_id": comment.id}, project_id=project_id) return preview_file.serialize()
def add_preview_file_to_comment(comment_id, person_id, task_id, revision=0): """ Add a preview to comment preview list. Auto set the revision field (add 1 if it's a new preview, keep the preview revision in other cases). """ comment = get_comment_raw(comment_id) if revision == 0 and len(comment.previews) == 0: revision = get_next_preview_revision(task_id) elif revision == 0: revision = comment.previews[0].revision preview_file = files_service.create_preview_file_raw( str(uuid.uuid4())[:13], revision, task_id, person_id ) comment.previews.append(preview_file) comment.save() return preview_file.serialize()