mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-31 15:29:08 +01:00
added User#answer, moved some code from inbox.rb to answer.rb
This commit is contained in:
parent
82924cfbec
commit
8aee9bd69e
3 changed files with 19 additions and 7 deletions
|
@ -4,6 +4,12 @@ class Answer < ActiveRecord::Base
|
|||
has_many :comments, dependent: :destroy
|
||||
has_many :smiles, dependent: :destroy
|
||||
|
||||
after_create do
|
||||
Notification.notify self.question.user, self unless self.question.author_is_anonymous
|
||||
self.user.increment! :answered_count
|
||||
self.question.increment! :answer_count
|
||||
end
|
||||
|
||||
before_destroy do
|
||||
# mark a report as deleted if it exists
|
||||
rep = Report.where(target_id: self.id).first
|
||||
|
|
|
@ -2,13 +2,8 @@ class Inbox < ActiveRecord::Base
|
|||
belongs_to :user
|
||||
belongs_to :question
|
||||
|
||||
def answer(answer, user)
|
||||
answer = Answer.create!(content: answer,
|
||||
user: user,
|
||||
question: self.question)
|
||||
Notification.notify self.question.user, answer unless self.question.author_is_anonymous
|
||||
user.increment! :answered_count
|
||||
self.question.increment! :answer_count
|
||||
def answer(answer_content, user)
|
||||
answer = user.answer(self.question, answer_content)
|
||||
self.destroy
|
||||
answer
|
||||
end
|
||||
|
|
|
@ -92,6 +92,15 @@ class User < ActiveRecord::Base
|
|||
friends.include? target_user
|
||||
end
|
||||
|
||||
# answers a question
|
||||
# @param question [Question] the question to answer
|
||||
# @param content [String] the answer content
|
||||
def answer(question, content)
|
||||
Answer.create!(content: content,
|
||||
user: self,
|
||||
question: question)
|
||||
end
|
||||
|
||||
# smiles an answer
|
||||
# @param answer [Answer] the answer to smile
|
||||
def smile(answer)
|
||||
|
@ -125,6 +134,7 @@ class User < ActiveRecord::Base
|
|||
self.moderator? || self.admin?
|
||||
end
|
||||
|
||||
# region stuff used for reporting/moderation
|
||||
def report(object)
|
||||
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id)
|
||||
end
|
||||
|
@ -156,6 +166,7 @@ class User < ActiveRecord::Base
|
|||
def report_comment(report, content)
|
||||
ModerationComment.create!(user: self, report: report, content: content)
|
||||
end
|
||||
# endregion
|
||||
|
||||
def cropping?
|
||||
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
|
||||
|
|
Loading…
Reference in a new issue