]> cat aescling's git repositories - mastodon.git/commitdiff
Fix PeerTube videos appearing with an erroneous “Edited at” marker (#18100)
authorClaire <claire.github-309c@sitedethib.com>
Tue, 26 Apr 2022 19:25:26 +0000 (21:25 +0200)
committersingle-right-quote <11325618-aescling@users.noreply.gitlab.com>
Thu, 5 May 2022 03:56:01 +0000 (23:56 -0400)
* 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
spec/lib/activitypub/activity/create_spec.rb

index 1ac509f1841c16903e6b4f93af94ca443d675a53..09fe08d45fcba4c50dc35749d5158a8719688eff 100644 (file)
@@ -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,
index 3e9cbba923a5fa18a6ebeab0c1e615206d512178..738e644c5468326cf63b6234ea62dd9ed747c04b 100644 (file)
@@ -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
           {