diff options
Diffstat (limited to 'app/services/draft_notes/destroy_service.rb')
-rw-r--r-- | app/services/draft_notes/destroy_service.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/services/draft_notes/destroy_service.rb b/app/services/draft_notes/destroy_service.rb new file mode 100644 index 00000000000..ddca0debb03 --- /dev/null +++ b/app/services/draft_notes/destroy_service.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module DraftNotes + class DestroyService < DraftNotes::BaseService + # If no `draft` is given it fallsback to all + # draft notes of the given merge request and user. + def execute(draft = nil) + drafts = draft || draft_notes + + clear_highlight_diffs_cache(Array.wrap(drafts)) + + drafts.is_a?(DraftNote) ? drafts.destroy! : drafts.delete_all + end + + private + + def clear_highlight_diffs_cache(drafts) + if drafts.any? { |draft| draft.diff_file&.unfolded? } + merge_request.diffs.clear_cache + end + end + end +end |