Merge remote-tracking branch 'origin/kb_development' into kb_migration
This commit is contained in:
commit
94cd200097
50 changed files with 801 additions and 66 deletions
|
@ -70,6 +70,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
as_array(@object['cc'] || @json['cc']).map { |x| value_or_id(x) }
|
||||
end
|
||||
|
||||
def audience_searchable_by
|
||||
return nil if @object['searchableBy'].nil?
|
||||
|
||||
@audience_searchable_by = as_array(@object['searchableBy']).map { |x| value_or_id(x) }
|
||||
end
|
||||
|
||||
def process_status
|
||||
@tags = []
|
||||
@mentions = []
|
||||
|
@ -122,6 +128,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
reply: @status_parser.reply,
|
||||
sensitive: @account.sensitized? || @status_parser.sensitive || false,
|
||||
visibility: @status_parser.visibility,
|
||||
searchability: searchability,
|
||||
thread: replied_to_status,
|
||||
conversation: conversation_from_uri(@object['conversation']),
|
||||
media_attachment_ids: process_attachments.take(4).map(&:id),
|
||||
|
@ -429,4 +436,54 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
def join_group!
|
||||
GroupReblogService.new.call(@status)
|
||||
end
|
||||
|
||||
def searchability_from_audience
|
||||
if audience_searchable_by.nil?
|
||||
nil
|
||||
elsif audience_searchable_by.any? { |uri| ActivityPub::TagManager.instance.public_collection?(uri) }
|
||||
:public
|
||||
elsif audience_searchable_by.include?(@account.followers_url)
|
||||
:unlisted # Followers only in kmyblue (generics: private)
|
||||
else
|
||||
:private # Reaction only in kmyblue (generics: direct)
|
||||
end
|
||||
end
|
||||
|
||||
def searchability
|
||||
searchability = searchability_from_audience
|
||||
|
||||
return nil if searchability.nil?
|
||||
|
||||
visibility = visibility_from_audience_with_silence
|
||||
|
||||
if searchability === visibility
|
||||
searchability
|
||||
elsif [:public, :unlisted].include?(searchability) && [:public, :unlisted].include?(visibility) # unlisted is Followers only in kmyblue (generics: private)
|
||||
:unlisted
|
||||
else
|
||||
:private # Reaction only in kmyblue (generics: direct)
|
||||
end
|
||||
end
|
||||
|
||||
def visibility_from_audience
|
||||
if audience_to.any? { |to| ActivityPub::TagManager.instance.public_collection?(to) }
|
||||
:public
|
||||
elsif audience_cc.any? { |cc| ActivityPub::TagManager.instance.public_collection?(cc) }
|
||||
:unlisted
|
||||
elsif audience_to.include?(@account.followers_url)
|
||||
:private
|
||||
else
|
||||
:direct
|
||||
end
|
||||
end
|
||||
|
||||
def visibility_from_audience_with_silence
|
||||
visibility = visibility_from_audience
|
||||
|
||||
if @account.silenced? && %i(public).include?(visibility)
|
||||
:unlisted
|
||||
else
|
||||
visibility
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -185,4 +185,53 @@ class ActivityPub::TagManager
|
|||
rescue ActiveRecord::RecordNotFound
|
||||
nil
|
||||
end
|
||||
|
||||
def searchable_by(status)
|
||||
searchable_by =
|
||||
case status.compute_searchability
|
||||
when 'public'
|
||||
[COLLECTIONS[:public]]
|
||||
when 'unlisted' # Followers only in kmyblue (generics: private)
|
||||
[account_followers_url(status.account)]
|
||||
when 'private' # Reaction only in kmyblue (generics: direct)
|
||||
[]
|
||||
when 'limited'
|
||||
status.conversation_id.present? ? [uri_for(status.conversation)] : []
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
searchable_by.concat(mentions_uris(status))
|
||||
end
|
||||
|
||||
def account_searchable_by(account)
|
||||
case account.searchability
|
||||
when 'public'
|
||||
[COLLECTIONS[:public]]
|
||||
when 'unlisted', 'private'
|
||||
[account_followers_url(account)]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def mentions_uris(status)
|
||||
if status.account.silenced?
|
||||
# Only notify followers if the account is locally silenced
|
||||
account_ids = status.active_mentions.pluck(:account_id)
|
||||
uris = status.account.followers.where(id: account_ids).each_with_object([]) do |account, result|
|
||||
result << uri_for(account)
|
||||
result << account_followers_url(account) if account.group?
|
||||
end
|
||||
uris.concat(FollowRequest.where(target_account_id: status.account_id, account_id: account_ids).each_with_object([]) do |request, result|
|
||||
result << uri_for(request.account)
|
||||
result << account_followers_url(request.account) if request.account.group?
|
||||
end)
|
||||
else
|
||||
status.active_mentions.each_with_object([]) do |mention, result|
|
||||
result << uri_for(mention.account)
|
||||
result << account_followers_url(mention.account) if mention.account.group?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue