streams_controller.rb 1.91 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
  before_action :authenticate_user!, except: :public
9
  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 35 36 37 38
    if current_user.getting_started
      gon.preloads[:getting_started] = true
      inviter = current_user.invited_by.try(:person)
      gon.preloads[:mentioned_person] = {name: inviter.name, handle: inviter.diaspora_handle} if inviter
    end

39
    stream_responder(Stream::Multi)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  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
55
    gon.preloads[:tagFollowings] = tags
56 57 58 59 60 61
    stream_responder(Stream::FollowedTag)
  end

  private

  def stream_responder(stream_klass=nil)
62

63 64 65 66 67
    if stream_klass.present?
      @stream ||= stream_klass.new(current_user, :max_time => max_time)
    end

    respond_with do |format|
68 69
      format.html { render 'streams/main_stream' }
      format.mobile { render 'streams/main_stream' }
70
      format.json { render :json => @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user)) }}
71 72 73 74 75 76 77 78 79
    end
  end

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