Skip to content
Extraits de code Groupes Projets
requests_controller.rb 1,85 ko
Newer Older
class RequestsController < ApplicationController
  before_filter :authenticate_user!
  include RequestsHelper 

  respond_to :html
  respond_to :json, :only => :index

    @remote_requests = Request.for_user current_user
    @request         = Request.new

    respond_with @remote_requests
      if params[:group_id]
        @friend = current_user.accept_and_respond( params[:id], params[:group_id])
        flash[:notice] = "you are now friends"
        respond_with :location => current_user.group_by_id(params[:group_id])
      else
        flash[:error] = "please select a group!"
        respond_with :location => requests_url
Raphael's avatar
Raphael a validé
      end
    else
      current_user.ignore_friend_request params[:id]
      respond_with :location => requests_url, :notice => "Ignored friend request."
    group = current_user.group_by_id(params[:request][:group_id])

    begin 
      rel_hash = relationship_flow(params[:request][:destination_url])
    rescue Exception => e
      respond_with :location => group, :error => "No diaspora seed found with this email!" 
    Rails.logger.debug("Sending request: #{rel_hash}")
      @request = current_user.send_friend_request_to(rel_hash[:friend], group)
    rescue Exception => e
      raise e unless e.message.include? "already friends"
      message = "You are already friends with #{params[:request][:destination_url]}!"
      respond_with :location => group, :notice => message
Raphael's avatar
Raphael a validé
      return
      message = "A friend request was sent to #{@request.destination_url}."
      respond_with :location => group, :notice => message
      message = "Something went horribly wrong."
      respond_with :location => group, :error => message