Skip to content

Commit

Permalink
Fixed some problems with activity notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Roendal committed May 12, 2011
1 parent 180ccc6 commit c9298bc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
6 changes: 4 additions & 2 deletions app/helpers/notifications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ def decode_notification notification_text, activity
end

if activity.direct_object.present?
notification_text=notification_text.gsub(/\%\{object\}/,link_to(activity.direct_object.class.to_s.downcase,activity.direct_object))
notification_text=notification_text.gsub(/\%\{object.name\}/,activity.direct_object.class.to_s.downcase)
object = activity.direct_object
object = object.subject if object.is_a? Actor
notification_text=notification_text.gsub(/\%\{object\}/,link_to(object.class.to_s.downcase,object))
notification_text=notification_text.gsub(/\%\{object.name\}/,object.class.to_s.downcase)
else
notification_text=notification_text.gsub(/\%\{object\}/,"nilclass")
notification_text=notification_text.gsub(/\%\{object.name\}/,"nilclass")
Expand Down
42 changes: 21 additions & 21 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# == Wall
# The Activity.wall(type, ties) scope provides all the activities attached to a set of ties
#
#
# There are two types of wall, :home and :profile. Check {Actor#wall} for more information
#
class Activity < ActiveRecord::Base
Expand All @@ -28,7 +28,6 @@ class Activity < ActiveRecord::Base
has_many :activity_objects,
:through => :activity_object_activities


scope :wall, lambda { |type, ties|
q = select("DISTINCT activities.*").
roots.
Expand All @@ -44,14 +43,16 @@ class Activity < ActiveRecord::Base
q
}

after_create :send_notifications

# After an activity is created, it is disseminated to follower ties
attr_accessor :_tie
after_create :disseminate_to_ties

after_create :increment_like_count
after_destroy :decrement_like_count

#For now, it should be the last one
#FIXME
after_create :send_notifications

# The name of the verb of this activity
def verb
Expand All @@ -68,7 +69,7 @@ def verb=(name)
# This method provides the {Actor}. Use {#sender_subject} for the {SocialStream::Models::Subject Subject}
# ({User}, {Group}, etc..)
def sender
tie.sender
tie.sender
end

# The {SocialStream::Models::Subject Subject} author of this activity
Expand Down Expand Up @@ -117,12 +118,12 @@ def liked_by?(user)
# Build a new children activity where subject like this
def new_like(subject)
a = children.new :verb => "like",
:_tie => subject.sent_ties(:receiver => receiver).first
:_tie => subject.sent_ties(:receiver => receiver).first

if direct_activity_object.present?
if direct_activity_object.present?
a.activity_objects << direct_activity_object
end

a
end

Expand All @@ -141,28 +142,27 @@ def title view
case verb
when "follow", "make-friend", "like"
I18n.t "activity.verb.#{ verb }.#{ tie.receiver.subject_type }.title",
:subject => view.link_name(sender_subject),
:contact => view.link_name(receiver_subject)
:subject => view.link_name(sender_subject),
:contact => view.link_name(receiver_subject)
when "post"
view.link_name sender_subject
end.html_safe
end

def notificable?
is_root? or ['post','update'].include?(root.verb)
end

def notify
return nil if !notificable?
#Avaible verbs: follow, like, make-friend, post, update
actionview = ActivitiesController.new.view_context
if ['like','follow','make-friend','post','update'].include? verb and _tie.sender!=_tie.receiver
notification_subject = actionview.render :partial => 'notifications/activities/' + verb + "_subject", :locals => {:activity => self}
notification_body = actionview.render :partial => 'notifications/activities/' + verb + "_body", :locals => {:activity => self}
end
if notification_subject.present? and notification_body.present?
receipts = _tie.receiver.notify(notification_subject, notification_body, self)
return true if !notificable?
#Avaible verbs: follow, like, make-friend, post, update
actionview = ActivitiesController.new.view_context
if ['like','follow','make-friend','post','update'].include? verb and _tie.sender!=_tie.receiver
notification_subject = actionview.render :partial => 'notifications/activities/' + verb + "_subject", :locals => {:activity => self}
notification_body = actionview.render :partial => 'notifications/activities/' + verb + "_body", :locals => {:activity => self}
_tie.receiver.notify(notification_subject, notification_body, self)
end
true
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/views/notifications/activities/_like_body.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if activity.direct_object.present? %>
<%= render :partial => 'notifications/activities/like_object_body', :locals => {:activity => activity} %>
<% if activity.direct_object.is_a? Actor %>
<%= render :partial => 'notifications/activities/like_subject_body' %>
<% else %>
<%= render :partial => 'notifications/activities/like_subject_body', :locals => {:activity => activity} %>
<%= render :partial => 'notifications/activities/like_object_body'%>
<% end %>
6 changes: 3 additions & 3 deletions app/views/notifications/activities/_like_subject.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if activity.direct_object.present? %>
<%= render :partial => 'notifications/activities/like_object_subject', :locals => {:activity => activity} %>
<% if activity.direct_object.is_a? Actor %>
<%= render :partial => 'notifications/activities/like_subject_subject' %>
<% else %>
<%= render :partial => 'notifications/activities/like_subject_subject', :locals => {:activity => activity} %>
<%= render :partial => 'notifications/activities/like_object_subject' %>
<% end %>

0 comments on commit c9298bc

Please sign in to comment.