Skip to content

Commit 9745de8

Browse files
authored
Add blocked_by relationship to the REST API (mastodon#10373)
1 parent e6cfa7a commit 9745de8

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

app/presenters/account_relationships_presenter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class AccountRelationshipsPresenter
4-
attr_reader :following, :followed_by, :blocking,
4+
attr_reader :following, :followed_by, :blocking, :blocked_by,
55
:muting, :requested, :domain_blocking,
66
:endorsed
77

@@ -12,6 +12,7 @@ def initialize(account_ids, current_account_id, **options)
1212
@following = cached[:following].merge(Account.following_map(@uncached_account_ids, @current_account_id))
1313
@followed_by = cached[:followed_by].merge(Account.followed_by_map(@uncached_account_ids, @current_account_id))
1414
@blocking = cached[:blocking].merge(Account.blocking_map(@uncached_account_ids, @current_account_id))
15+
@blocked_by = cached[:blocked_by].merge(Account.blocked_by_map(@uncached_account_ids, @current_account_id))
1516
@muting = cached[:muting].merge(Account.muting_map(@uncached_account_ids, @current_account_id))
1617
@requested = cached[:requested].merge(Account.requested_map(@uncached_account_ids, @current_account_id))
1718
@domain_blocking = cached[:domain_blocking].merge(Account.domain_blocking_map(@uncached_account_ids, @current_account_id))
@@ -22,6 +23,7 @@ def initialize(account_ids, current_account_id, **options)
2223
@following.merge!(options[:following_map] || {})
2324
@followed_by.merge!(options[:followed_by_map] || {})
2425
@blocking.merge!(options[:blocking_map] || {})
26+
@blocked_by.merge!(options[:blocked_by_map] || {})
2527
@muting.merge!(options[:muting_map] || {})
2628
@requested.merge!(options[:requested_map] || {})
2729
@domain_blocking.merge!(options[:domain_blocking_map] || {})
@@ -37,6 +39,7 @@ def cached
3739
following: {},
3840
followed_by: {},
3941
blocking: {},
42+
blocked_by: {},
4043
muting: {},
4144
requested: {},
4245
domain_blocking: {},
@@ -64,6 +67,7 @@ def cache_uncached!
6467
following: { account_id => following[account_id] },
6568
followed_by: { account_id => followed_by[account_id] },
6669
blocking: { account_id => blocking[account_id] },
70+
blocked_by: { account_id => blocked_by[account_id] },
6771
muting: { account_id => muting[account_id] },
6872
requested: { account_id => requested[account_id] },
6973
domain_blocking: { account_id => domain_blocking[account_id] },

app/serializers/rest/relationship_serializer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class REST::RelationshipSerializer < ActiveModel::Serializer
4-
attributes :id, :following, :showing_reblogs, :followed_by, :blocking,
4+
attributes :id, :following, :showing_reblogs, :followed_by, :blocking, :blocked_by,
55
:muting, :muting_notifications, :requested, :domain_blocking,
66
:endorsed
77

@@ -27,6 +27,10 @@ def blocking
2727
instance_options[:relationships].blocking[object.id] || false
2828
end
2929

30+
def blocked_by
31+
instance_options[:relationships].blocked_by[object.id] || false
32+
end
33+
3034
def muting
3135
instance_options[:relationships].muting[object.id] ? true : false
3236
end

0 commit comments

Comments
 (0)