diff --git a/app/components/at_mention/at_mention.js b/app/components/at_mention/at_mention.js index d39351fd4..1b4605daa 100644 --- a/app/components/at_mention/at_mention.js +++ b/app/components/at_mention/at_mention.js @@ -97,9 +97,9 @@ export default class AtMention extends React.PureComponent { handleLongPress = async () => { const {formatMessage} = this.context.intl; - const config = await mattermostManaged.getLocalConfig(); + const config = mattermostManaged.getCachedConfig(); - if (config.copyAndPasteProtection !== 'false') { + if (config.copyAndPasteProtection !== 'true') { const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'}); const actionText = formatMessage({id: 'mobile.mention.copy_mention', defaultMessage: 'Copy Mention'}); diff --git a/app/components/markdown/markdown_code_block/markdown_code_block.js b/app/components/markdown/markdown_code_block/markdown_code_block.js index 2cdace7ca..73666c348 100644 --- a/app/components/markdown/markdown_code_block/markdown_code_block.js +++ b/app/components/markdown/markdown_code_block/markdown_code_block.js @@ -82,7 +82,7 @@ export default class MarkdownCodeBlock extends React.PureComponent { handleLongPress = async () => { const {formatMessage} = this.context.intl; - const config = await mattermostManaged.getLocalConfig(); + const config = mattermostManaged.getCachedConfig(); if (config.copyAndPasteProtection !== 'true') { const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'}); diff --git a/app/components/markdown/markdown_image/markdown_image.js b/app/components/markdown/markdown_image/markdown_image.js index a99d7f3ec..4e9700f21 100644 --- a/app/components/markdown/markdown_image/markdown_image.js +++ b/app/components/markdown/markdown_image/markdown_image.js @@ -144,7 +144,7 @@ export default class MarkdownImage extends React.Component { handleLinkLongPress = async () => { const {formatMessage} = this.context.intl; - const config = await mattermostManaged.getLocalConfig(); + const config = mattermostManaged.getCachedConfig(); if (config.copyAndPasteProtection !== 'true') { const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'}); diff --git a/app/components/markdown/markdown_link/markdown_link.js b/app/components/markdown/markdown_link/markdown_link.js index 1c60de74c..20a00badb 100644 --- a/app/components/markdown/markdown_link/markdown_link.js +++ b/app/components/markdown/markdown_link/markdown_link.js @@ -99,7 +99,7 @@ export default class MarkdownLink extends PureComponent { handleLongPress = async () => { const {formatMessage} = this.context.intl; - const config = await mattermostManaged.getLocalConfig(); + const config = mattermostManaged.getCachedConfig(); if (config.copyAndPasteProtection !== 'true') { const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'}); diff --git a/app/components/post_list/post_list_base.js b/app/components/post_list/post_list_base.js index 5bed007fb..cf3b4afd8 100644 --- a/app/components/post_list/post_list_base.js +++ b/app/components/post_list/post_list_base.js @@ -57,15 +57,6 @@ export default class PostListBase extends PureComponent { siteURL: '', }; - componentWillMount() { - this.listenerId = mattermostManaged.addEventListener('managedConfigDidChange', this.setManagedConfig); - } - - componentDidMount() { - this.mounted = true; - this.setManagedConfig(); - } - componentDidUpdate() { if (this.props.deepLinkURL) { this.handleDeepLink(this.props.deepLinkURL); @@ -73,11 +64,6 @@ export default class PostListBase extends PureComponent { } } - componentWillUnmount() { - this.mounted = false; - mattermostManaged.removeEventListener(this.listenerId); - } - handleClosePermalink = () => { const {actions} = this.props; actions.selectFocusedPostId(''); @@ -173,7 +159,6 @@ export default class PostListBase extends PureComponent { shouldRenderReplyButton, location, } = this.props; - const {managedConfig} = this.state; const highlight = highlightPostId === postId; return ( @@ -190,25 +175,12 @@ export default class PostListBase extends PureComponent { shouldRenderReplyButton={shouldRenderReplyButton} onPress={onPostPress} navigator={navigator} - managedConfig={managedConfig} + managedConfig={mattermostManaged.getCachedConfig()} location={location} /> ); }; - setManagedConfig = async (config) => { - let nextConfig = config; - if (!nextConfig) { - nextConfig = await mattermostManaged.getLocalConfig(); - } - - if (this.mounted) { - this.setState({ - managedConfig: nextConfig, - }); - } - }; - showPermalinkView = (postId) => { const {actions, navigator} = this.props; diff --git a/app/mattermost_managed/mattermost-managed.android.js b/app/mattermost_managed/mattermost-managed.android.js index 7aa71819c..272036a0c 100644 --- a/app/mattermost_managed/mattermost-managed.android.js +++ b/app/mattermost_managed/mattermost-managed.android.js @@ -8,12 +8,12 @@ import JailMonkey from 'jail-monkey'; const {MattermostManaged} = NativeModules; const listeners = []; -let localConfig; +let cachedConfig = {}; export default { addEventListener: (name, callback) => { const listener = DeviceEventEmitter.addListener(name, (config) => { - localConfig = config; + cachedConfig = config; if (callback && typeof callback === 'function') { callback(config); } @@ -36,17 +36,17 @@ export default { }, authenticate: LocalAuth.auth, blurAppScreen: MattermostManaged.blurAppScreen, - getConfig: MattermostManaged.getConfig, - getLocalConfig: async () => { - if (!localConfig) { - try { - localConfig = await MattermostManaged.getConfig(); - } catch (error) { - // do nothing... - } + getConfig: async () => { + try { + cachedConfig = await MattermostManaged.getConfig(); + } catch (error) { + // do nothing... } - return localConfig || {}; + return cachedConfig; + }, + getCachedConfig: () => { + return cachedConfig; }, isDeviceSecure: async () => { try { diff --git a/app/mattermost_managed/mattermost-managed.ios.js b/app/mattermost_managed/mattermost-managed.ios.js index eef8e1129..4c4c64d8a 100644 --- a/app/mattermost_managed/mattermost-managed.ios.js +++ b/app/mattermost_managed/mattermost-managed.ios.js @@ -8,12 +8,12 @@ const {BlurAppScreen, MattermostManaged} = NativeModules; const mattermostManagedEmitter = new NativeEventEmitter(MattermostManaged); const listeners = []; -let localConfig; +let cachedConfig = {}; export default { addEventListener: (name, callback) => { const listener = mattermostManagedEmitter.addListener(name, (config) => { - localConfig = config; + cachedConfig = config; if (callback && typeof callback === 'function') { callback(config); } @@ -36,17 +36,17 @@ export default { }, authenticate: LocalAuth.authenticate, blurAppScreen: BlurAppScreen.enabled, - getConfig: MattermostManaged.getConfig, - getLocalConfig: async () => { - if (!localConfig) { - try { - localConfig = await MattermostManaged.getConfig(); - } catch (error) { - // do nothing... - } + getConfig: async () => { + try { + cachedConfig = await MattermostManaged.getConfig(); + } catch (error) { + // do nothing... } - return localConfig || {}; + return cachedConfig; + }, + getCachedConfig: () => { + return cachedConfig; }, isDeviceSecure: async () => { try { diff --git a/app/screens/flagged_posts/flagged_posts.js b/app/screens/flagged_posts/flagged_posts.js index 18ff0aac8..3e2d3bd15 100644 --- a/app/screens/flagged_posts/flagged_posts.js +++ b/app/screens/flagged_posts/flagged_posts.js @@ -56,22 +56,6 @@ export default class FlaggedPosts extends PureComponent { props.navigator.setOnNavigatorEvent(this.onNavigatorEvent); props.actions.clearSearch(); props.actions.getFlaggedPosts(); - - this.state = { - managedConfig: {}, - }; - } - - componentWillMount() { - this.listenerId = mattermostManaged.addEventListener('managedConfigDidChange', this.setManagedConfig); - } - - componentDidMount() { - this.setManagedConfig(); - } - - componentWillUnmount() { - mattermostManaged.removeEventListener(this.listenerId); } goToThread = (post) => { @@ -158,7 +142,7 @@ export default class FlaggedPosts extends PureComponent { renderPost = ({item, index}) => { const {postIds, theme} = this.props; - const {managedConfig} = this.state; + if (isDateLine(item)) { return ( { - let nextConfig = config; - if (!nextConfig) { - nextConfig = await mattermostManaged.getLocalConfig(); - } - - this.setState({ - managedConfig: nextConfig, - }); - }; - showPermalinkView = (postId, isPermalink) => { const {actions, navigator} = this.props; diff --git a/app/screens/pinned_posts/pinned_posts.js b/app/screens/pinned_posts/pinned_posts.js index b916d062b..8c42cb29a 100644 --- a/app/screens/pinned_posts/pinned_posts.js +++ b/app/screens/pinned_posts/pinned_posts.js @@ -55,27 +55,14 @@ export default class PinnedPosts extends PureComponent { super(props); props.navigator.setOnNavigatorEvent(this.onNavigatorEvent); - - this.state = { - managedConfig: {}, - }; - } - - componentWillMount() { - this.listenerId = mattermostManaged.addEventListener('managedConfigDidChange', this.setManagedConfig); } componentDidMount() { const {actions, currentChannelId} = this.props; - this.setManagedConfig(); actions.clearSearch(); actions.getPinnedPosts(currentChannelId); } - componentWillUnmount() { - mattermostManaged.removeEventListener(this.listenerId); - } - goToThread = (post) => { const {actions, navigator, theme} = this.props; const channelId = post.channel_id; @@ -160,7 +147,6 @@ export default class PinnedPosts extends PureComponent { renderPost = ({item, index}) => { const {postIds, theme} = this.props; - const {managedConfig} = this.state; if (isDateLine(item)) { return ( { - let nextConfig = config; - if (!nextConfig) { - nextConfig = await mattermostManaged.getLocalConfig(); - } - - this.setState({ - managedConfig: nextConfig, - }); - }; - showPermalinkView = (postId, isPermalink) => { const {actions, navigator} = this.props; diff --git a/app/screens/recent_mentions/recent_mentions.js b/app/screens/recent_mentions/recent_mentions.js index e51493e9b..eb05d3e5f 100644 --- a/app/screens/recent_mentions/recent_mentions.js +++ b/app/screens/recent_mentions/recent_mentions.js @@ -56,22 +56,6 @@ export default class RecentMentions extends PureComponent { props.navigator.setOnNavigatorEvent(this.onNavigatorEvent); props.actions.clearSearch(); props.actions.getRecentMentions(); - - this.state = { - managedConfig: {}, - }; - } - - componentWillMount() { - this.listenerId = mattermostManaged.addEventListener('managedConfigDidChange', this.setManagedConfig); - } - - componentDidMount() { - this.setManagedConfig(); - } - - componentWillUnmount() { - mattermostManaged.removeEventListener(this.listenerId); } goToThread = (post) => { @@ -158,7 +142,7 @@ export default class RecentMentions extends PureComponent { renderPost = ({item, index}) => { const {postIds, theme} = this.props; - const {managedConfig} = this.state; + if (isDateLine(item)) { return ( @@ -193,17 +177,6 @@ export default class RecentMentions extends PureComponent { ); }; - setManagedConfig = async (config) => { - let nextConfig = config; - if (!nextConfig) { - nextConfig = await mattermostManaged.getLocalConfig(); - } - - this.setState({ - managedConfig: nextConfig, - }); - }; - showPermalinkView = (postId, isPermalink) => { const {actions, navigator} = this.props; diff --git a/app/screens/search/search.js b/app/screens/search/search.js index 928e67dda..3a12f8d20 100644 --- a/app/screens/search/search.js +++ b/app/screens/search/search.js @@ -93,18 +93,11 @@ export default class Search extends PureComponent { channelName: '', cursorPosition: 0, value: props.initialValue, - managedConfig: {}, recent: props.recent, }; } - componentWillMount() { - this.listenerId = mattermostManaged.addEventListener('managedConfigDidChange', this.setManagedConfig); - } - componentDidMount() { - this.setManagedConfig(); - if (this.props.initialValue) { this.search(this.props.initialValue); } @@ -148,10 +141,6 @@ export default class Search extends PureComponent { } } - componentWillUnmount() { - mattermostManaged.removeEventListener(this.listenerId); - } - archivedIndicator = (postID, style) => { const channelIsArchived = this.props.archivedPostIds.includes(postID); let archivedIndicator = null; @@ -366,7 +355,6 @@ export default class Search extends PureComponent { renderPost = ({item, index}) => { const {postIds, theme} = this.props; - const {managedConfig} = this.state; const style = getStyleFromTheme(theme); if (item.id) { @@ -403,7 +391,7 @@ export default class Search extends PureComponent { navigator={this.props.navigator} onHashtagPress={this.handleHashtagPress} onPermalinkPress={this.handlePermalinkPress} - managedConfig={managedConfig} + managedConfig={mattermostManaged.getCachedConfig()} skipPinnedHeader={true} /> {separator} @@ -459,17 +447,6 @@ export default class Search extends PureComponent { this.search(this.state.value.trim()); }; - setManagedConfig = async (config) => { - let nextConfig = config; - if (!nextConfig) { - nextConfig = await mattermostManaged.getLocalConfig(); - } - - this.setState({ - managedConfig: nextConfig, - }); - }; - showPermalinkView = (postId, isPermalink) => { const {actions, navigator} = this.props;