"commented on your answer"

This commit is contained in:
nilsding 2014-12-14 15:10:23 +01:00
parent 154c360e15
commit 43474a6c92
4 changed files with 22 additions and 14 deletions

View File

@ -5,4 +5,8 @@ class Comment < ActiveRecord::Base
validates :answer_id, presence: true
validates :content, length: { maximum: 160 }
def notification_type(*_args)
Notifications::Commented
end
end

View File

@ -0,0 +1,2 @@
class Notifications::Commented < Notification
end

View File

@ -108,7 +108,8 @@ class User < ActiveRecord::Base
end
def comment(answer, content)
Comment.create!(user: self, answer: answer, content: content)
comment = Comment.create!(user: self, answer: answer, content: content)
Notification.notify answer.user, comment unless answer.user == self
increment! :commented_count
answer.increment! :comment_count
end

View File

@ -46,16 +46,17 @@
ago
.notification--icon
%i.fa.fa-smile-o
%li.list-group-item
.media
- when "Comment"
.pull-left
%img.notification--img
%img.notification--img{src: gravatar_url(notification.target.user)}
.media-body
%h6.media-heading.notification--user
username
= user_screen_name notification.target.user
%p.notification--text
commented
commented on
%a{href: show_user_answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)}
%a your answer
some time ago!
= time_ago_in_words notification.target.created_at
ago
.notification--icon
%i.fa.fa-comments