Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
module SocketsHelper
danielvincent
a validé
include NotificationsHelper
if object.respond_to?(:post_id)
object.post_id
elsif object.respond_to?(:post_guid)
object.post_guid
else
object.id
end
def action_hash(user, object, opts={})
uid = user.id
unless user.nil?
old_locale = I18n.locale
I18n.locale = user.language.to_s
end
:comments => object.comments.map{|c|
{:comment => c,
Maxwell Salzberg
a validé
:all_aspects => all_aspects,
}
v = render_to_string(:partial => 'shared/stream_element', :locals => post_hash)
:single_aspect_form => opts["single_aspect_form"],
Maxwell Salzberg
a validé
:all_aspects => all_aspects,
:contact => user.contact_for(object),
:current_user => user}
v = render_to_string(:partial => 'people/person', :locals => person_hash)
danielvincent
a validé
elsif object.is_a? Comment
v = render_to_string(:partial => 'comments/comment', :locals => {:post => object.post, :comment => object, :person => object.author, :current_user => user})
danielvincent
a validé
MrZYX
a validé
elsif object.is_a? Like
v = render_to_string(:partial => 'likes/likes', :locals => {:likes => object.post.likes, :dislikes => object.post.dislikes})
danielvincent
a validé
elsif object.is_a? Notification
v = render_to_string(:partial => 'notifications/popup', :locals => {:note => object, :person => opts[:actor]})
danielvincent
a validé
raise "#{object.inspect} with class #{object.class} is not actionhashable." unless object.is_a? Retraction
Rails.logger.error("event=socket_render status=fail user=#{user.diaspora_handle} object=#{object.id.to_s}")
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
action_hash[:photo_hash] = object.thumb_hash
if object.is_a? Comment
post = object.post
danielvincent
a validé
action_hash[:comment_id] = object.id
action_hash[:my_post?] = (post.author.owner_id == uid)
action_hash[:post_guid] = post.guid
MrZYX
a validé
if object.is_a? Like
action_hash[:post_guid] = object.post.guid
end
action_hash[:mine?] = object.author && (object.author.owner_id == uid) if object.respond_to?(:author)