Appease the dog overlords
This commit is contained in:
parent
9b5fefc661
commit
04243c2ec8
|
@ -1,4 +1,6 @@
|
|||
require 'errors'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "errors"
|
||||
|
||||
class Ajax::QuestionController < AjaxController
|
||||
def destroy
|
||||
|
@ -72,9 +74,11 @@ class Ajax::QuestionController < AjaxController
|
|||
return
|
||||
end
|
||||
|
||||
# rubocop:disable Style/IfUnlessModifier
|
||||
unless MuteRule.where(user: target_user).any? { |rule| rule.applies_to? question }
|
||||
Inbox.create!(user_id: target_user.id, question_id: question.id, new: true)
|
||||
end
|
||||
# rubocop:enable Style/IfUnlessModifier
|
||||
end
|
||||
|
||||
@response[:status] = :okay
|
||||
|
|
|
@ -106,8 +106,10 @@ class User < ApplicationRecord
|
|||
# @param question [Question] the question to answer
|
||||
# @param content [String] the answer content
|
||||
def answer(question, content)
|
||||
# rubocop:disable Style/RedundantSelf
|
||||
raise Errors::AnsweringOtherBlockedSelf if question.user.blocking?(self)
|
||||
raise Errors::AnsweringSelfBlockedOther if self.blocking?(question.user)
|
||||
# rubocop:enable Style/RedundantSelf
|
||||
|
||||
Answer.create!(content: content,
|
||||
user: self,
|
||||
|
@ -123,8 +125,10 @@ class User < ApplicationRecord
|
|||
# smiles an answer
|
||||
# @param answer [Answer] the answer to smile
|
||||
def smile(answer)
|
||||
# rubocop:disable Style/RedundantSelf
|
||||
raise Errors::ReactingSelfBlockedOther if self.blocking?(answer.user)
|
||||
raise Errors::ReactingOtherBlockedSelf if answer.user.blocking?(self)
|
||||
# rubocop:enable Style/RedundantSelf
|
||||
|
||||
Smile.create!(user: self, answer: answer)
|
||||
end
|
||||
|
@ -156,8 +160,10 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def comment(answer, content)
|
||||
# rubocop:disable Style/RedundantSelf
|
||||
raise Errors::CommentingSelfBlockedOther if self.blocking?(answer.user)
|
||||
raise Errors::CommentingOtherBlockedSelf if answer.user.blocking?(self)
|
||||
# rubocop:enable Style/RedundantSelf
|
||||
|
||||
Comment.create!(user: self, answer: answer, content: content)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'errors'
|
||||
require "errors"
|
||||
|
||||
class User
|
||||
module Relationship
|
||||
|
@ -22,11 +22,7 @@ class User
|
|||
def block(target_user)
|
||||
raise Errors::BlockingSelf if target_user == self
|
||||
|
||||
unfollow(target_user) if following?(target_user)
|
||||
target_user.unfollow(self) if target_user.following?(self)
|
||||
target_user.inboxes.joins(:question).where(question: { user_id: id }).destroy_all
|
||||
inboxes.joins(:question).where(questions: { user_id: target_user.id, author_is_anonymous: false }).destroy_all
|
||||
ListMember.joins(:list).where(list: { user_id: target_user.id }, user_id: id).destroy_all
|
||||
unfollow_and_remove(target_user)
|
||||
create_relationship(active_block_relationships, target_user)
|
||||
end
|
||||
|
||||
|
@ -39,6 +35,16 @@ class User
|
|||
def blocking?(target_user)
|
||||
relationship_active?(blocked_users, target_user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unfollow_and_remove(target_user)
|
||||
unfollow(target_user) if following?(target_user)
|
||||
target_user.unfollow(self) if target_user.following?(self)
|
||||
target_user.inboxes.joins(:question).where(question: { user_id: id }).destroy_all
|
||||
inboxes.joins(:question).where(questions: { user_id: target_user.id, author_is_anonymous: false }).destroy_all
|
||||
ListMember.joins(:list).where(list: { user_id: target_user.id }, user_id: id).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,8 +21,10 @@ class User
|
|||
# Follow an user
|
||||
def follow(target_user)
|
||||
raise Errors::FollowingSelf if target_user == self
|
||||
# rubocop:disable Style/RedundantSelf
|
||||
raise Errors::FollowingOtherBlockedSelf if target_user.blocking?(self)
|
||||
raise Errors::FollowingSelfBlockedOther if self.blocking?(target_user)
|
||||
# rubocop:enable Style/RedundantSelf
|
||||
|
||||
create_relationship(active_follow_relationships, target_user)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue