"smiled your answer"

This commit is contained in:
nilsding 2014-12-14 15:06:10 +01:00
parent c9b5947e6b
commit 154c360e15
4 changed files with 25 additions and 15 deletions

View File

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

View File

@ -3,4 +3,8 @@ class Smile < ActiveRecord::Base
belongs_to :answer belongs_to :answer
validates :user_id, presence: true validates :user_id, presence: true
validates :answer_id, presence: true validates :answer_id, presence: true
def notification_type(*_args)
Notifications::Smiled
end
end end

View File

@ -81,7 +81,8 @@ class User < ActiveRecord::Base
# smiles an answer # smiles an answer
# @param answer [Answer] the answer to smile # @param answer [Answer] the answer to smile
def smile(answer) def smile(answer)
Smile.create(user: self, answer: answer) smile = Smile.create(user: self, answer: answer)
Notification.notify answer.user, smile unless answer.user == self
increment! :smiled_count increment! :smiled_count
answer.increment! :smile_count answer.increment! :smile_count
end end

View File

@ -27,22 +27,25 @@
%h6.media-heading.notification--user %h6.media-heading.notification--user
= user_screen_name notification.target.source = user_screen_name notification.target.source
%p.notification--text %p.notification--text
followed you! followed you
= time_ago_in_words notification.target.created_at
ago
.notification--icon .notification--icon
%i.fa.fa-users %i.fa.fa-users
%li.list-group-item - when "Smile"
.media .pull-left
.pull-left %img.notification--img{src: gravatar_url(notification.target.user)}
%img.notification--img .media-body
.media-body %h6.media-heading.notification--user
%h6.media-heading.notification--user = user_screen_name notification.target.user
username %p.notification--text
%p.notification--text smiled at
smiled at %a{href: show_user_answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)}
%a your answer your answer
some time ago! = time_ago_in_words notification.target.created_at
.notification--icon ago
%i.fa.fa-smile-o .notification--icon
%i.fa.fa-smile-o
%li.list-group-item %li.list-group-item
.media .media
.pull-left .pull-left