From 47ac7a2e502f70fbe3481b9c4e82f3eec8b66b45 Mon Sep 17 00:00:00 2001 From: fef Date: Sat, 3 Dec 2022 16:20:29 +0000 Subject: [PATCH] fix image for new custom emoji reactions --- .../flavours/glitch/actions/interactions.js | 7 ++++--- .../flavours/glitch/components/status_action_bar.js | 2 +- .../flavours/glitch/containers/status_container.js | 4 ++-- .../glitch/features/status/components/action_bar.js | 2 +- .../flavours/glitch/features/status/index.js | 4 ++-- app/javascript/flavours/glitch/reducers/statuses.js | 12 +++++++++--- app/javascript/mastodon/actions/interactions.js | 7 ++++--- .../mastodon/containers/status_container.js | 4 ++-- app/javascript/mastodon/features/status/index.js | 4 ++-- app/javascript/mastodon/reducers/statuses.js | 12 +++++++++--- 10 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/interactions.js b/app/javascript/flavours/glitch/actions/interactions.js index 0df6db4277..2d483de818 100644 --- a/app/javascript/flavours/glitch/actions/interactions.js +++ b/app/javascript/flavours/glitch/actions/interactions.js @@ -403,7 +403,7 @@ export function unpinFail(status, error) { }; }; -export const addReaction = (statusId, name) => (dispatch, getState) => { +export const addReaction = (statusId, name, url) => (dispatch, getState) => { const status = getState().get('statuses').get(statusId); let alreadyAdded = false; if (status) { @@ -413,7 +413,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => { } } if (!alreadyAdded) { - dispatch(addReactionRequest(statusId, name)); + dispatch(addReactionRequest(statusId, name, url)); } api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => { @@ -425,10 +425,11 @@ export const addReaction = (statusId, name) => (dispatch, getState) => { }); }; -export const addReactionRequest = (statusId, name) => ({ +export const addReactionRequest = (statusId, name, url) => ({ type: REACTION_ADD_REQUEST, id: statusId, name, + url, }); export const addReactionSuccess = (statusId, name) => ({ diff --git a/app/javascript/flavours/glitch/components/status_action_bar.js b/app/javascript/flavours/glitch/components/status_action_bar.js index 33dbe3ab89..72912acedd 100644 --- a/app/javascript/flavours/glitch/components/status_action_bar.js +++ b/app/javascript/flavours/glitch/components/status_action_bar.js @@ -118,7 +118,7 @@ class StatusActionBar extends ImmutablePureComponent { } handleEmojiPick = data => { - this.props.onReactionAdd(this.props.status.get('id'), data.native.replace(/:/g, '')); + this.props.onReactionAdd(this.props.status.get('id'), data.native.replace(/:/g, ''), data.imageUrl); } handleReblogClick = e => { diff --git a/app/javascript/flavours/glitch/containers/status_container.js b/app/javascript/flavours/glitch/containers/status_container.js index d68e059af4..3edcf9c7a8 100644 --- a/app/javascript/flavours/glitch/containers/status_container.js +++ b/app/javascript/flavours/glitch/containers/status_container.js @@ -167,8 +167,8 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({ } }, - onReactionAdd (statusId, name) { - dispatch(addReaction(statusId, name)); + onReactionAdd (statusId, name, url) { + dispatch(addReaction(statusId, name, url)); }, onReactionRemove (statusId, name) { diff --git a/app/javascript/flavours/glitch/features/status/components/action_bar.js b/app/javascript/flavours/glitch/features/status/components/action_bar.js index 1ed89ea059..6f86e2aa2c 100644 --- a/app/javascript/flavours/glitch/features/status/components/action_bar.js +++ b/app/javascript/flavours/glitch/features/status/components/action_bar.js @@ -81,7 +81,7 @@ class ActionBar extends React.PureComponent { } handleEmojiPick = data => { - this.props.onReactionAdd(this.props.status.get('id'), data.native.replace(/:/g, '')); + this.props.onReactionAdd(this.props.status.get('id'), data.native.replace(/:/g, ''), data.imageUrl); } handleBookmarkClick = (e) => { diff --git a/app/javascript/flavours/glitch/features/status/index.js b/app/javascript/flavours/glitch/features/status/index.js index a33939445f..f77f4a20fb 100644 --- a/app/javascript/flavours/glitch/features/status/index.js +++ b/app/javascript/flavours/glitch/features/status/index.js @@ -293,12 +293,12 @@ class Status extends ImmutablePureComponent { } } - handleReactionAdd = (statusId, name) => { + handleReactionAdd = (statusId, name, url) => { const { dispatch } = this.props; const { signedIn } = this.context.identity; if (signedIn) { - dispatch(addReaction(statusId, name)); + dispatch(addReaction(statusId, name, url)); } else { dispatch(openModal('INTERACTION', { type: 'reaction_add', diff --git a/app/javascript/flavours/glitch/reducers/statuses.js b/app/javascript/flavours/glitch/reducers/statuses.js index 22fdeb2841..446c991cac 100644 --- a/app/javascript/flavours/glitch/reducers/statuses.js +++ b/app/javascript/flavours/glitch/reducers/statuses.js @@ -59,11 +59,17 @@ const updateReaction = (state, id, name, updater) => state.update( const updateReactionCount = (state, reaction) => updateReaction(state, reaction.status_id, reaction.name, x => x.set('count', reaction.count)); -const addReaction = (state, id, name) => updateReaction( +// The url parameter is only used when adding a new custom emoji reaction +// (one that wasn't in the reactions list before) because we don't have its +// URL yet. In all other cases, it's undefined. +const addReaction = (state, id, name, url) => updateReaction( state, id, name, - x => x.set('me', true).update('count', n => n + 1), + x => x.set('me', true) + .update('count', n => n + 1) + .update('url', old => old ? old : url) + .update('static_url', old => old ? old : url), ); const removeReaction = (state, id, name) => updateReaction( @@ -103,7 +109,7 @@ export default function statuses(state = initialState, action) { return updateReactionCount(state, action.reaction); case REACTION_ADD_REQUEST: case REACTION_REMOVE_FAIL: - return addReaction(state, action.id, action.name); + return addReaction(state, action.id, action.name, action.url); case REACTION_REMOVE_REQUEST: case REACTION_ADD_FAIL: return removeReaction(state, action.id, action.name); diff --git a/app/javascript/mastodon/actions/interactions.js b/app/javascript/mastodon/actions/interactions.js index dd1395cbd3..54592ec535 100644 --- a/app/javascript/mastodon/actions/interactions.js +++ b/app/javascript/mastodon/actions/interactions.js @@ -423,7 +423,7 @@ export function unpinFail(status, error) { }; }; -export const addReaction = (statusId, name) => (dispatch, getState) => { +export const addReaction = (statusId, name, url) => (dispatch, getState) => { const status = getState().get('statuses').get(statusId); let alreadyAdded = false; if (status) { @@ -433,7 +433,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => { } } if (!alreadyAdded) { - dispatch(addReactionRequest(statusId, name)); + dispatch(addReactionRequest(statusId, name, url)); } api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => { @@ -445,10 +445,11 @@ export const addReaction = (statusId, name) => (dispatch, getState) => { }); }; -export const addReactionRequest = (statusId, name) => ({ +export const addReactionRequest = (statusId, name, url) => ({ type: REACTION_ADD_REQUEST, id: statusId, name, + url, }); export const addReactionSuccess = (statusId, name) => ({ diff --git a/app/javascript/mastodon/containers/status_container.js b/app/javascript/mastodon/containers/status_container.js index 556910f089..70adc04934 100644 --- a/app/javascript/mastodon/containers/status_container.js +++ b/app/javascript/mastodon/containers/status_container.js @@ -132,8 +132,8 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({ } }, - onReactionAdd (statusId, name) { - dispatch(addReaction(statusId, name)); + onReactionAdd (statusId, name, url) { + dispatch(addReaction(statusId, name, url)); }, onReactionRemove (statusId, name) { diff --git a/app/javascript/mastodon/features/status/index.js b/app/javascript/mastodon/features/status/index.js index e262cd94fb..d22009d0ed 100644 --- a/app/javascript/mastodon/features/status/index.js +++ b/app/javascript/mastodon/features/status/index.js @@ -257,12 +257,12 @@ class Status extends ImmutablePureComponent { } } - handleReactionAdd = (statusId, name) => { + handleReactionAdd = (statusId, name, url) => { const { dispatch } = this.props; const { signedIn } = this.context.identity; if (signedIn) { - dispatch(addReaction(statusId, name)); + dispatch(addReaction(statusId, name, url)); } else { dispatch(openModal('INTERACTION', { type: 'reaction_add', diff --git a/app/javascript/mastodon/reducers/statuses.js b/app/javascript/mastodon/reducers/statuses.js index 2228906674..cb9759119a 100644 --- a/app/javascript/mastodon/reducers/statuses.js +++ b/app/javascript/mastodon/reducers/statuses.js @@ -57,11 +57,17 @@ const updateReaction = (state, id, name, updater) => state.update( const updateReactionCount = (state, reaction) => updateReaction(state, reaction.status_id, reaction.name, x => x.set('count', reaction.count)); -const addReaction = (state, id, name) => updateReaction( +// The url parameter is only used when adding a new custom emoji reaction +// (one that wasn't in the reactions list before) because we don't have its +// URL yet. In all other cases, it's undefined. +const addReaction = (state, id, name, url) => updateReaction( state, id, name, - x => x.set('me', true).update('count', n => n + 1), + x => x.set('me', true) + .update('count', n => n + 1) + .update('url', old => old ? old : url) + .update('static_url', old => old ? old : url), ); const removeReaction = (state, id, name) => updateReaction( @@ -101,7 +107,7 @@ export default function statuses(state = initialState, action) { return updateReactionCount(state, action.reaction); case REACTION_ADD_REQUEST: case REACTION_REMOVE_FAIL: - return addReaction(state, action.id, action.name); + return addReaction(state, action.id, action.name, action.url); case REACTION_REMOVE_REQUEST: case REACTION_ADD_FAIL: return removeReaction(state, action.id, action.name);