From 34ba2505bdd8c6a30c9f8ffaa0a2cbd72ceed11f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 23 Feb 2022 18:25:38 -0500 Subject: [PATCH] normalizeStatus: normalize quote post --- app/soapbox/normalizers/__tests__/status-test.js | 8 ++++++++ app/soapbox/normalizers/status.js | 9 +++++++++ app/soapbox/reducers/statuses.js | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/soapbox/normalizers/__tests__/status-test.js b/app/soapbox/normalizers/__tests__/status-test.js index 654354373..ae9052ccc 100644 --- a/app/soapbox/normalizers/__tests__/status-test.js +++ b/app/soapbox/normalizers/__tests__/status-test.js @@ -71,4 +71,12 @@ describe('normalizeStatus', () => { expect(status.get('media_attachments')).toEqual(result.get('media_attachments')); }); + + it('normalizes Pleroma quote post', () => { + const status = fromJS(require('soapbox/__fixtures__/pleroma-quote-post.json')); + const result = normalizeStatus(status); + + expect(result.get('quote')).toEqual(status.getIn(['pleroma', 'quote'])); + expect(result.getIn(['pleroma', 'quote'])).toBe(undefined); + }); }); diff --git a/app/soapbox/normalizers/status.js b/app/soapbox/normalizers/status.js index 02525ec3b..f6f8fccb3 100644 --- a/app/soapbox/normalizers/status.js +++ b/app/soapbox/normalizers/status.js @@ -73,10 +73,19 @@ const addSelfMention = status => { } }; +// Move the quote to the top-level +const fixQuote = status => { + return status.withMutations(status => { + status.update('quote', quote => quote || status.getIn(['pleroma', 'quote']) || null); + status.deleteIn(['pleroma', 'quote']); + }); +}; + export const normalizeStatus = status => { return status.withMutations(status => { setRequiredFields(status); fixMentions(status); + fixQuote(status); addSelfMention(status); normalizeAttachments(status); }); diff --git a/app/soapbox/reducers/statuses.js b/app/soapbox/reducers/statuses.js index aca48b9c1..d06b0acec 100644 --- a/app/soapbox/reducers/statuses.js +++ b/app/soapbox/reducers/statuses.js @@ -42,7 +42,7 @@ const minifyStatus = status => { account: status.getIn(['account', 'id']), reblog: status.getIn(['reblog', 'id']), poll: status.getIn(['poll', 'id']), - quote: status.getIn(['quote', 'id']) || status.getIn(['pleroma', 'quote', 'id']), + quote: status.getIn(['quote', 'id']), }); }; @@ -70,6 +70,7 @@ export const calculateStatus = (status, oldStatus, expandSpoilers = false) => { } }; +// Check whether a status is a quote by secondary characteristics const isQuote = status => { return Boolean(status.get('quote_id') || status.getIn(['pleroma', 'quote_url'])); };