"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
.pull-left - case notification.target_type
%img.notification--img{src: gravatar_url(notification.target.user)} - when "Answer"
.media-body .pull-left
%h6.media-heading.notification--user %img.notification--img{src: gravatar_url(notification.target.user)}
= user_screen_name notification.target.user .media-body
- case notification.target_type %h6.media-heading.notification--user
- when "Answer" = user_screen_name notification.target.user
%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,17 +20,16 @@
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{src: gravatar_url(notification.target.source)}
%img.notification--img .media-body
.media-body %h6.media-heading.notification--user
%h6.media-heading.notification--user = user_screen_name notification.target.source
username %p.notification--text
%p.notification--text followed you!
followed you! .notification--icon
.notification--icon %i.fa.fa-users
%i.fa.fa-users
%li.list-group-item %li.list-group-item
.media .media
.pull-left .pull-left