Skip to content
Extraits de code Groupes Projets
posts_controller.rb 1,99 ko
Newer Older
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
maxwell's avatar
maxwell a validé
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class PostsController < ApplicationController
theworldbright's avatar
theworldbright a validé
  before_action :authenticate_user!, only: :destroy
  before_action :set_format_if_malformed_from_status_net, only: :show
theworldbright's avatar
theworldbright a validé
  respond_to :html, :mobile, :json, :xml
theworldbright's avatar
theworldbright a validé
  rescue_from Diaspora::NonPublic do |_exception|
theworldbright's avatar
theworldbright a validé
      format.all { render template: "errors/not_public", status: 404, layout: "application" }
maxwell's avatar
maxwell a validé
  def show
theworldbright's avatar
theworldbright a validé
    post_service = PostService.new(id: params[:id], user: current_user)
    post_service.assign_post_and_mark_notifications
    @post = post_service.post
    respond_to do |format|
theworldbright's avatar
theworldbright a validé
      format.html { gon.post = post_service.present_json }
      format.xml { render xml: @post.to_diaspora_xml }
theworldbright's avatar
theworldbright a validé
      format.json { render json: post_service.present_json }
theworldbright's avatar
theworldbright a validé
    render text: post_iframe_url(params[:id]), layout: false
Maxwell Salzberg's avatar
Maxwell Salzberg a validé
  def oembed
    post_id = OEmbedPresenter.id_from_url(params.delete(:url))
theworldbright's avatar
theworldbright a validé
    post_service = PostService.new(id: post_id, user: current_user,
                                    oembed: params.slice(:format, :maxheight, :minheight))
    post_service.assign_post
    render json: post_service.present_oembed
Maxwell Salzberg's avatar
Maxwell Salzberg a validé
  end

  def interactions
theworldbright's avatar
theworldbright a validé
    post_service = PostService.new(id: params[:id], user: current_user)
    post_service.assign_post
    respond_with(post_service.present_interactions_json)
  end

  def destroy
theworldbright's avatar
theworldbright a validé
    post_service = PostService.new(id: params[:id], user: current_user)
    post_service.retract_post
    @post = post_service.post
    respond_to do |format|
theworldbright's avatar
theworldbright a validé
      format.js { render "destroy", layout: false, format: :js }
      format.json { render nothing: true, status: 204 }
Maxwell Salzberg's avatar
Maxwell Salzberg a validé
      format.any { redirect_to stream_path }
theworldbright's avatar
theworldbright a validé
  private
Maxwell Salzberg's avatar
Maxwell Salzberg a validé

  def set_format_if_malformed_from_status_net
theworldbright's avatar
theworldbright a validé
    request.format = :html if request.format == "application/html+xml"
maxwell's avatar
maxwell a validé
end