Skip to content
Extraits de code Groupes Projets
status_messages_controller.rb 3,12 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    
    Raphael's avatar
    Raphael a validé
    #   the COPYRIGHT file.
    
    maxwell's avatar
    maxwell a validé
    class StatusMessagesController < ApplicationController
    
      before_filter :authenticate_user!
    
      respond_to :html
      respond_to :json, :only => :show
    
    
    maxwell's avatar
    maxwell a validé
      def create
    
        params[:status_message][:aspect_ids] = params[:aspect_ids]
    
        photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle)
    
        public_flag = params[:status_message][:public]
    
    maxwell's avatar
    maxwell a validé
        public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
    
        params[:status_message][:public] = public_flag
    
        @status_message = current_user.build_post(:status_message, params[:status_message])
    
        aspects = current_user.aspects_from_ids(params[:aspect_ids])
    
          current_user.add_to_streams(@status_message, aspects)
          current_user.dispatch_post(@status_message, :url => post_url(@status_message))
    
          if !photos.empty?
            @status_message.photos += photos
            for photo in photos
              photo.public = public_flag
    
    Raphael's avatar
    Raphael a validé
              photo.pending = false
    
              current_user.add_to_streams(photo, aspects)
              current_user.dispatch_post(photo)
    
            format.js { render :json => {:post_id => @status_message.id,
    
                                         :html => render_to_string(
    
                                           :partial => 'shared/stream_element',
    
                                           :locals => {
    
                                             :post => @status_message,
    
                                             :person => @status_message.person,
    
                                             :photos => @status_message.photos,
    
                                             :comments => [],
    
                                             :all_aspects => current_user.aspects,
    
                                             :current_user => current_user
    
            },
                               :status => 201 }
            format.html { respond_with @status_message }
    
    maxwell's avatar
    maxwell a validé
      end
    
    maxwell's avatar
    maxwell a validé
      def destroy
    
        @status_message = current_user.posts.where(:id => params[:id]).first
    
        if @status_message
          @status_message.destroy
    
    Raphael's avatar
    Raphael a validé
          render :nothing => true, :status => 200
    
    Raphael's avatar
    Raphael a validé
          Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'"
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
          render :nothing => true, :status => 404
    
    maxwell's avatar
    maxwell a validé
      end
    
    maxwell's avatar
    maxwell a validé
      def show
    
        @status_message = current_user.find_visible_post_by_id params[:id]
    
        comments_hash = Comment.hash_from_post_ids [@status_message.id]
        person_hash = Person.from_post_comment_hash comments_hash
        @comment_hashes = comments_hash[@status_message.id].map do |comment|
          {:comment => comment,
    
           :person => person_hash[comment.person_id]
    
    
        @object_aspect_ids = @status_message.aspects.map{|a| a.id}
    
    
        respond_with @status_message
    
    maxwell's avatar
    maxwell a validé
      end
    
    maxwell's avatar
    maxwell a validé
    end