MM-16442: count actual reactions before falling back to has_reactions (#2910)
* MM-16442: leverage post hasReactions utils function This handles backwards compatibility with servers that do not have post metadata, allowing the client to detect the presence of reactions that in turn might need to be loaded when the component is mounted. * temporary mattermost-redux commit for testing * revert usage of hasReactions, and count directly We still fallback to has_reactions if set, in case we're connected to a server without post metadata. * revert mattermost-redux changes
This commit is contained in:
parent
e3ffb037e5
commit
954868f572
2 changed files with 8 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general
|
|||
import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users';
|
||||
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
|
||||
import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis';
|
||||
import {makeGetReactionsForPost} from 'mattermost-redux/selectors/entities/posts';
|
||||
import {memoizeResult} from 'mattermost-redux/utils/helpers';
|
||||
|
||||
import {
|
||||
|
|
@ -30,10 +31,12 @@ const POST_TIMEOUT = 20000;
|
|||
|
||||
function makeMapStateToProps() {
|
||||
const memoizeHasEmojisOnly = memoizeResult((message, customEmojis) => hasEmojisOnly(message, customEmojis));
|
||||
const getReactionsForPost = makeGetReactionsForPost();
|
||||
|
||||
return (state, ownProps) => {
|
||||
const post = ownProps.post;
|
||||
const channel = getChannel(state, post.channel_id) || {};
|
||||
const reactions = getReactionsForPost(state, post.id);
|
||||
|
||||
let isFailed = post.failed;
|
||||
let isPending = post.id === post.pending_post_id;
|
||||
|
|
@ -83,7 +86,7 @@ function makeMapStateToProps() {
|
|||
fileIds: post.file_ids,
|
||||
hasBeenDeleted: post.state === Posts.POST_DELETED,
|
||||
hasBeenEdited: isEdited(post),
|
||||
hasReactions: post.has_reactions,
|
||||
hasReactions: (reactions && Object.keys(reactions).length > 0) || Boolean(post.has_reactions),
|
||||
isFailed,
|
||||
isPending,
|
||||
isPostAddChannelMember,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
import {bindActionCreators} from 'redux';
|
||||
import {connect} from 'react-redux';
|
||||
|
||||
import {selectPost} from 'mattermost-redux/actions/posts';
|
||||
import {selectPost, makeGetReactionsForPost} from 'mattermost-redux/actions/posts';
|
||||
import {makeGetChannel} from 'mattermost-redux/selectors/entities/channels';
|
||||
import {getPost} from 'mattermost-redux/selectors/entities/posts';
|
||||
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
|
||||
|
|
@ -15,14 +15,16 @@ import LongPost from './long_post';
|
|||
|
||||
function makeMapStateToProps() {
|
||||
const getChannel = makeGetChannel();
|
||||
const getReactionsForPost = makeGetReactionsForPost();
|
||||
|
||||
return function mapStateToProps(state, ownProps) {
|
||||
const post = getPost(state, ownProps.postId);
|
||||
const channel = post ? getChannel(state, {id: post.channel_id}) : null;
|
||||
const reactions = getReactionsForPost(state, post.id);
|
||||
|
||||
return {
|
||||
channelName: channel ? channel.display_name : '',
|
||||
hasReactions: post ? post.has_reactions : false,
|
||||
hasReactions: (reactions && Object.keys(reactions).length > 0) || Boolean(post.has_reactions),
|
||||
inThreadView: Boolean(state.entities.posts.selectedPostId),
|
||||
fileIds: post ? post.file_ids : false,
|
||||
theme: getTheme(state),
|
||||
|
|
|
|||
Loading…
Reference in a new issue