MM-15428 Return empty object for native managed configuration when not set (#2770)
This commit is contained in:
parent
0b74be530f
commit
d8a76946f3
10 changed files with 19 additions and 15 deletions
|
|
@ -56,10 +56,10 @@ public class MattermostManagedModule extends ReactContextBaseJavaModule {
|
|||
Object result = Arguments.fromBundle(config);
|
||||
promise.resolve(result);
|
||||
} else {
|
||||
throw new Exception("The MDM vendor has not sent any Managed configuration");
|
||||
promise.resolve(Arguments.createMap());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
promise.reject("no managed configuration", e);
|
||||
promise.resolve(Arguments.createMap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ export default class AtMention extends React.PureComponent {
|
|||
|
||||
const config = mattermostManaged.getCachedConfig();
|
||||
|
||||
if (config.copyAndPasteProtection !== 'true') {
|
||||
if (config?.copyAndPasteProtection !== 'true') {
|
||||
const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'});
|
||||
const actionText = formatMessage({id: 'mobile.mention.copy_mention', defaultMessage: 'Copy Mention'});
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ export default class MarkdownCodeBlock extends React.PureComponent {
|
|||
|
||||
const config = mattermostManaged.getCachedConfig();
|
||||
|
||||
if (config.copyAndPasteProtection !== 'true') {
|
||||
if (config?.copyAndPasteProtection !== 'true') {
|
||||
const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'});
|
||||
const actionText = formatMessage({id: 'mobile.markdown.code.copy_code', defaultMessage: 'Copy Code'});
|
||||
BottomSheet.showBottomSheetWithOptions({
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ export default class MarkdownImage extends React.Component {
|
|||
|
||||
const config = mattermostManaged.getCachedConfig();
|
||||
|
||||
if (config.copyAndPasteProtection !== 'true') {
|
||||
if (config?.copyAndPasteProtection !== 'true') {
|
||||
const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'});
|
||||
const actionText = formatMessage({id: 'mobile.markdown.link.copy_url', defaultMessage: 'Copy URL'});
|
||||
BottomSheet.showBottomSheetWithOptions({
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ export default class MarkdownLink extends PureComponent {
|
|||
|
||||
const config = mattermostManaged.getCachedConfig();
|
||||
|
||||
if (config.copyAndPasteProtection !== 'true') {
|
||||
if (config?.copyAndPasteProtection !== 'true') {
|
||||
const cancelText = formatMessage({id: 'mobile.post.cancel', defaultMessage: 'Cancel'});
|
||||
const actionText = formatMessage({id: 'mobile.markdown.link.copy_url', defaultMessage: 'Copy URL'});
|
||||
BottomSheet.showBottomSheetWithOptions({
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ export default class PostList extends PostListBase {
|
|||
|
||||
this.state = {
|
||||
refreshing: false,
|
||||
managedConfig: {},
|
||||
dataSource: new DataSource(props.postIds, this.keyExtractor),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ export default class PostList extends PostListBase {
|
|||
this.makeExtraData = makeExtraData();
|
||||
|
||||
this.state = {
|
||||
managedConfig: {},
|
||||
postListHeight: 0,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ const {BlurAppScreen, MattermostManaged} = NativeModules;
|
|||
const mattermostManagedEmitter = new NativeEventEmitter(MattermostManaged);
|
||||
|
||||
const listeners = [];
|
||||
const emptyObject = {};
|
||||
let cachedConfig = {};
|
||||
|
||||
export default {
|
||||
|
|
@ -39,7 +38,7 @@ export default {
|
|||
blurAppScreen: BlurAppScreen.enabled,
|
||||
getConfig: async () => {
|
||||
try {
|
||||
cachedConfig = await MattermostManaged.getConfig() || emptyObject;
|
||||
cachedConfig = await MattermostManaged.getConfig();
|
||||
} catch (error) {
|
||||
// do nothing...
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ function mapStateToProps(state, ownProps) {
|
|||
canAddReaction = false;
|
||||
}
|
||||
|
||||
if (!ownProps.isSystemMessage && ownProps.managedConfig.copyAndPasteProtection !== 'true' && post.message) {
|
||||
if (!ownProps.isSystemMessage && ownProps.managedConfig?.copyAndPasteProtection !== 'true' && post.message) {
|
||||
canCopyText = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,14 +69,22 @@ static NSString * const feedbackKey = @"com.apple.feedback.managed";
|
|||
{
|
||||
NSDictionary *response = [[NSUserDefaults standardUserDefaults] dictionaryForKey:configurationKey];
|
||||
if (hasListeners) {
|
||||
[self sendEventWithName:@"managedConfigDidChange" body:response];
|
||||
@try {
|
||||
[self sendEventWithName:@"managedConfigDidChange" body:response];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"Error sending event managedConfigDidChange to JS details=%@", exception.reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) remoteConfigChanged {
|
||||
NSDictionary *response = [[NSUserDefaults standardUserDefaults] dictionaryForKey:configurationKey];
|
||||
if (hasListeners) {
|
||||
[self sendEventWithName:@"managedConfigDidChange" body:response];
|
||||
@try {
|
||||
[self sendEventWithName:@"managedConfigDidChange" body:response];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"Error sending event managedConfigDidChange to JS details=%@", exception.reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,8 +95,7 @@ RCT_EXPORT_METHOD(getConfig:(RCTPromiseResolveBlock)resolve
|
|||
resolve(response);
|
||||
}
|
||||
else {
|
||||
NSError *error = [NSError errorWithDomain:@"Mattermost Managed" code:-1 userInfo:nil];
|
||||
reject(@"no managed configuration", @"The MDM vendor has not sent any Managed configuration", error);
|
||||
resolve(@{});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue