summaryrefslogtreecommitdiff
path: root/app/services/zoom_notes_service.rb
blob: 983a7fcacd185ba2423224f04b4ac3702dc1b148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

class ZoomNotesService
  def initialize(issue, project, current_user, old_description: nil)
    @issue = issue
    @project = project
    @current_user = current_user
    @old_description = old_description
  end

  def execute
    return if @issue.description == @old_description

    if zoom_link_added?
      zoom_link_added_notification
    elsif zoom_link_removed?
      zoom_link_removed_notification
    end
  end

  private

  def zoom_link_added?
    has_zoom_link?(@issue.description) && !has_zoom_link?(@old_description)
  end

  def zoom_link_removed?
    !has_zoom_link?(@issue.description) && has_zoom_link?(@old_description)
  end

  def has_zoom_link?(text)
    Gitlab::ZoomLinkExtractor.new(text).match?
  end

  def zoom_link_added_notification
    SystemNoteService.zoom_link_added(@issue, @project, @current_user)
  end

  def zoom_link_removed_notification
    SystemNoteService.zoom_link_removed(@issue, @project, @current_user)
  end
end