diff options
author | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-03-09 00:17:17 +0000 |
---|---|---|
committer | Jenkins <jenkins@jenkins.ninjawedding.org> | 2018-03-09 00:17:17 +0000 |
commit | 447d7e612753d69f043e08ebb228b21e411c8b4a (patch) | |
tree | 80caebcff2b131898f620f89ad0858d44530d30f /app/lib | |
parent | 43a9a781a443a6b9296431fbcc4285b3ca6a1a57 (diff) | |
parent | ff44b2e92d496c6027b20157fea6ebd885906bea (diff) |
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activitypub/activity.rb | 4 | ||||
-rw-r--r-- | app/lib/activitypub/activity/add.rb | 13 | ||||
-rw-r--r-- | app/lib/activitypub/activity/create.rb | 15 | ||||
-rw-r--r-- | app/lib/activitypub/activity/remove.rb | 14 | ||||
-rw-r--r-- | app/lib/activitypub/adapter.rb | 1 | ||||
-rw-r--r-- | app/lib/formatter.rb | 2 | ||||
-rw-r--r-- | app/lib/ostatus/activity/creation.rb | 13 |
7 files changed, 41 insertions, 21 deletions
diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb index 6f4a3b491..9b00f0f52 100644 --- a/app/lib/activitypub/activity.rb +++ b/app/lib/activitypub/activity.rb @@ -46,6 +46,10 @@ class ActivityPub::Activity ActivityPub::Activity::Reject when 'Flag' ActivityPub::Activity::Flag + when 'Add' + ActivityPub::Activity::Add + when 'Remove' + ActivityPub::Activity::Remove end end end diff --git a/app/lib/activitypub/activity/add.rb b/app/lib/activitypub/activity/add.rb new file mode 100644 index 000000000..ea94d2f98 --- /dev/null +++ b/app/lib/activitypub/activity/add.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ActivityPub::Activity::Add < ActivityPub::Activity + def perform + return unless @json['target'].present? && value_or_id(@json['target']) == @account.featured_collection_url + + status = status_from_uri(object_uri) + + return unless status.account_id == @account.id && !@account.pinned?(status) + + StatusPin.create!(account: @account, status: status) + end +end diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index a7afbb859..5a1c13d67 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -20,13 +20,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity private def process_status - media_attachments = process_attachments + status_params = process_status_params ApplicationRecord.transaction do @status = Status.create!(status_params) process_tags(@status) - attach_media(@status, media_attachments) end resolve_thread(@status) @@ -40,7 +39,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity status end - def status_params + def process_status_params { uri: @object['id'], url: object_url || @object['id'], @@ -54,6 +53,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity visibility: visibility_from_audience, thread: replied_to_status, conversation: conversation_from_uri(@object['conversation']), + media_attachments: process_attachments.take(4), } end @@ -108,7 +108,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity end def process_attachments - return if @object['attachment'].nil? + return [] if @object['attachment'].nil? media_attachments = [] @@ -132,13 +132,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity media_attachments end - def attach_media(status, media_attachments) - return if media_attachments.blank? - - media = MediaAttachment.where(status_id: nil, id: media_attachments.take(4).map(&:id)) - media.update(status_id: status.id) - end - def resolve_thread(status) return unless status.reply? && status.thread.nil? ThreadResolveWorker.perform_async(status.id, in_reply_to_uri) diff --git a/app/lib/activitypub/activity/remove.rb b/app/lib/activitypub/activity/remove.rb new file mode 100644 index 000000000..62a1e3196 --- /dev/null +++ b/app/lib/activitypub/activity/remove.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class ActivityPub::Activity::Remove < ActivityPub::Activity + def perform + return unless @json['target'].present? && value_or_id(@json['target']) == @account.featured_collection_url + + status = status_from_uri(object_uri) + + return unless status.account_id == @account.id + + pin = StatusPin.find_by(account: @account, status: status) + pin&.destroy! + end +end diff --git a/app/lib/activitypub/adapter.rb b/app/lib/activitypub/adapter.rb index 8198ac580..f19b04ae6 100644 --- a/app/lib/activitypub/adapter.rb +++ b/app/lib/activitypub/adapter.rb @@ -18,6 +18,7 @@ class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base 'toot' => 'http://joinmastodon.org/ns#', 'Emoji' => 'toot:Emoji', 'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' }, + 'featured' => 'toot:featured', }, ], }.freeze diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 8c0f8cebc..1df4ff8d4 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -19,6 +19,8 @@ class Formatter raw_content = status.text + return '' if raw_content.blank? + unless status.local? html = reformat(raw_content) html = encode_custom_emojis(html, status.emojis) if options[:custom_emojify] diff --git a/app/lib/ostatus/activity/creation.rb b/app/lib/ostatus/activity/creation.rb index 7cf2d90dc..aa46267dc 100644 --- a/app/lib/ostatus/activity/creation.rb +++ b/app/lib/ostatus/activity/creation.rb @@ -29,7 +29,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base # Skip if the reblogged status is not public return if cached_reblog && !(cached_reblog.public_visibility? || cached_reblog.unlisted_visibility?) - media_attachments = save_media + media_attachments = save_media.take(4) ApplicationRecord.transaction do status = Status.create!( @@ -44,12 +44,12 @@ class OStatus::Activity::Creation < OStatus::Activity::Base language: content_language, visibility: visibility_scope, conversation: find_or_create_conversation, - thread: thread? ? find_status(thread.first) || find_activitypub_status(thread.first, thread.second) : nil + thread: thread? ? find_status(thread.first) || find_activitypub_status(thread.first, thread.second) : nil, + media_attachments: media_attachments ) save_mentions(status) save_hashtags(status) - attach_media(status, media_attachments) save_emojis(status) end @@ -159,13 +159,6 @@ class OStatus::Activity::Creation < OStatus::Activity::Base media_attachments end - def attach_media(parent, media_attachments) - return if media_attachments.blank? - - media = MediaAttachment.where(status_id: nil, id: media_attachments.take(4).map(&:id)) - media.update(status_id: parent.id) - end - def save_emojis(parent) do_not_download = DomainBlock.find_by(domain: parent.account.domain)&.reject_media? |