Skip to content
Extraits de code Groupes Projets
requests_controller.rb 1,96 ko
Newer Older
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.  See
#   the COPYRIGHT file.
class RequestsController < ApplicationController
  before_filter :authenticate_user!
Jamie Wilkinson's avatar
Jamie Wilkinson a validé
  include RequestsHelper
Raphael's avatar
Raphael a validé
      if params[:aspect_id]
        @friend = current_user.accept_and_respond( params[:id], params[:aspect_id])
        flash[:notice] = I18n.t 'requests.destroy.success'
        respond_with :location => current_user.aspect_by_id(params[:aspect_id])
        flash[:error] = I18n.t 'requests.destroy.error'
        respond_with :location => requests_url
Raphael's avatar
Raphael a validé
      end
    else
      current_user.ignore_friend_request params[:id]
      flash[:notice] = I18n.t 'requests.destroy.ignore'
      respond_with :location => requests_url
Raphael's avatar
Raphael a validé
    aspect = current_user.aspect_by_id(params[:request][:aspect_id])
Jamie Wilkinson's avatar
Jamie Wilkinson a validé
    begin
      rel_hash = relationship_flow(params[:request][:destination_url])
    rescue Exception => e
Raphael's avatar
Raphael a validé
      raise e unless e.message.include? "not found"
      flash[:error] = I18n.t 'requests.create.error'
      respond_with :location => aspect
    # rel_hash = {:friend => params[:friend_handle]}
    Rails.logger.debug("Sending request: #{rel_hash}")
Raphael's avatar
Raphael a validé
      @request = current_user.send_friend_request_to(rel_hash[:friend], aspect)
    rescue Exception => e
      raise e unless e.message.include? "already"
      flash[:notice] = I18n.t 'requests.create.already_friends', :destination_url => params[:request][:destination_url]
      respond_with :location => aspect
Raphael's avatar
Raphael a validé
      return
      flash[:notice] =  I18n.t 'requests.create.success',:destination_url => @request.destination_url
      respond_with :location => aspect
      flash[:error] = I18n.t 'requests.create.horribly_wrong'
      respond_with :location => aspect