This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
index.js
60 lines (48 loc) · 2.08 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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {withRouter} from 'react-router-dom';
import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {getUser} from 'mattermost-redux/selectors/entities/users';
import {getTeamByName, getTeamMemberships} from 'mattermost-redux/selectors/entities/teams';
import {Constants} from 'utils/constants';
import PostView from './post_view.jsx';
export const isChannelLoading = (params, channel, team, teammate, teamMemberships) => {
if (params.postid) {
return false;
}
if (channel && team) {
if (channel.type !== Constants.DM_CHANNEL && channel.name !== params.identifier) {
return true;
} else if (channel.type === Constants.DM_CHANNEL && teammate && params.identifier !== `@${teammate.username}`) {
return true;
}
const teamId = team.id;
if ((channel.team_id && channel.team_id !== teamId) || (teamMemberships && !teamMemberships[teamId])) {
return true;
}
return false;
}
return true;
};
function makeMapStateToProps() {
return function mapStateToProps(state, ownProps) {
const team = getTeamByName(state, ownProps.match.params.team);
let teammate;
const channel = getChannel(state, ownProps.channelId);
let lastViewedAt = state.views.channel.lastChannelViewTime[ownProps.channelId];
if (channel) {
if (channel.type === Constants.DM_CHANNEL && channel.teammate_id) {
teammate = getUser(state, channel.teammate_id);
}
lastViewedAt = channel.last_post_at ? lastViewedAt : channel.last_post_at;
}
const teamMemberships = getTeamMemberships(state);
const channelLoading = isChannelLoading(ownProps.match.params, channel, team, teammate, teamMemberships);
return {
lastViewedAt,
channelLoading,
};
};
}
export default withRouter(connect(makeMapStateToProps)(PostView));