diff --git a/app/models/comment.rb b/app/models/comment.rb index fcaf7c24..1cfe26b4 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/notifications/commented.rb b/app/models/notifications/commented.rb new file mode 100644 index 00000000..7eacfeb5 --- /dev/null +++ b/app/models/notifications/commented.rb @@ -0,0 +1,2 @@ +class Notifications::Commented < Notification +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 8fd15b5c..b3b5982d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 58c1dfcc..1d483343 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -46,16 +46,17 @@ ago .notification--icon %i.fa.fa-smile-o - %li.list-group-item - .media - .pull-left - %img.notification--img - .media-body - %h6.media-heading.notification--user - username - %p.notification--text - commented - %a your answer - some time ago! - .notification--icon - %i.fa.fa-comments \ No newline at end of file + - when "Comment" + .pull-left + %img.notification--img{src: gravatar_url(notification.target.user)} + .media-body + %h6.media-heading.notification--user + = user_screen_name notification.target.user + %p.notification--text + commented on + %a{href: show_user_answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)} + %a your answer + = time_ago_in_words notification.target.created_at + ago + .notification--icon + %i.fa.fa-comments \ No newline at end of file