Class: StatusMessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/status_messages_controller.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Method Summary collapse

Instance Method Details

#bookmarkletObject


42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/status_messages_controller.rb', line 42

def bookmarklet
  @aspects = current_user.aspects
  @aspect_ids = @aspects.map{|x| x.id}

  gon.preloads[:bookmarklet] = {
    content: params[:content],
    title: params[:title],
    url: params[:url],
    notes: params[:notes]
  }
end

#createObject


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/status_messages_controller.rb', line 54

def create
  params[:status_message][:aspect_ids] = [*params[:aspect_ids]]
  normalize_public_flag!
  services = [*params[:services]].compact

  @status_message = current_user.build_post(:status_message, params[:status_message])
  @status_message.build_location(:address => params[:location_address], :coordinates => params[:location_coords]) if params[:location_address].present?
  if params[:poll_question].present?
    @status_message.build_poll(:question => params[:poll_question])
    [*params[:poll_answers]].each do |poll_answer|
      @status_message.poll.poll_answers.build(:answer => poll_answer)
    end
  end


  @status_message.attach_photos_by_ids(params[:photos])

  if @status_message.save
    aspects = current_user.aspects_from_ids(destination_aspect_ids)
    current_user.add_to_streams(@status_message, aspects)
    receiving_services = Service.titles(services)

    current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :service_types => receiving_services)

    #this is done implicitly, somewhere else, but it doesnt work, says max. :'(
    @status_message.photos.each do |photo|
      current_user.dispatch_post(photo)
    end

    current_user.participate!(@status_message)

    if coming_from_profile_page? && !own_profile_page? # if this is a post coming from a profile page
      flash[:notice] = successful_mention_message
    end

    respond_to do |format|
      format.html { redirect_to :back }
      format.mobile { redirect_to stream_path }
      format.json { render :json => PostPresenter.new(@status_message, current_user), :status => 201 }
    end
  else
    respond_to do |format|
      format.html { redirect_to :back }
      format.mobile { redirect_to stream_path }
      format.json { render :nothing => true, :status => 403 }
    end
  end
end

#newObject

Called when a user clicks “Mention” on a profile page


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/status_messages_controller.rb', line 20

def new
  if params[:person_id] && @person = Person.where(:id => params[:person_id]).first
    @aspect = :profile
    @contact = current_user.contact_for(@person)
    @aspects_with_person = []
    if @contact
      @aspects_with_person = @contact.aspects
      @aspect_ids = @aspects_with_person.map{|x| x.id}
      gon.aspect_ids = @aspect_ids
      @contacts_of_contact = @contact.contacts
      render :layout => nil
    end
  elsif(request.format == :mobile)
    @aspect = :all
    @aspects = current_user.aspects
    @aspect_ids = @aspects.map{ |a| a.id }
    gon.aspect_ids = @aspect_ids
  else
    redirect_to stream_path
  end
end