Skip to content

Commit

Permalink
chore: avoid notification flood
Browse files Browse the repository at this point in the history
  • Loading branch information
lhguerra committed Nov 13, 2024
1 parent bc2ff67 commit 2e51ac2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
19 changes: 5 additions & 14 deletions app/services/slack/slack_notification_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def notify_demand_state_changed(stage, demand, demand_transition)
demand_transition.update(transition_notified: true)
end

def notify_item_assigned(item_assignment, demand_url)
def notify_item_assigned(item_assignment, _demand_url)
return if item_assignment.valid? == false

slack_configurations = slack_configurations(item_assignment.demand, :item_assigned)
Expand All @@ -204,19 +204,10 @@ def notify_item_assigned(item_assignment, demand_url)

return if item_assignment.assignment_notified?

demand_title = "*<#{demand_url}|#{item_assignment.demand.external_id} - #{item_assignment.demand.demand_title}>*"
assign_message = "#{item_assignment.team_member_name} puxou a demanda em _#{item_assignment.assigned_at&.name || 'sem etapa'}_ às #{I18n.l(item_assignment.start_time, format: :short)}"
message_previous_pull = "Anterior: #{item_assignment.previous_assignment&.demand&.external_id}"
message_ongoing = ":computer: #{item_assignment.membership_open_assignments.map(&:demand).flatten.map { |demand| "#{demand.external_id} (#{demand.current_stage_name})" }.join(', ')}"
message_idle = ":zzz: #{time_distance_in_words(item_assignment.pull_interval)} :zzz: :busts_in_silhouette: #{number_to_percentage(item_assignment.membership.team.percentage_idle_members * 100, precision: 0)}"

info_block = { type: 'section', text: { type: 'mrkdwn', text: ">#{demand_title}\n>#{assign_message}\n>#{message_previous_pull}\n>#{message_ongoing}\n>#{message_idle}" } }
divider_block = { type: 'divider' }

slack_configurations.each do |config|
slack_notifier = Slack::Notifier.new(config.room_webhook)
slack_notifier.post(blocks: [info_block, divider_block])
end
# slack_configurations.each do |config|
# slack_notifier = Slack::Notifier.new(config.room_webhook)
# slack_notifier.post(blocks: [info_block, divider_block])
# end

ItemAssignment.transaction { item_assignment.update(assignment_notified: true) }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/slack/slack_notification_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@

Fabricate :slack_configuration, team: team, info_type: :item_assigned, active: true

expect_any_instance_of(Slack::Notifier).to receive(:post)
# expect_any_instance_of(Slack::Notifier).to receive(:post)

described_class.instance.notify_item_assigned(item_assignment, 'htto://foo.bar/baz')
expect(item_assignment.reload.assignment_notified?).to be true
Expand Down

0 comments on commit 2e51ac2

Please sign in to comment.