Skip to content

Commit

Permalink
MM-22719: resolve custom emoji in attributes (#32)
Browse files Browse the repository at this point in the history
* MM-22719: resolve custom emoji in attributes

Resolve any custom emoji in attributes. Typically, these custom emoji
are resolved organically when they appear for the first time in posts,
but if not, we now rely on mattermost-redux to ensure same.

Fixes: https://mattermost.atlassian.net/browse/MM-22719

* improve readability

* linting
  • Loading branch information
lieut-data authored Apr 14, 2020
1 parent f5fdbf4 commit d7c7227
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions webapp/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {getCustomEmojisInText} from 'mattermost-redux/actions/emojis';

import Client from '../client';
import ActionTypes from '../action_types';
import {id as pluginId} from '../manifest';
Expand All @@ -11,7 +13,7 @@ export function getAttributes(userID = '') {
return {};
}

let data;
let data = [];
try {
data = await Client.getAttributes(userID);
} catch (error) {
Expand All @@ -27,6 +29,8 @@ export function getAttributes(userID = '') {
return {error};
}

data.forEach((attribute) => dispatch(getCustomEmojisInText(attribute)));

dispatch({
type: ActionTypes.RECEIVED_ATTRIBUTES,
userID,
Expand All @@ -37,4 +41,4 @@ export function getAttributes(userID = '') {

return {data};
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class CustomAttribute extends React.Component {
onChange: PropTypes.func.isRequired,
actions: PropTypes.shape({
getProfilesByIds: PropTypes.func.isRequired,
getCustomEmojisInText: PropTypes.func.isRequired,
}).isRequired,
}

Expand Down Expand Up @@ -105,6 +106,8 @@ export default class CustomAttribute extends React.Component {
return null;
}

this.props.actions.getCustomEmojisInText(this.state.name);

const formattedText = formatText(this.state.name);
return messageHtmlToComponent(formattedText);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getCustomEmojisInText} from 'mattermost-redux/actions/emojis';

import {getProfilesByIds} from 'mattermost-redux/actions/users';

Expand All @@ -9,6 +10,7 @@ function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
getProfilesByIds,
getCustomEmojisInText,
}, dispatch),
};
}
Expand Down

0 comments on commit d7c7227

Please sign in to comment.