2025-03-21 11:45:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseSolved
|
|
|
|
class FirstAcceptedPostSolutionValidator
|
|
|
|
def self.check(post, trust_level:)
|
|
|
|
return false if post.archetype != Archetype.default
|
|
|
|
return false if !post&.user&.human?
|
|
|
|
|
2025-06-30 15:40:16 +08:00
|
|
|
if trust_level != "any" && TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
|
|
|
|
return false
|
2025-03-21 11:45:19 +08:00
|
|
|
end
|
|
|
|
|
2025-06-30 15:40:16 +08:00
|
|
|
!DiscourseSolved::SolvedTopic
|
|
|
|
.joins(:answer_post)
|
2025-07-02 11:45:14 +08:00
|
|
|
.where("posts.user_id = ? AND posts.id != ?", post.user_id, post.id)
|
2025-06-30 15:40:16 +08:00
|
|
|
.exists?
|
2025-03-21 11:45:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|