* [#MM-12410] Custom Terms of Service Modal. - Create a new screen for terms of service - Register it in app navigation - Open it as a modal when login succeeds or app is opened when already logged in. - Get terms of service and render it as markdown * Refactor service terms to terms of service * Show terms modal when launching channel instead of componentDidMount * Remove footer text * Close modal before logging out * Use dismissAllModals instead od this.close * Update header styles * Update the back icon * Add left icon conditinally based on os * Update en.json * - Integrate Accept/Reject API - Refactor show navigator to util - Remove title - Code refactoring * Handle Accept/Reject API errors * Update package-lock * - Show Alert to handle API error - Handle API error for GetTerms error, Accept/Reject error and Reject success - Changes in en.json - Remove error banner - Open terms modal in sso and experimental certificate * Enable navigator buttons after getting terms * Rename Ok to OK in Alert * Add retry for API error * Fix check-style * Fix FailedNetworkAction Error Message * - Use Close button instead of back button - Update en.json * Remove unused import * Disable hashtags and atmentions in terms modal * Enable close button when terms text fails to load * Minor changes * Fix show terms on sso login * Handle restartApp event * Add test cases * Revert change to app/components/formatted_markdown_text.js * Show the terms modal on the channel page * Remove remaining references to showTermsOfService * Disable Hashtags, AtMentions and ChannelLinks * Update the props to markdown component * Pass the text as literal to renderText * Return the generated renderTexts * Fix lint * Render ~, #, @ with Channel link, Hashtags and At Mentions * Fix failing tests Revert unwanted changes * Hide the channel page content before the terms are accepted * Fix lint and failing tests * Revert changes to hide channel while terms are not accepted * Open modal in componentDidMount instead of constructor Code refactoring Disable back button on android * Remove unused import * No need to await for showModal * No need to await for accept and reject * Update flag for updateTermsOfServiceStatus to updateMyTermsOfServiceStatus - as phase 2 redux PR was mered. * Fix check-style * Change opacity in terms of service text - Fix tests * Revert package-lock.json changes
191 lines
5.5 KiB
JavaScript
191 lines
5.5 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {PureComponent} from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import {Platform} from 'react-native';
|
|
import {intlShape} from 'react-intl';
|
|
import {General, RequestStatus} from 'mattermost-redux/constants';
|
|
|
|
import Loading from 'app/components/loading';
|
|
import KeyboardLayout from 'app/components/layout/keyboard_layout';
|
|
import PostList from 'app/components/post_list';
|
|
import PostTextbox from 'app/components/post_textbox';
|
|
import SafeAreaView from 'app/components/safe_area_view';
|
|
import StatusBar from 'app/components/status_bar';
|
|
import {makeStyleSheetFromTheme, setNavigatorStyles} from 'app/utils/theme';
|
|
import DeletedPost from 'app/components/deleted_post';
|
|
|
|
export default class Thread extends PureComponent {
|
|
static propTypes = {
|
|
actions: PropTypes.shape({
|
|
selectPost: PropTypes.func.isRequired,
|
|
}).isRequired,
|
|
channelId: PropTypes.string.isRequired,
|
|
channelType: PropTypes.string,
|
|
displayName: PropTypes.string,
|
|
navigator: PropTypes.object,
|
|
myMember: PropTypes.object.isRequired,
|
|
rootId: PropTypes.string.isRequired,
|
|
theme: PropTypes.object.isRequired,
|
|
postIds: PropTypes.array.isRequired,
|
|
channelIsArchived: PropTypes.bool,
|
|
threadLoadingStatus: PropTypes.object,
|
|
};
|
|
|
|
state = {};
|
|
|
|
static contextTypes = {
|
|
intl: intlShape,
|
|
};
|
|
|
|
componentWillMount() {
|
|
const {channelType, displayName} = this.props;
|
|
const {intl} = this.context;
|
|
let title;
|
|
|
|
if (channelType === General.DM_CHANNEL) {
|
|
title = intl.formatMessage({id: 'mobile.routes.thread_dm', defaultMessage: 'Direct Message Thread'});
|
|
} else {
|
|
title = intl.formatMessage({id: 'mobile.routes.thread', defaultMessage: '{channelName} Thread'}, {channelName: displayName});
|
|
}
|
|
|
|
this.props.navigator.setTitle({
|
|
title,
|
|
});
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
if (this.props.theme !== nextProps.theme) {
|
|
setNavigatorStyles(this.props.navigator, nextProps.theme);
|
|
}
|
|
|
|
if (this.props.postIds !== nextProps.postIds && !nextProps.postIds.length) {
|
|
this.close();
|
|
return;
|
|
}
|
|
|
|
if (!this.state.lastViewedAt) {
|
|
this.setState({lastViewedAt: nextProps.myMember.last_viewed_at});
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.props.actions.selectPost('');
|
|
}
|
|
|
|
close = () => {
|
|
const {navigator} = this.props;
|
|
|
|
if (Platform.OS === 'ios') {
|
|
navigator.pop({
|
|
animated: true,
|
|
});
|
|
} else {
|
|
navigator.dismissModal({
|
|
animationType: 'slide-down',
|
|
});
|
|
}
|
|
};
|
|
|
|
hasRootPost = () => {
|
|
return this.props.postIds.includes(this.props.rootId);
|
|
};
|
|
|
|
renderFooter = () => {
|
|
if (!this.hasRootPost() && this.props.threadLoadingStatus.status !== RequestStatus.STARTED) {
|
|
return (
|
|
<DeletedPost theme={this.props.theme}/>
|
|
);
|
|
} else if (this.props.threadLoadingStatus.status === RequestStatus.STARTED) {
|
|
return (
|
|
<Loading/>
|
|
);
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
onCloseChannel = () => {
|
|
this.props.navigator.resetTo({
|
|
screen: 'Channel',
|
|
title: '',
|
|
animated: false,
|
|
backButtonTitle: '',
|
|
navigatorStyle: {
|
|
animated: true,
|
|
animationType: 'fade',
|
|
navBarHidden: true,
|
|
statusBarHidden: false,
|
|
statusBarHideWithNavBar: false,
|
|
screenBackgroundColor: 'transparent',
|
|
},
|
|
passProps: {
|
|
disableTermsModal: true,
|
|
},
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const {
|
|
channelId,
|
|
myMember,
|
|
navigator,
|
|
postIds,
|
|
rootId,
|
|
theme,
|
|
channelIsArchived,
|
|
} = this.props;
|
|
const style = getStyle(theme);
|
|
let content;
|
|
let postTextBox;
|
|
if (this.hasRootPost()) {
|
|
content = (
|
|
<PostList
|
|
renderFooter={this.renderFooter()}
|
|
indicateNewMessages={true}
|
|
postIds={postIds}
|
|
currentUserId={myMember.user_id}
|
|
lastViewedAt={this.state.lastViewedAt}
|
|
navigator={navigator}
|
|
/>
|
|
);
|
|
|
|
postTextBox = (
|
|
<PostTextbox
|
|
channelIsArchived={channelIsArchived}
|
|
rootId={rootId}
|
|
channelId={channelId}
|
|
navigator={navigator}
|
|
onCloseChannel={this.onCloseChannel}
|
|
/>
|
|
);
|
|
} else {
|
|
content = (
|
|
<Loading/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<SafeAreaView
|
|
excludeHeader={true}
|
|
keyboardOffset={20}
|
|
>
|
|
<StatusBar/>
|
|
<KeyboardLayout style={style.container}>
|
|
{content}
|
|
{postTextBox}
|
|
</KeyboardLayout>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
}
|
|
|
|
const getStyle = makeStyleSheetFromTheme((theme) => {
|
|
return {
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: theme.centerChannelBg,
|
|
},
|
|
};
|
|
});
|