"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'
validates :source_id, presence: true
validates :target_id, presence: true
def notification_type(*_args)
Notifications::StartedFollowing
end
end

View File

@ -56,7 +56,8 @@ class User < ActiveRecord::Base
# follows an 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! :friend_count

View File

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