streams_controller.rb 1.72 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class StreamsController < ApplicationController
8 9
  before_action :authenticate_user!
  before_action :save_selected_aspects, :only => :aspects
10

11 12
  layout proc { request.format == :mobile ? "application" : "with_header" }

13 14 15 16 17
  respond_to :html,
             :mobile,
             :json

  def aspects
18
    aspect_ids = (session[:a_ids] || [])
19 20 21 22 23 24 25 26 27
    @stream = Stream::Aspect.new(current_user, aspect_ids,
                                 :max_time => max_time)
    stream_responder
  end

  def public
    stream_responder(Stream::Public)
  end

28 29
  def activity
    stream_responder(Stream::Activity)
danielgrippi's avatar
danielgrippi committed
30 31
  end

32
  def multi
33 34
    gon.preloads[:getting_started] = current_user.getting_started
    stream_responder(Stream::Multi)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  end

  def commented
    stream_responder(Stream::Comments)
  end

  def liked
    stream_responder(Stream::Likes)
  end

  def mentioned
    stream_responder(Stream::Mention)
  end

  def followed_tags
50
    gon.preloads[:tagFollowings] = tags
51 52 53 54 55 56
    stream_responder(Stream::FollowedTag)
  end

  private

  def stream_responder(stream_klass=nil)
57

58 59 60 61 62
    if stream_klass.present?
      @stream ||= stream_klass.new(current_user, :max_time => max_time)
    end

    respond_with do |format|
63 64
      format.html { render 'streams/main_stream' }
      format.mobile { render 'streams/main_stream' }
65
      format.json { render :json => @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) }}
66 67 68 69 70 71 72 73 74
    end
  end

  def save_selected_aspects
    if params[:a_ids].present?
      session[:a_ids] = params[:a_ids]
    end
  end
end