diff --git a/app/soapbox/__fixtures__/pleroma-status-deleted.json b/app/soapbox/__fixtures__/pleroma-status-deleted.json new file mode 100644 index 000000000..2d37af257 --- /dev/null +++ b/app/soapbox/__fixtures__/pleroma-status-deleted.json @@ -0,0 +1,229 @@ +{ + "account": { + "acct": "alex", + "avatar": "https://media.gleasonator.com/6d64aecb17348b23aaff78db4687b9476cb0da1c07cc6a819c2e6ec7144c18b1.png", + "avatar_static": "https://media.gleasonator.com/6d64aecb17348b23aaff78db4687b9476cb0da1c07cc6a819c2e6ec7144c18b1.png", + "bot": false, + "created_at": "2020-01-08T01:25:43.000Z", + "display_name": "Alex Gleason", + "emojis": [], + "fields": [ + { + "name": "Website", + "value": "https://alexgleason.me" + }, + { + "name": "Soapbox", + "value": "https://soapbox.pub" + }, + { + "name": "Email", + "value": "alex@alexgleason.me" + }, + { + "name": "Gender identity", + "value": "Soyboy" + }, + { + "name": "Donate (PayPal)", + "value": "https://paypal.me/gleasonator" + }, + { + "name": "$BTC", + "value": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n" + }, + { + "name": "$ETH", + "value": "0xAc9aB5Fc04Dc1cB1789Af75b523Bd23C70B2D717" + }, + { + "name": "$DOGE", + "value": "D5zVZs6jrRakaPVGiErkQiHt9sayzm6V5D" + }, + { + "name": "$XMR", + "value": "45JDCLrjJ4bgVUSbbs2yjy9m5Mf4VLPW8fG7jw9sq5u69rXZZopQogZNeyYkMBnXpkaip4p4QwaaJNhdTotPa9g44DBCzdK" + } + ], + "follow_requests_count": 0, + "followers_count": 2489, + "following_count": 1586, + "fqn": "alex@gleasonator.com", + "header": "https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png", + "header_static": "https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png", + "id": "9v5bmRalQvjOy0ECcC", + "last_status_at": "2022-03-16T21:57:17", + "locked": false, + "note": "I create Fediverse software that empowers people online.

I'm vegan btw

Note: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.", + "pleroma": { + "accepts_chat_messages": true, + "accepts_email_list": true, + "allow_following_move": true, + "also_known_as": [ + "https://mitra.social/users/alex" + ], + "ap_id": "https://gleasonator.com/users/alex", + "background_image": null, + "birthday": "1993-07-03", + "deactivated": false, + "email": "alex@alexgleason.me", + "favicon": "https://gleasonator.com/favicon.png", + "hide_favorites": true, + "hide_followers": false, + "hide_followers_count": false, + "hide_follows": false, + "hide_follows_count": false, + "is_admin": true, + "is_confirmed": true, + "is_moderator": false, + "is_suggested": true, + "location": null, + "notification_settings": { + "block_from_strangers": false, + "hide_notification_contents": false + }, + "relationship": {}, + "skip_thread_containment": false, + "tags": [], + "unread_conversation_count": 392, + "unread_notifications_count": 2 + }, + "source": { + "fields": [ + { + "name": "Website", + "value": "https://alexgleason.me" + }, + { + "name": "Soapbox", + "value": "https://soapbox.pub" + }, + { + "name": "Email", + "value": "alex@alexgleason.me" + }, + { + "name": "Gender identity", + "value": "Soyboy" + }, + { + "name": "Donate (PayPal)", + "value": "https://paypal.me/gleasonator" + }, + { + "name": "$BTC", + "value": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n" + }, + { + "name": "$ETH", + "value": "0xAc9aB5Fc04Dc1cB1789Af75b523Bd23C70B2D717" + }, + { + "name": "$DOGE", + "value": "D5zVZs6jrRakaPVGiErkQiHt9sayzm6V5D" + }, + { + "name": "$XMR", + "value": "45JDCLrjJ4bgVUSbbs2yjy9m5Mf4VLPW8fG7jw9sq5u69rXZZopQogZNeyYkMBnXpkaip4p4QwaaJNhdTotPa9g44DBCzdK" + } + ], + "note": "I create Fediverse software that empowers people online.\r\n\r\nI'm vegan btw\r\n\r\nNote: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.", + "pleroma": { + "actor_type": "Person", + "discoverable": false, + "no_rich_text": false, + "show_birthday": true, + "show_role": true + }, + "privacy": "public", + "sensitive": false + }, + "statuses_count": 23695, + "url": "https://gleasonator.com/users/alex", + "username": "alex" + }, + "application": { + "name": "Soapbox FE", + "website": "https://soapbox.pub/" + }, + "bookmarked": false, + "card": null, + "content": "

I am going to delete this post for testing purposes

", + "created_at": "2022-03-16T21:57:16.000Z", + "emojis": [], + "favourited": false, + "favourites_count": 3, + "id": "AHU2RrX0wdcwzCYjFQ", + "in_reply_to_account_id": null, + "in_reply_to_id": null, + "language": null, + "media_attachments": [ + { + "blurhash": "eWGlL@?b~q%MRj4nt7IUof%M%MIURjRjIUM{IUM{Rjayxut7j[j[xu", + "description": "", + "id": "508107650", + "meta": { + "original": { + "aspect": 1, + "height": 1024, + "width": 1024 + } + }, + "pleroma": { + "mime_type": "image/png" + }, + "preview_url": "https://media.gleasonator.com/2b9ddcd8b27cad786fd34bc2cfe02c1b63aa1b8e7b8d72379b5c9375fb61f199.png", + "remote_url": "https://media.gleasonator.com/2b9ddcd8b27cad786fd34bc2cfe02c1b63aa1b8e7b8d72379b5c9375fb61f199.png", + "text_url": "https://media.gleasonator.com/2b9ddcd8b27cad786fd34bc2cfe02c1b63aa1b8e7b8d72379b5c9375fb61f199.png", + "type": "image", + "url": "https://media.gleasonator.com/2b9ddcd8b27cad786fd34bc2cfe02c1b63aa1b8e7b8d72379b5c9375fb61f199.png" + } + ], + "mentions": [], + "muted": false, + "pinned": false, + "pleroma": { + "content": { + "text/plain": "I am going to delete this post for testing purposes" + }, + "content_type": "text/markdown", + "conversation_id": "AHU2RrUB7BMIqPESpM", + "direct_conversation_id": null, + "emoji_reactions": [ + { + "count": 1, + "me": false, + "name": "😭" + }, + { + "count": 1, + "me": false, + "name": "❔" + } + ], + "expires_at": null, + "in_reply_to_account_acct": null, + "local": true, + "parent_visible": false, + "pinned_at": null, + "quote": null, + "quote_url": null, + "quote_visible": false, + "spoiler_text": { + "text/plain": "" + }, + "thread_muted": false + }, + "poll": null, + "reblog": null, + "reblogged": false, + "reblogs_count": 1, + "replies_count": 2, + "sensitive": false, + "spoiler_text": "", + "tags": [], + "text": "I am going to delete this post for testing purposes", + "uri": "https://gleasonator.com/objects/205ec868-d28d-4668-a56a-33321f7e285e", + "url": "https://gleasonator.com/notice/AHU2RrX0wdcwzCYjFQ", + "visibility": "public" +} diff --git a/app/soapbox/actions/statuses.js b/app/soapbox/actions/statuses.js index abc7e4f94..3433f47f2 100644 --- a/app/soapbox/actions/statuses.js +++ b/app/soapbox/actions/statuses.js @@ -1,5 +1,5 @@ import { isLoggedIn } from 'soapbox/utils/auth'; -import { getFeatures } from 'soapbox/utils/features'; +import { getFeatures, parseVersion } from 'soapbox/utils/features'; import { shouldHaveCard } from 'soapbox/utils/status'; import api from '../api'; @@ -99,17 +99,16 @@ export function fetchStatus(id) { export function redraft(status, raw_text, content_type) { return (dispatch, getState) => { - const state = getState(); - const instance = state.get('instance'); - const { explicitAddressing, redraftMedia } = getFeatures(instance); + const { instance } = getState(); + const { explicitAddressing } = getFeatures(instance); dispatch({ type: REDRAFT, status, raw_text, explicitAddressing, - redraftMedia, content_type, + v: parseVersion(instance.version), }); }; } diff --git a/app/soapbox/reducers/__tests__/compose-test.js b/app/soapbox/reducers/__tests__/compose-test.js index 348739a6b..454c787ca 100644 --- a/app/soapbox/reducers/__tests__/compose-test.js +++ b/app/soapbox/reducers/__tests__/compose-test.js @@ -1,10 +1,11 @@ -import { Map as ImmutableMap } from 'immutable'; +import { Map as ImmutableMap, fromJS } from 'immutable'; import * as actions from 'soapbox/actions/compose'; import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me'; import { SETTING_CHANGE } from 'soapbox/actions/settings'; -//import { REDRAFT } from 'soapbox/actions/statuses'; +import { REDRAFT } from 'soapbox/actions/statuses'; import { TIMELINE_DELETE } from 'soapbox/actions/timelines'; +import { normalizeStatus } from 'soapbox/normalizers/status'; import reducer from '../compose'; @@ -38,6 +39,29 @@ describe('compose reducer', () => { expect(state.get('idempotencyKey').length === 36); }); + describe('REDRAFT', () => { + it('strips Pleroma integer attachments', () => { + const action = { + type: REDRAFT, + status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + v: { software: 'Pleroma' }, + }; + + const result = reducer(undefined, action); + expect(result.get('media_attachments').isEmpty()).toBe(true); + }); + + it('leaves non-Pleroma integer attachments alone', () => { + const action = { + type: REDRAFT, + status: normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))), + }; + + const result = reducer(undefined, action); + expect(result.getIn(['media_attachments', 0, 'id'])).toEqual('508107650'); + }); + }); + it('uses \'public\' scope as default', () => { const action = { type: actions.COMPOSE_REPLY, @@ -325,30 +349,6 @@ describe('compose reducer', () => { }); }); - // it('should handle COMPOSE_UPLOAD_UNDO', () => { - // const state = ImmutableMap({ - // media_attachments: ImmutableList([ - // description: null, - // id: '1375732379', - // pleroma: { - // mime_type: 'image/jpeg' - // }, - // preview_url: 'https://media.gleasonator.com/media_attachments/files/000/853/856/original/7035d67937053e1d.jpg', - // remote_url: 'https://media.gleasonator.com/media_attachments/files/000/853/856/original/7035d67937053e1d.jpg', - // text_url: 'https://media.gleasonator.com/media_attachments/files/000/853/856/original/7035d67937053e1d.jpg', - // type: 'image', - // url: 'https://media.gleasonator.com/media_attachments/files/000/853/856/original/7035d67937053e1d.jpg' - // ]), - // }); - // const action = { - // type: actions.COMPOSE_UPLOAD_UNDO, - // mediaId: '1375732379', - // }; - // expect(reducer(state, action)).toEqual({ - // media_attachments: [], - // }); - // }); - it('should handle COMPOSE_UPLOAD_PROGRESS', () => { const state = ImmutableMap({ progress: 0 }); const action = { @@ -361,203 +361,6 @@ describe('compose reducer', () => { }); }); - // it('should handle COMPOSE_MENTION', () => { - // const state = ImmutableMap({}); - // const account = { - // '9w1HhmenIAKBHJiUs4': { - // header_static: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - // display_name_html: 'Alex Gleason', - // bot: false, - // display_name: 'Alex Gleason', - // created_at: '2020-06-12T21:47:28.000Z', - // locked: false, - // emojis: [], - // header: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - // url: 'https://gleasonator.com/users/alex', - // note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - // acct: 'alex@gleasonator.com', - // avatar_static: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - // username: 'alex', - // avatar: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - // fields: [ - // { - // name: 'Website', - // value: 'https://alexgleason.me', - // name_emojified: 'Website', - // value_emojified: 'https://alexgleason.me', - // value_plain: 'https://alexgleason.me' - // }, - // { - // name: 'Pleroma+Soapbox', - // value: 'https://soapbox.pub', - // name_emojified: 'Pleroma+Soapbox', - // value_emojified: 'https://soapbox.pub', - // value_plain: 'https://soapbox.pub' - // }, - // { - // name: 'Email', - // value: 'alex@alexgleason.me', - // name_emojified: 'Email', - // value_emojified: 'alex@alexgleason.me', - // value_plain: 'alex@alexgleason.me' - // }, - // { - // name: 'Gender identity', - // value: 'Soyboy', - // name_emojified: 'Gender identity', - // value_emojified: 'Soyboy', - // value_plain: 'Soyboy' - // } - // ], - // pleroma: { - // hide_follows: false, - // hide_followers_count: false, - // background_image: null, - // confirmation_pending: false, - // is_moderator: false, - // hide_follows_count: false, - // hide_followers: false, - // relationship: { - // showing_reblogs: true, - // followed_by: false, - // subscribing: false, - // blocked_by: false, - // requested: false, - // domain_blocking: false, - // following: false, - // endorsed: false, - // blocking: false, - // muting: false, - // id: '9w1HhmenIAKBHJiUs4', - // muting_notifications: false - // }, - // tags: [], - // hide_favorites: true, - // is_admin: false, - // skip_thread_containment: false - // }, - // source: { - // fields: [], - // note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - // pleroma: { - // actor_type: 'Person', - // discoverable: false - // }, - // sensitive: false - // }, - // id: '9w1HhmenIAKBHJiUs4', - // note_emojified: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.' - // }, - // }; - // const action = { - // type: actions.COMPOSE_MENTION, - // account: account, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // text: '@alex@gleasonator.com', - // caretPosition: null, - // }); - // }); - - // it('should handle COMPOSE_DIRECT', () => { - // const state = ImmutableMap({}); - // const account = { - // '9w1HhmenIAKBHJiUs4': { - // header_static: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - // display_name_html: 'Alex Gleason', - // bot: false, - // display_name: 'Alex Gleason', - // created_at: '2020-06-12T21:47:28.000Z', - // locked: false, - // emojis: [], - // header: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - // url: 'https://gleasonator.com/users/alex', - // note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - // acct: 'alex@gleasonator.com', - // avatar_static: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - // username: 'alex', - // avatar: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - // fields: [ - // { - // name: 'Website', - // value: 'https://alexgleason.me', - // name_emojified: 'Website', - // value_emojified: 'https://alexgleason.me', - // value_plain: 'https://alexgleason.me' - // }, - // { - // name: 'Pleroma+Soapbox', - // value: 'https://soapbox.pub', - // name_emojified: 'Pleroma+Soapbox', - // value_emojified: 'https://soapbox.pub', - // value_plain: 'https://soapbox.pub' - // }, - // { - // name: 'Email', - // value: 'alex@alexgleason.me', - // name_emojified: 'Email', - // value_emojified: 'alex@alexgleason.me', - // value_plain: 'alex@alexgleason.me' - // }, - // { - // name: 'Gender identity', - // value: 'Soyboy', - // name_emojified: 'Gender identity', - // value_emojified: 'Soyboy', - // value_plain: 'Soyboy' - // } - // ], - // pleroma: { - // hide_follows: false, - // hide_followers_count: false, - // background_image: null, - // confirmation_pending: false, - // is_moderator: false, - // hide_follows_count: false, - // hide_followers: false, - // relationship: { - // showing_reblogs: true, - // followed_by: false, - // subscribing: false, - // blocked_by: false, - // requested: false, - // domain_blocking: false, - // following: false, - // endorsed: false, - // blocking: false, - // muting: false, - // id: '9w1HhmenIAKBHJiUs4', - // muting_notifications: false - // }, - // tags: [], - // hide_favorites: true, - // is_admin: false, - // skip_thread_containment: false - // }, - // source: { - // fields: [], - // note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - // pleroma: { - // actor_type: 'Person', - // discoverable: false - // }, - // sensitive: false - // }, - // id: '9w1HhmenIAKBHJiUs4', - // note_emojified: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.' - // } - // }; - // const action = { - // type: actions.COMPOSE_DIRECT, - // account: account, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // text: '@alex@gleasonator.com', - // caretPosition: null, - // privacy: 'direct', - // }); - // }); - // it('should handle COMPOSE_SUGGESTIONS_CLEAR', () => { const state = ImmutableMap({ }); const action = { @@ -570,28 +373,6 @@ describe('compose reducer', () => { }); }); - // it('should handle COMPOSE_SUGGESTIONS_READY', () => { - // const state = ImmutableMap({ default_privacy: 'public', privacy: 'public'}); - // const action = { - // type: actions.COMPOSE_SUGGESTIONS_READY, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // default_privacy: 'unlisted', - // privacy: 'public', - // }); - // }); - // - // it('should handle COMPOSE_SUGGESTION_SELECT', () => { - // const state = ImmutableMap({ default_privacy: 'public', privacy: 'public'}); - // const action = { - // type: actions.COMPOSE_SUGGESTION_SELECT, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // default_privacy: 'unlisted', - // privacy: 'public', - // }); - // }); - // it('should handle COMPOSE_SUGGESTION_TAGS_UPDATE', () => { const state = ImmutableMap({ tagHistory: [ 'hashtag' ] }); const action = { @@ -627,42 +408,6 @@ describe('compose reducer', () => { }); }); - // it('should handle COMPOSE_EMOJI_INSERT', () => { - // const state = ImmutableMap({ text: 'this is my' }); - // const action = { - // type: actions.COMPOSE_EMOJI_INSERT, - // position: 11, - // emoji: [], - // needsSpace, true, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // text: 'this is my :emoji:', - // caretPosition: 15, - // }); - // }); - // - // it('should handle COMPOSE_UPLOAD_CHANGE_SUCCESS', () => { - // const state = ImmutableMap({ default_privacy: 'public' }); - // const action = { - // type: actions.COMPOSE_UPLOAD_CHANGE_SUCCESS, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // default_privacy: 'unlisted', - // privacy: 'public', - // }); - // }); - // - // it('should handle REDRAFT', () => { - // const state = ImmutableMap({ default_privacy: 'public' }); - // const action = { - // type: REDRAFT, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // default_privacy: 'unlisted', - // privacy: 'public', - // }); - // }); - // it('should handle COMPOSE_POLL_ADD', () => { const state = ImmutableMap({ poll: null }); const initialPoll = Object({ @@ -691,34 +436,6 @@ describe('compose reducer', () => { }); }); - // it('should handle COMPOSE_POLL_OPTION_ADD', () => { - // const initialPoll = Object({ - // options: [ - // 'option 1', - // 'option 2', - // ], - // expires_in: 86400, - // multiple: false - // }); - // const state = ImmutableMap({ poll: initialPoll }); - // const action = { - // type: actions.COMPOSE_POLL_OPTION_ADD, - // title: 'option 3', - // }; - // const updatedPoll = Object({ - // options: [ - // 'option 1', - // 'option 2', - // 'option 3', - // ], - // expires_in: 86400, - // multiple: false, - // }); - // expect(reducer(state, action).toJS()).toMatchObject({ - // poll: updatedPoll, - // }); - // }); - it('should handle COMPOSE_POLL_OPTION_CHANGE', () => { const initialPoll = Object({ options: [ @@ -747,32 +464,6 @@ describe('compose reducer', () => { }); }); - // it('should handle COMPOSE_POLL_OPTION_REMOVE', () => { - // const initialPoll = Object({ - // options: [ - // 'option 1', - // 'option 2', - // ], - // expires_in: 86400, - // multiple: false, - // }); - // const state = ImmutableMap({ poll: initialPoll }); - // const action = { - // type: actions.COMPOSE_POLL_OPTION_REMOVE, - // index: 1, - // }; - // const updatedPoll = Object({ - // options: [ - // 'option 1', - // ], - // expires_in: 86400, - // multiple: false, - // }); - // expect(reducer(state, action).toJS()).toMatchObject({ - // poll: updatedPoll, - // }); - // }); - it('sets the post content-type', () => { const action = { type: actions.COMPOSE_TYPE_CHANGE, diff --git a/app/soapbox/reducers/compose.js b/app/soapbox/reducers/compose.js index f4dc03985..43fd23154 100644 --- a/app/soapbox/reducers/compose.js +++ b/app/soapbox/reducers/compose.js @@ -1,6 +1,8 @@ import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable'; import { tagHistory } from 'soapbox/settings'; +import { PLEROMA } from 'soapbox/utils/features'; +import { hasIntegerMediaIds } from 'soapbox/utils/status'; import { COMPOSE_MOUNT, @@ -431,13 +433,17 @@ export default function compose(state = initialState, action) { map.set('to', action.explicitAddressing ? getExplicitMentions(action.status.get('account', 'id'), action.status) : undefined); map.set('in_reply_to', action.status.get('in_reply_to_id')); map.set('privacy', action.status.get('visibility')); - // TODO: Actually fix this rather than just removing it - if (action.redraftMedia) map.set('media_attachments', action.status.get('media_attachments')); map.set('focusDate', new Date()); map.set('caretPosition', null); map.set('idempotencyKey', uuid()); map.set('content_type', action.content_type || 'text/plain'); + if (action.v?.software === PLEROMA && hasIntegerMediaIds(action.status)) { + map.set('media_attachments', ImmutableList()); + } else { + map.set('media_attachments', action.status.get('media_attachments')); + } + if (action.status.get('spoiler_text').length > 0) { map.set('spoiler', true); map.set('spoiler_text', action.status.get('spoiler_text')); diff --git a/app/soapbox/utils/__tests__/numbers-test.js b/app/soapbox/utils/__tests__/numbers-test.js new file mode 100644 index 000000000..86923a781 --- /dev/null +++ b/app/soapbox/utils/__tests__/numbers-test.js @@ -0,0 +1,13 @@ +import { isIntegerId } from '../numbers'; + +test('isIntegerId()', () => { + expect(isIntegerId('0')).toBe(true); + expect(isIntegerId('1')).toBe(true); + expect(isIntegerId('508107650')).toBe(true); + expect(isIntegerId('-1764036199')).toBe(true); + expect(isIntegerId('106801667066418367')).toBe(true); + expect(isIntegerId('9v5bmRalQvjOy0ECcC')).toBe(false); + expect(isIntegerId(null)).toBe(false); + expect(isIntegerId(undefined)).toBe(false); + expect(isIntegerId()).toBe(false); +}); diff --git a/app/soapbox/utils/__tests__/status-test.js b/app/soapbox/utils/__tests__/status-test.js new file mode 100644 index 000000000..0dcb3e78a --- /dev/null +++ b/app/soapbox/utils/__tests__/status-test.js @@ -0,0 +1,12 @@ +import { fromJS } from 'immutable'; + +import { normalizeStatus } from 'soapbox/normalizers/status'; + +import { hasIntegerMediaIds } from '../status'; + +describe('hasIntegerMediaIds()', () => { + it('returns true for a Pleroma deleted status', () => { + const status = normalizeStatus(fromJS(require('soapbox/__fixtures__/pleroma-status-deleted.json'))); + expect(hasIntegerMediaIds(status)).toBe(true); + }); +}); diff --git a/app/soapbox/utils/features.js b/app/soapbox/utils/features.js index f745cd0e7..8f636eea0 100644 --- a/app/soapbox/utils/features.js +++ b/app/soapbox/utils/features.js @@ -110,7 +110,6 @@ export const getFeatures = createSelector([instance => instance], instance => { v.software === MASTODON && gte(v.compatVersion, '3.2.0'), v.software === PLEROMA && gte(v.version, '2.4.50'), ]), - redraftMedia: v.software === MASTODON, }, overrides); }); diff --git a/app/soapbox/utils/numbers.js b/app/soapbox/utils/numbers.js index 8191692b3..18f4d5019 100644 --- a/app/soapbox/utils/numbers.js +++ b/app/soapbox/utils/numbers.js @@ -12,3 +12,5 @@ export const shortNumberFormat = number => { return K; } }; + +export const isIntegerId = id => new RegExp(/^-?[0-9]+$/g).test(id); diff --git a/app/soapbox/utils/status.js b/app/soapbox/utils/status.js index 48554ced9..acd69dc5e 100644 --- a/app/soapbox/utils/status.js +++ b/app/soapbox/utils/status.js @@ -1,3 +1,5 @@ +import { isIntegerId } from 'soapbox/utils/numbers'; + export const getFirstExternalLink = status => { try { // Pulled from Pleroma's media parser @@ -13,3 +15,8 @@ export const getFirstExternalLink = status => { export const shouldHaveCard = status => { return Boolean(getFirstExternalLink(status)); }; + +// https://gitlab.com/soapbox-pub/soapbox-fe/-/merge_requests/1087 +export const hasIntegerMediaIds = status => { + return status.media_attachments.some(({ id }) => isIntegerId(id)); +};