diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index b413be07..080b7c2a 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -74,9 +74,10 @@ class UserController < ApplicationController def followers @title = 'Followers' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! - @users = @user.cursored_followers(last_id: params[:last_id]) - @users_last_id = @users.map(&:id).min - @more_data_available = !@user.cursored_followers(last_id: @users_last_id, size: 1).count.zero? + @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 respond_to do |format| @@ -89,9 +90,10 @@ class UserController < ApplicationController def followings @title = 'Following' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! - @users = @user.cursored_followings(last_id: params[:last_id]) - @users_last_id = @users.map(&:id).min - @more_data_available = !@user.cursored_followings(last_id: @users_last_id, size: 1).count.zero? + @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 respond_to do |format| diff --git a/app/models/user/relationship_methods.rb b/app/models/user/relationship_methods.rb index 1392a331..efddb747 100644 --- a/app/models/user/relationship_methods.rb +++ b/app/models/user/relationship_methods.rb @@ -5,6 +5,8 @@ module User::RelationshipMethods define_cursor_paginator :cursored_followings, :ordered_followings define_cursor_paginator :cursored_followers, :ordered_followers + define_cursor_paginator :cursored_following_relationships, :ordered_following_relationships + define_cursor_paginator :cursored_follower_relationships, :ordered_follower_relationships def ordered_followings followings.reverse_order.includes(:profile) @@ -13,4 +15,12 @@ module User::RelationshipMethods def ordered_followers followers.reverse_order.includes(:profile) end + + def ordered_following_relationships + active_follow_relationships.reverse_order.includes(target: [:profile]) + end + + def ordered_follower_relationships + passive_follow_relationships.reverse_order.includes(source: [:profile]) + end end diff --git a/app/views/user/show_follow.haml b/app/views/user/show_follow.haml index 1d27a2df..6a1f443d 100644 --- a/app/views/user/show_follow.haml +++ b/app/views/user/show_follow.haml @@ -3,11 +3,11 @@ .col.pb-3 = render 'shared/userbox', user: user, type: @type -= render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @users_last_id += render 'shared/cursored_pagination_dummy', more_data_available: @more_data_available, last_id: @relationships_last_id - if @more_data_available .d-flex.justify-content-center.justify-content-sm-start - %button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @users_last_id } } + %button.btn.btn-light#load-more-btn{ type: :button, data: { last_id: @relationships_last_id } } = t 'views.actions.load' - provide(:title, user_title(@user, 'friends and followers')) diff --git a/app/views/user/show_follow.js.erb b/app/views/user/show_follow.js.erb index 87845c36..c164badb 100644 --- a/app/views/user/show_follow.js.erb +++ b/app/views/user/show_follow.js.erb @@ -2,7 +2,7 @@ $('#users').append('<% @users.each do |user| %>