diff options
author | ThibG <thib@sitedethib.com> | 2019-01-20 13:56:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-20 13:56:37 +0100 |
commit | aa362ab73dc7121104b3c01800152b9fc56ea396 (patch) | |
tree | f0f5879a51325856887a2e32a4c3f9654af61aab /app/lib | |
parent | 530d29148ca0c5bf29f6fa516b1ef4f91d95894b (diff) | |
parent | 5145c81620efbd5cf8dc911858d17d1fa888c996 (diff) |
Merge pull request #888 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activitypub/activity/announce.rb | 14 | ||||
-rw-r--r-- | app/lib/activitypub/activity/create.rb | 9 | ||||
-rw-r--r-- | app/lib/activitypub/activity/delete.rb | 20 |
3 files changed, 37 insertions, 6 deletions
diff --git a/app/lib/activitypub/activity/announce.rb b/app/lib/activitypub/activity/announce.rb index 1147a4481..34d1b7cbd 100644 --- a/app/lib/activitypub/activity/announce.rb +++ b/app/lib/activitypub/activity/announce.rb @@ -17,7 +17,7 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity uri: @json['id'], created_at: @json['published'], override_timestamps: @options[:override_timestamps], - visibility: original_status.visibility + visibility: visibility_from_audience ) distribute(status) @@ -26,6 +26,18 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity private + def visibility_from_audience + if equals_or_includes?(@json['to'], ActivityPub::TagManager::COLLECTIONS[:public]) + :public + elsif equals_or_includes?(@json['cc'], ActivityPub::TagManager::COLLECTIONS[:public]) + :unlisted + elsif equals_or_includes?(@json['to'], @account.followers_url) + :private + else + :direct + end + end + def announceable?(status) status.account_id == @account.id || status.public_visibility? || status.unlisted_visibility? end diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 2b238bc88..b49657d4b 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -5,10 +5,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity CONVERTED_TYPES = %w(Image Video Article Page).freeze def perform - return if delete_arrived_first?(object_uri) || unsupported_object_type? || invalid_origin?(@object['id']) + return if unsupported_object_type? || invalid_origin?(@object['id']) + return if Tombstone.exists?(uri: @object['id']) RedisLock.acquire(lock_options) do |lock| if lock.acquired? + return if delete_arrived_first?(object_uri) + @status = find_existing_status if @status.nil? @@ -59,7 +62,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity account: @account, text: text_from_content || '', language: detected_language, - spoiler_text: text_from_summary || '', + spoiler_text: converted_object_type? ? '' : (text_from_summary || ''), created_at: @object['published'], override_timestamps: @options[:override_timestamps], reply: @object['inReplyTo'].present?, @@ -254,7 +257,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity end def text_from_content - return Formatter.instance.linkify([text_from_name, object_url || @object['id']].join(' ')) if converted_object_type? + return Formatter.instance.linkify([[text_from_name, text_from_summary.presence].compact.join("\n\n"), object_url || @object['id']].join(' ')) if converted_object_type? if @object['content'].present? @object['content'] diff --git a/app/lib/activitypub/activity/delete.rb b/app/lib/activitypub/activity/delete.rb index 8270fed1b..dc76dd3e2 100644 --- a/app/lib/activitypub/activity/delete.rb +++ b/app/lib/activitypub/activity/delete.rb @@ -21,11 +21,14 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity def delete_note return if object_uri.nil? + unless invalid_origin?(object_uri) + RedisLock.acquire(lock_options) { |_lock| delete_later!(object_uri) } + Tombstone.find_or_create_by(uri: object_uri, account: @account) + end + @status = Status.find_by(uri: object_uri, account: @account) @status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present? - delete_later!(object_uri) - return if @status.nil? if @status.public_visibility? || @status.unlisted_visibility? @@ -68,4 +71,17 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity def payload @payload ||= Oj.dump(@json) end + + def lock_options + { redis: Redis.current, key: "create:#{object_uri}" } + end + + def invalid_origin?(url) + return true if unsupported_uri_scheme?(url) + + needle = Addressable::URI.parse(url).host + haystack = Addressable::URI.parse(@account.uri).host + + !haystack.casecmp(needle).zero? + end end |