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
|
# File 'app/jobs/collavre_slack/slack_reaction_job.rb', line 5
def perform(comment_id:, emoji:, action:, user_id: nil)
Rails.logger.info("[CollavreSlack] SlackReactionJob performing: comment_id=#{}, emoji=#{emoji.inspect}, action=#{action}")
= SlackCommentLink.where(comment_id: )
Rails.logger.info("[CollavreSlack] Found #{.count} comment links")
return if .empty?
slack_emoji = EmojiMapping.to_slack(emoji)
Rails.logger.info("[CollavreSlack] Normalized emoji: #{emoji.inspect} -> #{slack_emoji.inspect}")
.each do |link|
channel_link = link.slack_channel_link
client = SlackClient.new(access_token: channel_link.slack_account.access_token)
response = if action == :add
client.add_reaction(
channel: channel_link.channel_id,
timestamp: link.message_ts,
name: slack_emoji
)
else
client.remove_reaction(
channel: channel_link.channel_id,
timestamp: link.message_ts,
name: slack_emoji
)
end
if response[:ok]
Rails.logger.info("[CollavreSlack] Reaction #{action} successful for channel=#{channel_link.channel_id}, ts=#{link.message_ts}")
else
unless %w[already_reacted no_reaction].include?(response[:error])
Rails.logger.warn("[CollavreSlack] Reaction #{action} failed: #{response[:error]}")
end
end
end
end
|