Retrospring/app/controllers/user_controller.rb

72 lines
2.6 KiB
Ruby
Raw Normal View History

2014-11-02 08:57:37 -08:00
class UserController < ApplicationController
before_action :authenticate_user!, only: %w[data]
2014-12-29 02:21:43 -08:00
2014-11-02 08:57:37 -08:00
def show
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@answers = @user.cursored_answers(last_id: params[:last_id])
@answers_last_id = @answers.map(&:id).min
@more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero?
if user_signed_in?
2021-12-31 13:19:21 -08:00
notif = Notification.where(target_type: "Relationship", target_id: @user.active_follow_relationships.where(target_id: current_user.id).pluck(:id), recipient_id: current_user.id, new: true).first
unless notif.nil?
notif.new = false
notif.save
end
end
2014-12-08 06:23:04 -08:00
respond_to do |format|
format.html
2020-05-08 19:39:09 -07:00
format.js { render layout: false }
2014-12-08 06:23:04 -08:00
end
2014-11-02 08:57:37 -08:00
end
2014-12-08 08:03:06 -08:00
def followers
@title = 'Followers'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@relationships = @user.cursored_follower_relationships(last_id: params[:last_id])
@relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_follower_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@users = @relationships.map(&:source)
@type = :friend
2020-05-08 19:39:09 -07:00
respond_to do |format|
format.html { render "show_follow" }
format.js { render "show_follow", layout: false }
end
2014-12-08 08:03:06 -08:00
end
2022-01-16 09:51:27 -08:00
# rubocop:disable Metrics/AbcSize
2021-12-31 13:19:21 -08:00
def followings
2014-12-08 08:03:06 -08:00
@title = 'Following'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@relationships = @user.cursored_following_relationships(last_id: params[:last_id])
@relationships_last_id = @relationships.map(&:id).min
@more_data_available = !@user.cursored_following_relationships(last_id: @relationships_last_id, size: 1).count.zero?
@users = @relationships.map(&:target)
@type = :friend
2020-05-08 19:39:09 -07:00
respond_to do |format|
format.html { render "show_follow" }
format.js { render "show_follow", layout: false }
end
2014-12-08 08:03:06 -08:00
end
2022-01-16 09:51:27 -08:00
# rubocop:enable Metrics/AbcSize
2014-12-19 13:34:24 -08:00
def questions
@title = 'Questions'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
2020-04-22 18:31:07 -07:00
@questions = @user.cursored_questions(author_is_anonymous: false, last_id: params[:last_id])
@questions_last_id = @questions.map(&:id).min
2020-04-22 18:31:07 -07:00
@more_data_available = !@user.cursored_questions(author_is_anonymous: false, last_id: @questions_last_id, size: 1).count.zero?
2020-05-08 19:39:09 -07:00
respond_to do |format|
format.html
format.js { render layout: false }
end
2014-12-19 13:34:24 -08:00
end
2015-06-20 11:38:07 -07:00
def data
end
2014-11-02 08:57:37 -08:00
end