From 368c9631d2126aa52693f018fce05eb6a055851a Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 26 Apr 2022 21:25:26 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20PeerTube=20videos=20appearing=20with=20an?= =?UTF-8?q?=20erroneous=20=E2=80=9CEdited=20at=E2=80=9D=20marker=20(#18100?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix PeerTube videos appearing with an erroneous “Edited at” marker PeerTube videos have an `updated` field equal to `published`. When processing an incoming activity that has the same value for `updated` and `published`, assume this doesn't represent an actual edit. * Please CodeClimate --- app/lib/activitypub/activity/create.rb | 2 +- spec/lib/activitypub/activity/create_spec.rb | 52 ++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index f4f98e29ce..1f32d8cce8 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -117,7 +117,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity language: @status_parser.language, spoiler_text: converted_object_type? ? '' : (@status_parser.spoiler_text || ''), created_at: @status_parser.created_at, - edited_at: @status_parser.edited_at, + edited_at: @status_parser.edited_at && @status_parser.edited_at != @status_parser.created_at ? @status_parser.edited_at : nil, override_timestamps: @options[:override_timestamps], reply: @status_parser.reply, sensitive: @account.sensitized? || @status_parser.sensitive || false, diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index 2703c18f39..1a25395fad 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -29,6 +29,58 @@ RSpec.describe ActivityPub::Activity::Create do subject.perform end + context 'object has been edited' do + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + published: '2022-01-22T15:00:00Z', + updated: '2022-01-22T16:00:00Z', + } + end + + it 'creates status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.text).to eq 'Lorem ipsum' + end + + it 'marks status as edited' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.edited?).to eq true + end + end + + context 'object has update date equal to creation date' do + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + published: '2022-01-22T15:00:00Z', + updated: '2022-01-22T15:00:00Z', + } + end + + it 'creates status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.text).to eq 'Lorem ipsum' + end + + it 'does not mark status as edited' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.edited?).to eq false + end + end + context 'unknown object type' do let(:object_json) do {