forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
106 lines (98 loc) · 4.89 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
// 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 {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentChannel, getCurrentChannelStats} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentUserId, isCurrentUserSystemAdmin, getStatusForUserId} from 'mattermost-redux/selectors/entities/users';
import {get, getInt, getBool} from 'mattermost-redux/selectors/entities/preferences';
import {
getCurrentUsersLatestPost,
getLatestReplyablePostId,
getMostRecentPostIdInChannel,
getPost,
makeGetCommentCountForPost,
makeGetMessageInHistoryItem,
} from 'mattermost-redux/selectors/entities/posts';
import {
addMessageIntoHistory,
moveHistoryIndexBack,
moveHistoryIndexForward,
addReaction,
removeReaction,
} from 'mattermost-redux/actions/posts';
import {Posts} from 'mattermost-redux/constants';
import {emitUserPostedEvent, postListScrollChangeToBottom} from 'actions/global_actions.jsx';
import {createPost, setEditingPost} from 'actions/post_actions.jsx';
import {selectPostFromRightHandSideSearchByPostId} from 'actions/views/rhs';
import {getPostDraft} from 'selectors/rhs';
import {setGlobalItem, actionOnGlobalItemsWithPrefix} from 'actions/storage';
import {openModal} from 'actions/views/modals';
import {Constants, Preferences, StoragePrefixes, TutorialSteps, UserStatuses} from 'utils/constants.jsx';
import {canUploadFiles} from 'utils/file_utils';
import CreatePost from './create_post.jsx';
function mapStateToProps() {
return (state) => {
const config = getConfig(state);
const currentChannel = getCurrentChannel(state) || {};
const draft = getPostDraft(state, StoragePrefixes.DRAFT, currentChannel.id);
const recentPostIdInChannel = getMostRecentPostIdInChannel(state, currentChannel.id);
const post = getPost(state, recentPostIdInChannel);
const getCommentCountForPost = makeGetCommentCountForPost();
const latestReplyablePostId = getLatestReplyablePostId(state);
const currentChannelMembersCount = getCurrentChannelStats(state) ? getCurrentChannelStats(state).member_count : 1;
const enableTutorial = config.EnableTutorial === 'true';
const tutorialStep = getInt(state, Preferences.TUTORIAL_STEP, getCurrentUserId(state), TutorialSteps.FINISHED);
const enableEmojiPicker = config.EnableEmojiPicker === 'true';
const enableConfirmNotificationsToChannel = config.EnableConfirmNotificationsToChannel === 'true';
const currentUserId = getCurrentUserId(state);
const userIsOutOfOffice = getStatusForUserId(state, currentUserId) === UserStatuses.OUT_OF_OFFICE;
return {
currentTeamId: getCurrentTeamId(state),
currentChannel,
currentChannelMembersCount,
currentUserId,
ctrlSend: getBool(state, Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'),
fullWidthTextBox: get(state, Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.CHANNEL_DISPLAY_MODE, Preferences.CHANNEL_DISPLAY_MODE_DEFAULT) === Preferences.CHANNEL_DISPLAY_MODE_FULL_SCREEN,
showTutorialTip: enableTutorial && tutorialStep === TutorialSteps.POST_POPOVER,
messageInHistoryItem: makeGetMessageInHistoryItem(Posts.MESSAGE_TYPES.POST)(state),
draft,
recentPostIdInChannel,
commentCountForPost: getCommentCountForPost(state, {post}),
latestReplyablePostId,
currentUsersLatestPost: getCurrentUsersLatestPost(state),
readOnlyChannel: !isCurrentUserSystemAdmin(state) && config.ExperimentalTownSquareIsReadOnly === 'true' && currentChannel.name === Constants.DEFAULT_CHANNEL,
canUploadFiles: canUploadFiles(config),
enableEmojiPicker,
enableConfirmNotificationsToChannel,
maxPostSize: parseInt(config.MaxPostSize, 10) || Constants.DEFAULT_CHARACTER_LIMIT,
userIsOutOfOffice,
};
};
}
function onSubmitPost(post, fileInfos) {
return () => {
emitUserPostedEvent(post);
createPost(post, fileInfos);
postListScrollChangeToBottom();
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
addMessageIntoHistory,
onSubmitPost,
moveHistoryIndexBack,
moveHistoryIndexForward,
addReaction,
removeReaction,
setDraft: setGlobalItem,
clearDraftUploads: actionOnGlobalItemsWithPrefix,
selectPostFromRightHandSideSearchByPostId,
setEditingPost,
openModal,
}, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(CreatePost);