diff --git a/app/soapbox/actions/external_auth.js b/app/soapbox/actions/external_auth.js index c6fc5d340..f4058cba2 100644 --- a/app/soapbox/actions/external_auth.js +++ b/app/soapbox/actions/external_auth.js @@ -24,7 +24,7 @@ const fetchExternalInstance = baseURL => { .get('/api/v1/instance') .then(({ data: instance }) => fromJS(instance)) .catch(error => { - if (error.response && error.response.status === 401) { + if (error.response?.status === 401) { // Authenticated fetch is enabled. // Continue with a limited featureset. return ImmutableMap({ version: '0.0.0' }); diff --git a/app/soapbox/actions/importer/index.js b/app/soapbox/actions/importer/index.js index aee579695..3a019e636 100644 --- a/app/soapbox/actions/importer/index.js +++ b/app/soapbox/actions/importer/index.js @@ -65,20 +65,20 @@ export function importFetchedStatus(status, idempotencyKey) { const normalizedStatus = normalizeStatus(status, normalOldStatus, expandSpoilers); - if (status.reblog && status.reblog.id) { + if (status.reblog?.id) { dispatch(importFetchedStatus(status.reblog)); } // Fedibird quotes - if (status.quote && status.quote.id) { + if (status.quote?.id) { dispatch(importFetchedStatus(status.quote)); } - if (status.pleroma && status.pleroma.quote && status.pleroma.quote.id) { + if (status.pleroma?.quote?.id) { dispatch(importFetchedStatus(status.pleroma.quote)); } - if (status.poll && status.poll.id) { + if (status.poll?.id) { dispatch(importFetchedPoll(status.poll)); } @@ -119,20 +119,20 @@ export function importFetchedStatuses(statuses) { normalStatuses.push(normalizeStatus(status, normalOldStatus, expandSpoilers)); accounts.push(status.account); - if (status.reblog && status.reblog.id) { + if (status.reblog?.id) { processStatus(status.reblog); } // Fedibird quotes - if (status.quote && status.quote.id) { + if (status.quote?.id) { processStatus(status.quote); } - if (status.pleroma && status.pleroma.quote && status.pleroma.quote.id) { + if (status.pleroma?.quote?.id) { processStatus(status.pleroma.quote); } - if (status.poll && status.poll.id) { + if (status.poll?.id) { polls.push(normalizePoll(status.poll)); } } diff --git a/app/soapbox/actions/importer/normalizer.js b/app/soapbox/actions/importer/normalizer.js index 7c5aa8bd3..7d40357f0 100644 --- a/app/soapbox/actions/importer/normalizer.js +++ b/app/soapbox/actions/importer/normalizer.js @@ -59,19 +59,19 @@ export function normalizeStatus(status, normalOldStatus, expandSpoilers) { normalStatus.account = status.account.id; - if (status.reblog && status.reblog.id) { + if (status.reblog?.id) { normalStatus.reblog = status.reblog.id; } - if (status.poll && status.poll.id) { + if (status.poll?.id) { normalStatus.poll = status.poll.id; } - if (status.pleroma && status.pleroma.quote && status.pleroma.quote.id) { + if (status.pleroma?.quote?.id) { // Normalize quote to the top-level, so delete the original for performance normalStatus.quote = status.pleroma.quote.id; delete normalStatus.pleroma.quote; - } else if (status.quote && status.quote.id) { + } else if (status.quote?.id) { // Fedibird compatibility, because why not normalStatus.quote = status.quote.id; } else if (status.quote_id) { @@ -88,7 +88,7 @@ export function normalizeStatus(status, normalOldStatus, expandSpoilers) { normalStatus.hidden = normalOldStatus.get('hidden'); } else { const spoilerText = normalStatus.spoiler_text || ''; - const searchContent = ([spoilerText, status.content].concat((status.poll && status.poll.options) ? status.poll.options.map(option => option.title) : [])).join('\n\n').replace(//g, '\n').replace(/<\/p>

/g, '\n\n'); + const searchContent = ([spoilerText, status.content].concat((status.poll?.options) ? status.poll.options.map(option => option.title) : [])).join('\n\n').replace(//g, '\n').replace(/<\/p>

/g, '\n\n'); const emojiMap = makeEmojiMap(normalStatus); normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent; @@ -107,7 +107,7 @@ export function normalizePoll(poll) { normalPoll.options = poll.options.map((option, index) => ({ ...option, - voted: poll.own_votes && poll.own_votes.includes(index), + voted: Boolean(poll.own_votes?.includes(index)), title_emojified: emojify(escapeTextContentForBrowser(option.title), emojiMap), })); diff --git a/app/soapbox/actions/notifications.js b/app/soapbox/actions/notifications.js index ac7066563..a4331bf8c 100644 --- a/app/soapbox/actions/notifications.js +++ b/app/soapbox/actions/notifications.js @@ -206,16 +206,16 @@ export function expandNotifications({ maxId } = {}, done = noOp) { const next = getLinks(response).refs.find(link => link.rel === 'next'); const entries = response.data.reduce((acc, item) => { - if (item.account && item.account.id) { + if (item.account?.id) { acc.accounts[item.account.id] = item.account; } // Used by Move notification - if (item.target && item.target.id) { + if (item.target?.id) { acc.accounts[item.target.id] = item.target; } - if (item.status && item.status.id) { + if (item.status?.id) { acc.statuses[item.status.id] = item.status; } diff --git a/app/soapbox/actions/statuses.js b/app/soapbox/actions/statuses.js index ba53994b5..b529e9b23 100644 --- a/app/soapbox/actions/statuses.js +++ b/app/soapbox/actions/statuses.js @@ -62,7 +62,7 @@ export function createStatus(params, idempotencyKey) { const poll = (retries = 5) => { api(getState).get(`/api/v1/statuses/${status.id}`).then(response => { - if (response.data && response.data.card) { + if (response.data?.card) { dispatch(importFetchedStatus(response.data)); } else if (retries > 0 && response.status === 200) { setTimeout(() => poll(retries - 1), delay); @@ -157,7 +157,7 @@ export function fetchContext(id) { } return context; }).catch(error => { - if (error.response && error.response.status === 404) { + if (error.response?.status === 404) { dispatch(deleteFromTimelines(id)); } diff --git a/app/soapbox/actions/timelines.js b/app/soapbox/actions/timelines.js index bef27b287..12223c0ba 100644 --- a/app/soapbox/actions/timelines.js +++ b/app/soapbox/actions/timelines.js @@ -26,7 +26,7 @@ export const MAX_QUEUED_ITEMS = 40; export function processTimelineUpdate(timeline, status, accept) { return (dispatch, getState) => { const me = getState().get('me'); - const ownStatus = status.account && status.account.id === me; + const ownStatus = status.account?.id === me; const hasPendingStatuses = !getState().get('pending_statuses').isEmpty(); const columnSettings = getSettings(getState()).get(timeline, ImmutableMap()); diff --git a/app/soapbox/components/birthday_reminders.js b/app/soapbox/components/birthday_reminders.js index b93c30ed5..12fa249fd 100644 --- a/app/soapbox/components/birthday_reminders.js +++ b/app/soapbox/components/birthday_reminders.js @@ -19,7 +19,7 @@ const mapStateToProps = (state, props) => { const birthdays = state.getIn(['user_lists', 'birthday_reminders', me]); - if (birthdays && birthdays.size > 0) { + if (birthdays?.size > 0) { return { birthdays, account: getAccount(state, birthdays.first()), @@ -151,4 +151,4 @@ class BirthdayReminders extends ImmutablePureComponent { ); } -} \ No newline at end of file +} diff --git a/app/soapbox/components/column_back_button.js b/app/soapbox/components/column_back_button.js index b4b09b0cf..40840f8ad 100644 --- a/app/soapbox/components/column_back_button.js +++ b/app/soapbox/components/column_back_button.js @@ -17,7 +17,7 @@ export default class ColumnBackButton extends React.PureComponent { handleClick = () => { const { to } = this.props; - if (window.history && window.history.length === 1) { + if (window.history?.length === 1) { this.context.router.history.push(to ? to : '/'); } else { this.context.router.history.goBack(); diff --git a/app/soapbox/components/column_header.js b/app/soapbox/components/column_header.js index 9c624ae8c..c13113db7 100644 --- a/app/soapbox/components/column_header.js +++ b/app/soapbox/components/column_header.js @@ -34,7 +34,7 @@ export default class ColumnHeader extends React.PureComponent { }; historyBack = () => { - if (window.history && window.history.length === 1) { + if (window.history?.length === 1) { this.context.router.history.push('/'); } else { this.context.router.history.goBack(); diff --git a/app/soapbox/components/display_name.js b/app/soapbox/components/display_name.js index daf7fe974..eca526679 100644 --- a/app/soapbox/components/display_name.js +++ b/app/soapbox/components/display_name.js @@ -49,7 +49,7 @@ class DisplayName extends React.PureComponent { ) : null; - if (others && others.size > 1) { + if (others?.size > 1) { displayName = others.take(2).map(a => ( diff --git a/app/soapbox/features/auth_login/components/login_page.js b/app/soapbox/features/auth_login/components/login_page.js index ca16c2a81..45de99585 100644 --- a/app/soapbox/features/auth_login/components/login_page.js +++ b/app/soapbox/features/auth_login/components/login_page.js @@ -52,8 +52,8 @@ class LoginPage extends ImmutablePureComponent { dispatch(switchAccount(account.id)); } }).catch(error => { - const data = error.response && error.response.data; - if (data && data.error === 'mfa_required') { + const data = error.response?.data; + if (data?.error === 'mfa_required') { this.setState({ mfa_auth_needed: true, mfa_token: data.mfa_token }); } this.setState({ isLoading: false }); diff --git a/app/soapbox/features/auth_login/components/registration_form.js b/app/soapbox/features/auth_login/components/registration_form.js index 1ed0b7f20..8a6f7353f 100644 --- a/app/soapbox/features/auth_login/components/registration_form.js +++ b/app/soapbox/features/auth_login/components/registration_form.js @@ -197,7 +197,7 @@ class RegistrationForm extends ImmutablePureComponent { this.setState({ usernameUnavailable: !!account }); }) .catch((error) => { - if (error.response && error.response.status === 404) { + if (error.response?.status === 404) { this.setState({ usernameUnavailable: false }); } }); diff --git a/app/soapbox/features/compose/components/compose_form.js b/app/soapbox/features/compose/components/compose_form.js index d509be69e..64a8910f9 100644 --- a/app/soapbox/features/compose/components/compose_form.js +++ b/app/soapbox/features/compose/components/compose_form.js @@ -124,7 +124,7 @@ export default class ComposeForm extends ImmutablePureComponent { document.querySelector('.privacy-dropdown__dropdown'), document.querySelector('.emoji-picker-dropdown__menu'), document.querySelector('.modal-root__overlay'), - ].some(element => element && element.contains(e.target)); + ].some(element => element?.contains(e.target)); } handleClick = (e) => { diff --git a/app/soapbox/reducers/auth.js b/app/soapbox/reducers/auth.js index bf54f5973..a4b649441 100644 --- a/app/soapbox/reducers/auth.js +++ b/app/soapbox/reducers/auth.js @@ -264,7 +264,7 @@ const persistAuthAccount = account => { }; const deleteForbiddenToken = (state, error, token) => { - if (error.response && [401, 403].includes(error.response.status)) { + if ([401, 403].includes(error.response?.status)) { return deleteToken(state, token); } else { return state; diff --git a/app/soapbox/reducers/instance.js b/app/soapbox/reducers/instance.js index b0dd8594f..8a79a2869 100644 --- a/app/soapbox/reducers/instance.js +++ b/app/soapbox/reducers/instance.js @@ -163,7 +163,7 @@ const persistInstance = instance => { }; const handleInstanceFetchFail = (state, error) => { - if (error.response && error.response.status === 401) { + if (error.response?.status === 401) { return handleAuthFetch(state); } else { return state; diff --git a/app/soapbox/reducers/me.js b/app/soapbox/reducers/me.js index f5fc11f20..9f0796a85 100644 --- a/app/soapbox/reducers/me.js +++ b/app/soapbox/reducers/me.js @@ -13,7 +13,7 @@ import { const initialState = null; const handleForbidden = (state, error) => { - if (error.response && [401, 403].includes(error.response.status)) { + if ([401, 403].includes(error.response?.status)) { return false; } else { return state; diff --git a/app/soapbox/service_worker/web_push_notifications.js b/app/soapbox/service_worker/web_push_notifications.js index b73dabf42..c0eb4982e 100644 --- a/app/soapbox/service_worker/web_push_notifications.js +++ b/app/soapbox/service_worker/web_push_notifications.js @@ -91,7 +91,7 @@ const handlePush = (event) => { options.image = notification.status && notification.status.media_attachments.length > 0 && notification.status.media_attachments[0].preview_url || undefined; options.data = { access_token, preferred_locale, id: notification.status ? notification.status.id : notification.account.id, url: notification.status ? `/@${notification.account.username}/posts/${notification.status.id}` : `/@${notification.account.username}` }; - if (notification.status && notification.status.spoiler_text || notification.status.sensitive) { + if (notification.status?.spoiler_text || notification.status.sensitive) { options.data.hiddenBody = htmlToPlainText(notification.status.content); options.data.hiddenImage = notification.status.media_attachments.length > 0 && notification.status.media_attachments[0].preview_url; diff --git a/app/soapbox/utils/config_db.js b/app/soapbox/utils/config_db.js index 4d03aaa17..98fe650d9 100644 --- a/app/soapbox/utils/config_db.js +++ b/app/soapbox/utils/config_db.js @@ -20,7 +20,7 @@ const toSimplePolicy = configs => { return acc.set(trimStart(key, ':'), ImmutableSet(hosts)); }; - if (config && config.get) { + if (config?.get) { const value = config.get('value', ImmutableList()); return value.reduce(reducer, ImmutableMap()); } else { diff --git a/app/soapbox/utils/resize_image.js b/app/soapbox/utils/resize_image.js index f6a4ca34c..4d0040078 100644 --- a/app/soapbox/utils/resize_image.js +++ b/app/soapbox/utils/resize_image.js @@ -80,7 +80,7 @@ const dropOrientationIfNeeded = (orientation) => new Promise(resolve => { // }); const getImageUrl = inputFile => new Promise((resolve, reject) => { - if (window.URL && URL.createObjectURL) { + if (window.URL?.createObjectURL) { try { resolve(URL.createObjectURL(inputFile)); } catch (error) {