Class: Socializer::SharesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/socializer/shares_controller.rb', line 10

def create
  # scope = params[:share][:scope]
  object_ids = params[:share][:object_ids]

  activity = Activity.new do |a|
    a.actor_id           = current_user.guid
    a.activity_object_id = params[:share][:activity_id]
    a.verb               = Verb.find_or_create_by(name: 'share')
  end

  activity.build_activity_field(content: params[:share][:content]) if params[:share][:content]

  public  = Socializer::Audience.privacy_level.find_value(:public).value.to_s
  circles = Socializer::Audience.privacy_level.find_value(:circles).value.to_s

  object_ids.split(',').each do |object_id|
    # REFACTOR: remove duplication
    if object_id == public || object_id == circles
      activity.audiences.build(privacy_level: object_id)
    else
      activity.audiences.build do |a|
        a.privacy_level = :limited
        a.activity_object_id = object_id
      end
    end
  end

  activity.save!

  redirect_to stream_path
end

#newObject

before_action :set_share, only: [:show, :edit, :update, :destroy]



5
6
7
8
# File 'app/controllers/socializer/shares_controller.rb', line 5

def new
  @activity_object = ActivityObject.find(params[:id])
  @share = @activity_object.activitable
end