Browse Source

If an OStatus message contains nsfw hashtag, mark it as sensitive (#7398)

* If an OStatus message contains nsfw hashtag, mark it as sensitive

Undo parts of #7048

* Put nsfw hashtag on OStatus messages if they have any media

* Fix code style issues
closed-social-v3
Eugen Rochko 6 years ago
committed by GitHub
parent
commit
6208ea5a53
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions
  1. +7
    -1
      app/lib/ostatus/activity/creation.rb
  2. +1
    -0
      app/lib/ostatus/atom_serializer.rb

+ 7
- 1
app/lib/ostatus/activity/creation.rb View File

@ -46,7 +46,8 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
visibility: visibility_scope,
conversation: find_or_create_conversation,
thread: thread? ? find_status(thread.first) || find_activitypub_status(thread.first, thread.second) : nil,
media_attachment_ids: media_attachments.map(&:id)
media_attachment_ids: media_attachments.map(&:id),
sensitive: sensitive?
)
save_mentions(status)
@ -105,6 +106,11 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
private
def sensitive?
# OStatus-specific convention (not standard)
@xml.xpath('./xmlns:category', xmlns: OStatus::TagManager::XMLNS).any? { |category| category['term'] == 'nsfw' }
end
def find_or_create_conversation
uri = @xml.at_xpath('./ostatus:conversation', ostatus: OStatus::TagManager::OS_XMLNS)&.attribute('ref')&.content
return if uri.nil?

+ 1
- 0
app/lib/ostatus/atom_serializer.rb View File

@ -368,6 +368,7 @@ class OStatus::AtomSerializer
append_element(entry, 'link', nil, rel: :enclosure, type: media.file_content_type, length: media.file_file_size, href: full_asset_url(media.file.url(:original, false)))
end
append_element(entry, 'category', nil, term: 'nsfw') if status.sensitive? && status.media_attachments.any?
append_element(entry, 'mastodon:scope', status.visibility)
status.emojis.each do |emoji|

Loading…
Cancel
Save