"followed you"

This commit is contained in:
nilsding 2014-12-14 14:58:29 +01:00
parent c56177cd10
commit c9b5947e6b
4 changed files with 25 additions and 19 deletions

View File

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

View File

@ -3,4 +3,8 @@ class Relationship < ActiveRecord::Base
belongs_to :target, class_name: 'User' belongs_to :target, class_name: 'User'
validates :source_id, presence: true validates :source_id, presence: true
validates :target_id, presence: true validates :target_id, presence: true
def notification_type(*_args)
Notifications::StartedFollowing
end
end end

View File

@ -56,7 +56,8 @@ class User < ActiveRecord::Base
# follows an user. # follows an user.
def follow(target_user) def follow(target_user)
active_relationships.create(target: target_user) relationship = active_relationships.create(target: target_user)
Notification.notify target_user, relationship
# increment counts # increment counts
increment! :friend_count increment! :friend_count

View File

@ -5,13 +5,13 @@
- Notification.for(current_user).each do |notification| - Notification.for(current_user).each do |notification|
%li.list-group-item %li.list-group-item
.media .media
- case notification.target_type
- when "Answer"
.pull-left .pull-left
%img.notification--img{src: gravatar_url(notification.target.user)} %img.notification--img{src: gravatar_url(notification.target.user)}
.media-body .media-body
%h6.media-heading.notification--user %h6.media-heading.notification--user
= user_screen_name notification.target.user = user_screen_name notification.target.user
- case notification.target_type
- when "Answer"
%p.notification--text %p.notification--text
answered answered
%a{href: show_user_answer_path(username: notification.target.user.screen_name, id: notification.target.id)} %a{href: show_user_answer_path(username: notification.target.user.screen_name, id: notification.target.id)}
@ -20,13 +20,12 @@
ago ago
.notification--icon .notification--icon
%i.fa.fa-exclamation %i.fa.fa-exclamation
%li.list-group-item - when "Relationship"
.media
.pull-left .pull-left
%img.notification--img %img.notification--img{src: gravatar_url(notification.target.source)}
.media-body .media-body
%h6.media-heading.notification--user %h6.media-heading.notification--user
username = user_screen_name notification.target.source
%p.notification--text %p.notification--text
followed you! followed you!
.notification--icon .notification--icon