forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
73 lines (58 loc) · 2.6 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {createSelector} from 'reselect';
import {Preferences} from 'mattermost-redux/constants';
import {getChannelNameToDisplayNameMap} from 'mattermost-redux/selectors/entities/channels';
import {getAutolinkedUrlSchemes, getConfig, getManagedResourcePaths} from 'mattermost-redux/selectors/entities/general';
import {getBool} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {getAllUserMentionKeys} from 'mattermost-redux/selectors/entities/search';
import {GlobalState} from 'mattermost-redux/types/store';
import {getEmojiMap} from 'selectors/emojis';
import {getSiteURL} from 'utils/url';
import {ChannelNamesMap, MentionKey} from 'utils/text_formatting';
import {getPost} from 'mattermost-redux/selectors/entities/posts';
import Markdown from './markdown';
type Props = {
channelNamesMap?: ChannelNamesMap;
mentionKeys?: MentionKey[];
postId?: string;
}
function makeGetChannelNamesMap() {
return createSelector(
'makeGetChannelNamesMap',
getChannelNameToDisplayNameMap,
(state: GlobalState, props: Props) => props && props.channelNamesMap,
(channelNamesMap, channelMentions) => {
if (channelMentions) {
return Object.assign({}, channelMentions, channelNamesMap);
}
return channelNamesMap;
},
);
}
function makeMapStateToProps() {
const getChannelNamesMap = makeGetChannelNamesMap();
return function mapStateToProps(state: GlobalState, ownProps: Props) {
const config = getConfig(state);
let channelId;
if (ownProps.postId) {
channelId = getPost(state, ownProps.postId)?.channel_id;
}
return {
autolinkedUrlSchemes: getAutolinkedUrlSchemes(state),
channelNamesMap: getChannelNamesMap(state, ownProps),
enableFormatting: getBool(state, Preferences.CATEGORY_ADVANCED_SETTINGS, 'formatting', true),
managedResourcePaths: getManagedResourcePaths(state),
mentionKeys: ownProps.mentionKeys || getAllUserMentionKeys(state),
siteURL: getSiteURL(),
team: getCurrentTeam(state),
hasImageProxy: config.HasImageProxy === 'true',
minimumHashtagLength: parseInt(config.MinimumHashtagLength || '', 10),
emojiMap: getEmojiMap(state),
channelId,
};
};
}
export default connect(makeMapStateToProps)(Markdown);