forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
149 lines (127 loc) · 6.1 KB
/
index.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {isCurrentUserSystemAdmin} from 'mattermost-redux/selectors/entities/users';
import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles';
import {getBool} from 'mattermost-redux/selectors/entities/preferences';
import {getAllChannelStats} from 'mattermost-redux/selectors/entities/channels';
import {makeGetMessageInHistoryItem} from 'mattermost-redux/selectors/entities/posts';
import {resetCreatePostRequest, resetHistoryIndex} from 'mattermost-redux/actions/posts';
import {getChannelTimezones} from 'mattermost-redux/actions/channels';
import {Permissions, Preferences, Posts} from 'mattermost-redux/constants';
import {connectionErrorCount} from 'selectors/views/system';
import {Constants, StoragePrefixes} from 'utils/constants';
import {getCurrentLocale} from 'selectors/i18n';
import {
clearCommentDraftUploads,
updateCommentDraft,
makeOnMoveHistoryIndex,
makeOnSubmit,
makeOnEditLatestPost,
} from 'actions/views/create_comment';
import {emitShortcutReactToLastPostFrom} from 'actions/post_actions';
import {getPostDraft, getIsRhsExpanded, getSelectedPostFocussedAt} from 'selectors/rhs';
import {showPreviewOnCreateComment} from 'selectors/views/textbox';
import {setShowPreviewOnCreateComment} from 'actions/views/textbox';
import CreateComment from './create_comment.jsx';
function makeMapStateToProps() {
const getMessageInHistoryItem = makeGetMessageInHistoryItem(Posts.MESSAGE_TYPES.COMMENT);
return (state, ownProps) => {
const err = state.requests.posts.createPost.error || {};
const draft = getPostDraft(state, StoragePrefixes.COMMENT_DRAFT, ownProps.rootId);
const enableAddButton = draft.message.trim().length !== 0 || draft.fileInfos.length !== 0;
const channelMembersCount = getAllChannelStats(state)[ownProps.channelId] ? getAllChannelStats(state)[ownProps.channelId].member_count : 1;
const messageInHistory = getMessageInHistoryItem(state);
const channel = state.entities.channels.channels[ownProps.channelId] || {};
const config = getConfig(state);
const enableConfirmNotificationsToChannel = config.EnableConfirmNotificationsToChannel === 'true';
const enableEmojiPicker = config.EnableEmojiPicker === 'true';
const enableGifPicker = config.EnableGifPicker === 'true';
const badConnection = connectionErrorCount(state) > 1;
const isTimezoneEnabled = config.ExperimentalTimezone === 'true';
const canPost = haveIChannelPermission(
state,
{
channel: channel.id,
team: channel.team_id,
permission: Permissions.CREATE_POST,
}
);
const useChannelMentions = haveIChannelPermission(state, {
channel: channel.id,
team: channel.team_id,
permission: Permissions.USE_CHANNEL_MENTIONS,
});
return {
draft,
messageInHistory,
enableAddButton,
channelMembersCount,
codeBlockOnCtrlEnter: getBool(state, Preferences.CATEGORY_ADVANCED_SETTINGS, 'code_block_ctrl_enter', true),
ctrlSend: getBool(state, Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'),
createPostErrorId: err.server_error_id,
readOnlyChannel: !isCurrentUserSystemAdmin(state) && config.ExperimentalTownSquareIsReadOnly === 'true' && channel.name === Constants.DEFAULT_CHANNEL,
enableConfirmNotificationsToChannel,
enableEmojiPicker,
enableGifPicker,
locale: getCurrentLocale(state),
maxPostSize: parseInt(config.MaxPostSize, 10) || Constants.DEFAULT_CHARACTER_LIMIT,
rhsExpanded: getIsRhsExpanded(state),
badConnection,
isTimezoneEnabled,
selectedPostFocussedAt: getSelectedPostFocussedAt(state),
canPost,
useChannelMentions,
shouldShowPreview: showPreviewOnCreateComment(state),
};
};
}
function makeOnUpdateCommentDraft(rootId) {
return (draft) => updateCommentDraft(rootId, draft);
}
function makeMapDispatchToProps() {
let onUpdateCommentDraft;
let onSubmit;
let onMoveHistoryIndexBack;
let onMoveHistoryIndexForward;
let onEditLatestPost;
function onResetHistoryIndex() {
return resetHistoryIndex(Posts.MESSAGE_TYPES.COMMENT);
}
let rootId;
let channelId;
let latestPostId;
return (dispatch, ownProps) => {
if (rootId !== ownProps.rootId) {
onUpdateCommentDraft = makeOnUpdateCommentDraft(ownProps.rootId);
onMoveHistoryIndexBack = makeOnMoveHistoryIndex(ownProps.rootId, -1);
onMoveHistoryIndexForward = makeOnMoveHistoryIndex(ownProps.rootId, 1);
}
if (rootId !== ownProps.rootId || channelId !== ownProps.channelId) {
onEditLatestPost = makeOnEditLatestPost(ownProps.channelId, ownProps.rootId);
}
if (rootId !== ownProps.rootId || channelId !== ownProps.channelId || latestPostId !== ownProps.latestPostId) {
onSubmit = makeOnSubmit(ownProps.channelId, ownProps.rootId, ownProps.latestPostId);
}
rootId = ownProps.rootId;
channelId = ownProps.channelId;
latestPostId = ownProps.latestPostId;
return bindActionCreators({
clearCommentDraftUploads,
onUpdateCommentDraft,
updateCommentDraftWithRootId: updateCommentDraft,
onSubmit,
onResetHistoryIndex,
onMoveHistoryIndexBack,
onMoveHistoryIndexForward,
onEditLatestPost,
resetCreatePostRequest,
getChannelTimezones,
emitShortcutReactToLastPostFrom,
setShowPreview: setShowPreviewOnCreateComment,
}, dispatch);
};
}
export default connect(makeMapStateToProps, makeMapDispatchToProps)(CreateComment);