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
43
44
45
|
# File 'app/jobs/collavre_slack/slack_inbound_reaction_job.rb', line 5
def perform(payload)
data = payload.with_indifferent_access
= Collavre::Comment.find_by(id: data[:comment_id])
user = Collavre.user_class.find_by(id: data[:user_id])
return unless && user
return unless .creative.has_permission?(user, :feedback)
emoji = data[:emoji]
action = data[:type].to_sym
if action == :reaction_added
reaction = Collavre::CommentReaction.find_or_initialize_by(
comment: ,
user: user,
emoji: emoji
)
if reaction.new_record?
reaction.instance_variable_set(:@from_slack, true)
reaction.save!
Rails.logger.info("[CollavreSlack] Created reaction from Slack: comment_id=#{.id}, emoji=#{emoji}, user_id=#{user.id}")
end
elsif action == :reaction_removed
reaction = Collavre::CommentReaction.find_by(
comment: ,
user: user,
emoji: emoji
)
if reaction
reaction.instance_variable_set(:@from_slack, true)
reaction.destroy!
Rails.logger.info("[CollavreSlack] Removed reaction from Slack: comment_id=#{.id}, emoji=#{emoji}, user_id=#{user.id}")
end
end
end
|