RN-203 Fixed RestrictDirectMessages setting not applying in RN app (#697)

* RN-203 Fixed RestrictDirectMessages setting not applying to MoreDirectMessages

* Removed unused prop from MoreDirectMessages

* RN-203 Fixed RestrictDirectMessages setting not applying to FilteredList

* Removed unused propTypes from FilteredList
This commit is contained in:
Harrison Healey 2017-07-04 10:00:06 -04:00 committed by enahum
parent 12e7f26083
commit 8c7433d7e2
4 changed files with 110 additions and 45 deletions

View file

@ -22,7 +22,7 @@ import {displayUsername} from 'mattermost-redux/utils/user_utils';
import ChannelDrawerItem from 'app/components/channel_drawer/channels_list/channel_item';
class ChannelDrawerList extends Component {
class FilteredList extends Component {
static propTypes = {
actions: PropTypes.shape({
makeGroupMessageVisibleIfNecessary: PropTypes.func.isRequired,
@ -30,22 +30,18 @@ class ChannelDrawerList extends Component {
searchProfiles: PropTypes.func.isRequired
}).isRequired,
channels: PropTypes.object.isRequired,
channelMembers: PropTypes.object,
currentTeam: PropTypes.object.isRequired,
currentUserId: PropTypes.string,
currentChannel: PropTypes.object,
groupChannels: PropTypes.array,
intl: intlShape.isRequired,
myPreferences: PropTypes.object,
myTeamMembers: PropTypes.object.isRequired,
navigator: PropTypes.object,
onSearchEnds: PropTypes.func.isRequired,
onSearchStart: PropTypes.func.isRequired,
onSelectChannel: PropTypes.func.isRequired,
onShowTeams: PropTypes.func.isRequired,
otherChannels: PropTypes.array,
profiles: PropTypes.object,
profilesInChannel: PropTypes.object,
profiles: PropTypes.oneOfType(
PropTypes.object,
PropTypes.array
),
statuses: PropTypes.object,
styles: PropTypes.object.isRequired,
term: PropTypes.string,
@ -143,7 +139,7 @@ class ChannelDrawerList extends Component {
const unreads = this.filterChannels(unreadChannels, term);
const channels = this.filterChannels([...favorites, ...publicChannels, ...privateChannels], term).
sort(sortChannelsByDisplayName.bind(null, props.intl.locale));
sort(sortChannelsByDisplayName.bind(null, props.intl.locale));
const others = this.filterChannels(notMemberOf, term);
const groups = this.filterChannels(groupChannels, term);
@ -286,4 +282,4 @@ class ChannelDrawerList extends Component {
}
}
export default injectIntl(ChannelDrawerList);
export default injectIntl(FilteredList);

View file

@ -7,8 +7,10 @@ import {connect} from 'react-redux';
import {searchChannels} from 'mattermost-redux/actions/channels';
import {searchProfiles} from 'mattermost-redux/actions/users';
import {makeGroupMessageVisibleIfNecessary} from 'mattermost-redux/actions/preferences';
import {getUserIdsInChannels, getUsers, getUserStatuses} from 'mattermost-redux/selectors/entities/users';
import {General} from 'mattermost-redux/constants';
import {getGroupChannels, getOtherChannels} from 'mattermost-redux/selectors/entities/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getProfilesInCurrentTeam, getUsers, getUserStatuses} from 'mattermost-redux/selectors/entities/users';
import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences';
import FilteredList from './filtered_list';
@ -16,12 +18,18 @@ import FilteredList from './filtered_list';
function mapStateToProps(state, ownProps) {
const {currentUserId} = state.entities.users;
let profiles;
if (getConfig(state).RestrictDirectMessage === General.RESTRICT_DIRECT_MESSAGE_ANY) {
profiles = getUsers(state);
} else {
profiles = getProfilesInCurrentTeam(state);
}
return {
currentUserId,
otherChannels: getOtherChannels(state),
groupChannels: getGroupChannels(state),
profiles: getUsers(state),
profilesInChannel: getUserIdsInChannels(state),
profiles,
myPreferences: getMyPreferences(state),
statuses: getUserStatuses(state),
...ownProps

View file

@ -3,39 +3,68 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {createSelector} from 'reselect';
import {setChannelDisplayName} from 'app/actions/views/channel';
import {makeDirectChannel} from 'app/actions/views/more_dms';
import {getTheme} from 'app/selectors/preferences';
import {getProfiles, searchProfiles} from 'mattermost-redux/actions/users';
import {getProfiles, getProfilesInTeam, searchProfiles} from 'mattermost-redux/actions/users';
import {General} from 'mattermost-redux/constants';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentUserId, getProfilesInCurrentTeam, getUsers} from 'mattermost-redux/selectors/entities/users';
import MoreDirectMessages from './more_dms';
function sortAndRemoveCurrentUser(profiles, currentUserId) {
const users = {...profiles};
Reflect.deleteProperty(users, currentUserId);
return Object.values(users).sort((a, b) => {
const nameA = a.username;
const nameB = b.username;
return nameA.localeCompare(nameB);
});
}
const getUsersInCurrentTeamForMoreDirectMessages = createSelector(
getProfilesInCurrentTeam,
getCurrentUserId,
sortAndRemoveCurrentUser
);
const getUsersForMoreDirectMessages = createSelector(
getUsers,
getCurrentUserId,
sortAndRemoveCurrentUser
);
function mapStateToProps(state, ownProps) {
const {getProfiles: requestStatus, searchProfiles: searchRequest} = state.requests.users;
const {createChannel: createChannelRequest} = state.requests.channels;
const {searchProfiles: searchRequest} = state.requests.users;
function getUsers() {
const {profiles, currentUserId} = state.entities.users;
const users = {...profiles};
Reflect.deleteProperty(users, currentUserId);
return Object.values(users).sort((a, b) => {
const nameA = a.username;
const nameB = b.username;
const config = getConfig(state);
return nameA.localeCompare(nameB);
});
let getRequest;
let profiles;
if (config.RestrictDirectMessage === General.RESTRICT_DIRECT_MESSAGE_ANY) {
getRequest = state.requests.users.getProfiles;
profiles = getUsersForMoreDirectMessages(state);
} else {
getRequest = state.requests.users.getProfilesInTeam;
profiles = getUsersInCurrentTeamForMoreDirectMessages(state);
}
return {
...ownProps,
config,
preferences: getMyPreferences(state),
profiles: getUsers(),
profiles,
theme: getTheme(state),
currentDisplayName: state.views.channel.displayName,
createChannelRequest,
requestStatus,
currentTeamId: getCurrentTeamId(state),
getRequest,
searchRequest
};
}
@ -45,6 +74,7 @@ function mapDispatchToProps(dispatch) {
actions: bindActionCreators({
makeDirectChannel,
getProfiles,
getProfilesInTeam,
searchProfiles,
setChannelDisplayName
}, dispatch)

View file

@ -27,15 +27,17 @@ class MoreDirectMessages extends PureComponent {
currentDisplayName: PropTypes.string,
intl: intlShape.isRequired,
navigator: PropTypes.object,
config: PropTypes.object.isRequired,
currentTeamId: PropTypes.string.isRequired,
preferences: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
profiles: PropTypes.array,
createChannelRequest: PropTypes.object.isRequired,
requestStatus: PropTypes.object.isRequired,
getRequest: PropTypes.object.isRequired,
searchRequest: PropTypes.object.isRequired,
actions: PropTypes.shape({
makeDirectChannel: PropTypes.func.isRequired,
getProfiles: PropTypes.func.isRequired,
getProfilesInTeam: PropTypes.func.isRequired,
searchProfiles: PropTypes.func.isRequired,
setChannelDisplayName: PropTypes.func.isRequired
}).isRequired
@ -59,9 +61,9 @@ class MoreDirectMessages extends PureComponent {
}
componentWillReceiveProps(nextProps) {
const {requestStatus} = this.props;
if (requestStatus.status === RequestStatus.STARTED &&
nextProps.requestStatus.status === RequestStatus.SUCCESS) {
const {getRequest} = this.props;
if (getRequest.status === RequestStatus.STARTED &&
nextProps.getRequest.status === RequestStatus.SUCCESS) {
const {page} = this.state;
const profiles = nextProps.profiles.splice(0, (page + 1) * General.PROFILE_CHUNK_SIZE);
this.setState({profiles, showNoResults: true});
@ -76,7 +78,7 @@ class MoreDirectMessages extends PureComponent {
// set the timeout to 400 cause is the time that the modal takes to open
// Somehow interactionManager doesn't care
setTimeout(() => {
this.props.actions.getProfiles(0);
this.getProfiles(0);
}, 400);
}
@ -94,7 +96,7 @@ class MoreDirectMessages extends PureComponent {
}
};
searchProfiles = (text) => {
onSearch = (text) => {
const term = text.toLowerCase();
if (term) {
@ -102,7 +104,7 @@ class MoreDirectMessages extends PureComponent {
clearTimeout(this.searchTimeoutId);
this.searchTimeoutId = setTimeout(() => {
this.props.actions.searchProfiles(term);
this.searchProfiles(term);
}, General.SEARCH_TIMEOUT_MILLISECONDS);
} else {
this.cancelSearch();
@ -118,12 +120,27 @@ class MoreDirectMessages extends PureComponent {
});
};
getProfiles = (page) => {
if (this.props.config.RestrictDirectMessage === General.RESTRICT_DIRECT_MESSAGE_ANY) {
return this.props.actions.getProfiles(page, General.PROFILE_CHUNK_SIZE);
}
return this.props.actions.getProfilesInTeam(page, General.PROFILE_CHUNK_SIZE);
};
searchProfiles = (term) => {
if (this.props.config.RestrictDirectMessage === General.RESTRICT_DIRECT_MESSAGE_ANY) {
return this.props.actions.searchProfiles(term);
}
return this.props.actions.searchProfiles(term, {team_id: this.props.currentTeamId});
};
loadMoreProfiles = () => {
let {page} = this.state;
if (this.props.requestStatus.status !== RequestStatus.STARTED && this.state.next && !this.state.searching) {
if (this.props.getRequest.status !== RequestStatus.STARTED && this.state.next && !this.state.searching) {
page = page + 1;
this.props.actions.getProfiles(page, General.PROFILE_CHUNK_SIZE).
then((data) => {
this.getProfiles(page).then((data) => {
if (data && data.length) {
this.setState({
page
@ -177,10 +194,24 @@ class MoreDirectMessages extends PureComponent {
};
render() {
const {intl, preferences, requestStatus, searchRequest, theme} = this.props;
const {adding, profiles, searching, showNoResults, term} = this.state;
const {
intl,
preferences,
getRequest,
searchRequest,
theme
} = this.props;
const {
adding,
profiles,
searching,
showNoResults,
term
} = this.state;
const {formatMessage} = intl;
const isLoading = (requestStatus.status === RequestStatus.STARTED) || (requestStatus.status === RequestStatus.NOT_STARTED) ||
const isLoading = (
getRequest.status === RequestStatus.STARTED) || (getRequest.status === RequestStatus.NOT_STARTED) ||
(searchRequest.status === RequestStatus.STARTED);
const style = getStyleFromTheme(theme);
const more = this.state.searching ? () => true : this.loadMoreProfiles;
@ -215,8 +246,8 @@ class MoreDirectMessages extends PureComponent {
tintColorSearch={changeOpacity(theme.centerChannelColor, 0.8)}
tintColorDelete={changeOpacity(theme.centerChannelColor, 0.5)}
titleCancelColor={theme.centerChannelColor}
onChangeText={this.searchProfiles}
onSearchButtonPress={this.searchProfiles}
onChangeText={this.onSearch}
onSearchButtonPress={this.onSearch}
onCancelButtonPress={this.cancelSearch}
value={term}
/>