2022-02-19 17:19:28 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module User::ReactionMethods
|
|
|
|
# smiles an answer or comment
|
|
|
|
# @param item [ApplicationRecord] the answer/comment to smile
|
|
|
|
def smile(item)
|
2022-07-05 22:31:15 +02:00
|
|
|
raise Errors::ReactingSelfBlockedOther if self.blocking?(item.user)
|
|
|
|
raise Errors::ReactingOtherBlockedSelf if item.user.blocking?(self)
|
2022-02-19 17:19:28 +01:00
|
|
|
|
2023-10-26 05:54:48 +02:00
|
|
|
Reaction.create!(user: self, parent: item, content: "🙂")
|
2022-02-19 17:19:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# unsmile an answer or comment
|
|
|
|
# @param item [ApplicationRecord] the answer/comment to unsmile
|
|
|
|
def unsmile(item)
|
2023-11-05 13:10:21 +01:00
|
|
|
Reaction.find_by!(user: self, parent: item).destroy
|
2022-02-19 17:19:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def smiled?(item)
|
|
|
|
item.smiles.pluck(:user_id).include? id
|
|
|
|
end
|
|
|
|
end
|