Chatwoot/app/jobs/conversations/user_mention_job.rb
Jordan Brough 59b31615ed
chore: Use "create!" and "save!" bang methods when not checking the result (#5358)
* Use "create!" when not checking for errors on the result
* Use "save!" when not checking the result
2022-09-13 17:40:06 +05:30

24 lines
641 B
Ruby

class Conversations::UserMentionJob < ApplicationJob
queue_as :default
def perform(mentioned_user_ids, conversation_id, account_id)
mentioned_user_ids.each do |mentioned_user_id|
mention = Mention.find_by(
user_id: mentioned_user_id,
conversation_id: conversation_id,
account_id: account_id
)
if mention.nil?
Mention.create!(
user_id: mentioned_user_id,
conversation_id: conversation_id,
mentioned_at: Time.zone.now,
account_id: account_id
)
else
mention.update(mentioned_at: Time.zone.now)
end
end
end
end