Add interrelationship filter

This commit is contained in:
noellabo 2020-11-12 18:37:54 +09:00
parent 5ea43e505b
commit c59ca999a6
6 changed files with 44 additions and 4 deletions

View file

@ -42,7 +42,11 @@ class RelationshipsController < ApplicationController
end
def mutual_relationship?
params[:relationship] == 'mutual'
params[:interrelationship] == 'mutual'
end
def one_way_relationship?
params[:interrelationship] == 'one_way'
end
def followed_by_relationship?

View file

@ -385,6 +385,7 @@ body,
.filters {
display: flex;
flex-wrap: wrap;
margin-right: -40px;
.filter-subset {
flex: 0 0 auto;

View file

@ -346,6 +346,11 @@ body.rtl {
text-align: right;
}
.filter {
margin-right: 0;
margin-left: -45px;
}
.filters .filter-subset {
margin-right: 0;
margin-left: 45px;

View file

@ -3,6 +3,7 @@
class RelationshipFilter
KEYS = %i(
relationship
interrelationship
status
by_domain
activity
@ -42,6 +43,8 @@ class RelationshipFilter
case key
when 'relationship'
relationship_scope(value)
when 'interrelationship'
by_interrelationship_scope(value)
when 'by_domain'
by_domain_scope(value)
when 'location'
@ -63,8 +66,6 @@ class RelationshipFilter
account.following.eager_load(:account_stat).reorder(nil)
when 'followed_by'
account.followers.eager_load(:account_stat).reorder(nil)
when 'mutual'
account.followers.eager_load(:account_stat).reorder(nil).merge(Account.where(id: account.following))
when 'invited'
Account.joins(user: :invite).merge(Invite.where(user: account.user)).eager_load(:account_stat).reorder(nil)
else
@ -72,6 +73,27 @@ class RelationshipFilter
end
end
def by_interrelationship_scope(value)
case value
when 'mutual'
case params[:relationship]
when 'following'
Account.where(id: account.followers)
when 'followed_by'
Account.where(id: account.following)
end
when 'one_way'
case params[:relationship]
when 'following'
Account.where.not(id: account.followers)
when 'followed_by'
Account.where.not(id: account.following)
end
else
raise "Unknown interrelationship: #{value}"
end
end
def by_domain_scope(value)
Account.where(domain: value)
end

View file

@ -10,7 +10,13 @@
%ul
%li= filter_link_to t('relationships.following'), relationship: nil
%li= filter_link_to t('relationships.followers'), relationship: 'followed_by'
%li= filter_link_to t('relationships.mutual'), relationship: 'mutual'
.filter-subset
%strong= t 'relationships.interrelationship'
%ul
%li= filter_link_to t('generic.all'), interrelationship: nil
%li= filter_link_to t('relationships.mutual'), interrelationship: 'mutual'
%li= filter_link_to t('relationships.one_way'), interrelationship: 'one_way'
.filter-subset
%strong= t 'relationships.status'

View file

@ -1236,11 +1236,13 @@ en:
follow_selected_followers: Follow selected followers
followers: Followers
following: Following
interrelationship: Interrelationship
invited: Invited
last_active: Last active
most_recent: Most recent
moved: Moved
mutual: Mutual
one_way: One-way
primary: Primary
relationship: Relationship
remove_selected_domains: Remove all followers from the selected domains