Mentions in private statuses allow mentioned people to see them

signup-info-prompt
Eugen Rochko 2017-02-11 15:10:22 +01:00
parent 00b5731ecb
commit dc851c922e
4 changed files with 16 additions and 15 deletions

View File

@ -107,7 +107,6 @@ class FeedManager
should_filter ||= receiver.blocking?(status.account) # or it's from someone I blocked should_filter ||= receiver.blocking?(status.account) # or it's from someone I blocked
should_filter ||= receiver.blocking?(status.mentions.includes(:account).map(&:account)) # or if it mentions someone I blocked should_filter ||= receiver.blocking?(status.mentions.includes(:account).map(&:account)) # or if it mentions someone I blocked
should_filter ||= (status.account.silenced? && !receiver.following?(status.account)) # of if the account is silenced and I'm not following them should_filter ||= (status.account.silenced? && !receiver.following?(status.account)) # of if the account is silenced and I'm not following them
should_filter ||= (status.private_visibility? && !receiver.following?(status.account)) # or if the mentioned account is not permitted to see the private status
if status.reply? && !status.in_reply_to_account_id.nil? # or it's a reply if status.reply? && !status.in_reply_to_account_id.nil? # or it's a reply
should_filter ||= receiver.blocking?(status.in_reply_to_account) # to a user I blocked should_filter ||= receiver.blocking?(status.in_reply_to_account) # to a user I blocked

View File

@ -76,7 +76,11 @@ class Status < ApplicationRecord
end end
def permitted?(other_account = nil) def permitted?(other_account = nil)
private_visibility? ? (account.id == other_account&.id || other_account&.following?(account)) : other_account.nil? || !account.blocking?(other_account) if private_visibility?
(account.id == other_account&.id || other_account&.following?(account) || mentions.include?(other_account))
else
other_account.nil? || !account.blocking?(other_account)
end
end end
def ancestors(account = nil) def ancestors(account = nil)
@ -153,6 +157,10 @@ class Status < ApplicationRecord
where('1 = 1') where('1 = 1')
elsif !account.nil? && target_account.blocking?(account) elsif !account.nil? && target_account.blocking?(account)
where('1 = 0') where('1 = 0')
elsif !account.nil?
joins('LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id')
.where('mentions.account_id = ?', account.id)
.where('statuses.visibility != ? OR mentions.id IS NOT NULL', Status.visibilities[:private])
else else
where.not(visibility: :private) where.not(visibility: :private)
end end

View File

@ -106,7 +106,8 @@ class ProcessFeedService < BaseService
text: content(entry), text: content(entry),
spoiler_text: content_warning(entry), spoiler_text: content_warning(entry),
created_at: published(entry), created_at: published(entry),
reply: thread?(entry) reply: thread?(entry),
visibility: visibility_scope(entry)
) )
if thread?(entry) if thread?(entry)
@ -144,15 +145,9 @@ class ProcessFeedService < BaseService
def mentions_from_xml(parent, xml) def mentions_from_xml(parent, xml)
processed_account_ids = [] processed_account_ids = []
public_visibility = false
xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each do |link| xml.xpath('./xmlns:link[@rel="mentioned"]', xmlns: TagManager::XMLNS).each do |link|
if link['ostatus:object-type'] == TagManager::TYPES[:collection] && link['href'] == TagManager::COLLECTIONS[:public] next if [TagManager::TYPES[:group], TagManager::TYPES[:collection]].include? link['ostatus:object-type']
public_visibility = true
next
elsif link['ostatus:object-type'] == TagManager::TYPES[:group]
next
end
url = Addressable::URI.parse(link['href']) url = Addressable::URI.parse(link['href'])
@ -172,9 +167,6 @@ class ProcessFeedService < BaseService
# So we can skip duplicate mentions # So we can skip duplicate mentions
processed_account_ids << mentioned_account.id processed_account_ids << mentioned_account.id
end end
parent.visibility = public_visibility ? :public : :unlisted
parent.save!
end end
def hashtags_from_xml(parent, xml) def hashtags_from_xml(parent, xml)
@ -230,6 +222,10 @@ class ProcessFeedService < BaseService
xml.at_xpath('./xmlns:summary', xmlns: TagManager::XMLNS)&.content || '' xml.at_xpath('./xmlns:summary', xmlns: TagManager::XMLNS)&.content || ''
end end
def visibility_scope(xml = @xml)
xml.at_xpath('./mastodon:scope', mastodon: TagManager::MTDN_XMLNS)&.content&.to_sym || :public
end
def published(xml = @xml) def published(xml = @xml)
xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content xml.at_xpath('./xmlns:published', xmlns: TagManager::XMLNS).content
end end

View File

@ -30,8 +30,6 @@ class ProcessMentionsService < BaseService
status.mentions.each do |mention| status.mentions.each do |mention|
mentioned_account = mention.account mentioned_account = mention.account
next if status.private_visibility? && (!mentioned_account.following?(status.account) || !mentioned_account.local?)
if mentioned_account.local? if mentioned_account.local?
NotifyService.new.call(mentioned_account, mention) NotifyService.new.call(mentioned_account, mention)
else else