From 154c360e156d77206d724a6f51b46fb0561c2563 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sun, 14 Dec 2014 15:06:10 +0100 Subject: [PATCH] "smiled your answer" --- app/models/notifications/smiled.rb | 2 ++ app/models/smile.rb | 4 ++++ app/models/user.rb | 3 ++- app/views/notifications/index.html.haml | 31 ++++++++++++++----------- 4 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 app/models/notifications/smiled.rb diff --git a/app/models/notifications/smiled.rb b/app/models/notifications/smiled.rb new file mode 100644 index 00000000..58ab289e --- /dev/null +++ b/app/models/notifications/smiled.rb @@ -0,0 +1,2 @@ +class Notifications::Smiled < Notification +end \ No newline at end of file diff --git a/app/models/smile.rb b/app/models/smile.rb index eed8ffd8..b73d5386 100644 --- a/app/models/smile.rb +++ b/app/models/smile.rb @@ -3,4 +3,8 @@ class Smile < ActiveRecord::Base belongs_to :answer validates :user_id, presence: true validates :answer_id, presence: true + + def notification_type(*_args) + Notifications::Smiled + end end diff --git a/app/models/user.rb b/app/models/user.rb index 1e52263b..8fd15b5c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -81,7 +81,8 @@ class User < ActiveRecord::Base # smiles an answer # @param answer [Answer] the answer to smile 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 answer.increment! :smile_count end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 70129d0c..58c1dfcc 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -27,22 +27,25 @@ %h6.media-heading.notification--user = user_screen_name notification.target.source %p.notification--text - followed you! + followed you + = time_ago_in_words notification.target.created_at + ago .notification--icon %i.fa.fa-users - %li.list-group-item - .media - .pull-left - %img.notification--img - .media-body - %h6.media-heading.notification--user - username - %p.notification--text - smiled at - %a your answer - some time ago! - .notification--icon - %i.fa.fa-smile-o + - when "Smile" + .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 + smiled at + %a{href: show_user_answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)} + your answer + = time_ago_in_words notification.target.created_at + ago + .notification--icon + %i.fa.fa-smile-o %li.list-group-item .media .pull-left