fix : code clean up from reviews

This commit is contained in:
Avinash Lingaloo
2021-06-14 20:23:19 +04:00
parent a9fd5828ff
commit 964b8d3b36
19 changed files with 33 additions and 77 deletions

View File

@@ -31,6 +31,7 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"
android:taskAffinity=""
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@@ -2,7 +2,6 @@
// See LICENSE.txt for license information.
import React from 'react';
import {ActivityIndicator, StyleSheet, View, ViewStyle} from 'react-native';
type LoadingProps = {
@@ -11,7 +10,7 @@ type LoadingProps = {
style?: ViewStyle,
}
const Loading = ({size = 'large', color = 'grey', style = {}}: LoadingProps) => {
const Loading = ({size = 'large', color = 'grey', style}: LoadingProps) => {
return (
<View style={styles.container}>
<ActivityIndicator

View File

@@ -1,24 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {getThemeFromState} from '@screens/navigation';
import React from 'react';
import {Platform, StatusBar as NativeStatusBar, StatusBarStyle} from 'react-native';
import tinyColor from 'tinycolor2';
type StatusBarProps = {
theme?: Theme;
headerColor?: string;
}
const StatusBar = ({theme, headerColor}: StatusBarProps) => {
const zTheme: Theme = theme ?? getThemeFromState();
const color = headerColor ? tinyColor(headerColor) : tinyColor(zTheme.sidebarHeaderBg);
const barStyle: StatusBarStyle = color.isLight() && Platform.OS === 'ios' ? 'dark-content' : 'light-content';
return (
<NativeStatusBar barStyle={barStyle}/>
);
};
export default StatusBar;

View File

@@ -2,7 +2,7 @@
// See LICENSE.txt for license information.
import Attachment from './attachment';
import Authentication from './authentication';
import SSO from './sso';
import Database from './database';
import DeepLink from './deep_linking';
import Device from './device';
@@ -17,7 +17,7 @@ import WebsocketEvents from './websocket';
export {
Attachment,
Authentication,
SSO,
Database,
DeepLink,
Device,

View File

@@ -85,7 +85,6 @@ export function componentDidAppearListener({componentId}: ComponentDidAppearEven
case 'SettingsSidebar':
DeviceEventEmitter.emit(NavigationConstants.BLUR_POST_DRAFT);
break;
default: break;
}
}

View File

@@ -1,15 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Database, Q} from '@nozbe/watermelondb';
import {MM_TABLES} from '@constants/database';
import Preference from '@typings/database/preference';
export const getTheme = async (database: Database) => {
const userTheme = await database.collections.get(MM_TABLES.SERVER.PREFERENCE).query(Q.where('category', 'theme')).fetch() as Preference[];
if (userTheme?.[0]) {
return userTheme[0].value;
}
return null;
};

View File

@@ -103,7 +103,7 @@ export const login = async ({ldapOnly = false, loginId, mfaToken, password}: Log
};
export const loadMe = async ({deviceToken, user}: LoadMeArgs) => {
let currentUser = user ?? undefined;
let currentUser = user;
const {activeServerDatabase, error} = await getActiveServerDatabase();
if (!activeServerDatabase) {
@@ -130,12 +130,6 @@ export const loadMe = async ({deviceToken, user}: LoadMeArgs) => {
}
try {
if (!currentUser) {
return {
error,
currentUser: undefined,
};
}
const analyticsClient = analytics.create(Client4.getUrl());
analyticsClient.setUserId(currentUser.id);
analyticsClient.setUserRoles(currentUser.roles);

View File

@@ -159,7 +159,7 @@ const Login: NavigationFunctionComponent = ({config, license, theme}: LoginProps
const goToMfa = () => {
const screen = 'MFA';
const title = intl.formatMessage({id: 'mobile.routes.mfa', defaultMessage: 'Multi-factor Authentication'});
const title = intl.formatMessage({id: 'mobile.routes.mfa', defaultMessage: 'Multi-factor SSO'});
goToScreen(screen, title, {goToChannel, loginId, password});
};

View File

@@ -104,7 +104,7 @@ describe('Login', () => {
expect(goToScreen).
toHaveBeenCalledWith(
'MFA',
'Multi-factor Authentication',
'Multi-factor SSO',
{
goToChannel: expect.anything(),
loginId,

View File

@@ -6,7 +6,7 @@ import {Image, Text} from 'react-native';
import Button from 'react-native-button';
import LocalConfig from '@assets/config.json';
import {Authentication} from '@constants';
import {SSO} from '@constants';
import {makeStyleSheetFromTheme} from '@utils/theme';
const GitLabOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => {
@@ -14,7 +14,7 @@ const GitLabOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => {
const forceHideFromLocal = LocalConfig.HideGitLabLoginExperimental;
const handlePress = () => {
onPress(Authentication.GITLAB);
onPress(SSO.GITLAB);
};
if (!forceHideFromLocal && config.EnableSignUpWithGitLab === 'true') {

View File

@@ -6,14 +6,14 @@ import {Image} from 'react-native';
import Button from 'react-native-button';
import FormattedText from '@components/formatted_text';
import {Authentication} from '@constants';
import {SSO} from '@constants';
import {makeStyleSheetFromTheme} from '@utils/theme';
const GoogleOption = ({config, onPress, theme}: LoginOptionWithConfigProps) => {
const styles = getStyleSheet(theme);
const handlePress = () => {
onPress(Authentication.GOOGLE);
onPress(SSO.GOOGLE);
};
if (config.EnableSignUpWithGoogle === 'true') {

View File

@@ -6,7 +6,7 @@ import Button from 'react-native-button';
import LocalConfig from '@assets/config.json';
import FormattedText from '@components/formatted_text';
import {Authentication} from '@constants';
import {SSO} from '@constants';
import {makeStyleSheetFromTheme} from '@utils/theme';
const Office365Option = ({config, license, onPress, theme}: LoginOptionWithConfigAndLicenseProps) => {
@@ -16,7 +16,7 @@ const Office365Option = ({config, license, onPress, theme}: LoginOptionWithConfi
license.Office365OAuth === 'true';
const handlePress = () => {
onPress(Authentication.OFFICE365);
onPress(SSO.OFFICE365);
};
if (!forceHideFromLocal && o365Enabled) {

View File

@@ -5,7 +5,7 @@ import React from 'react';
import Button from 'react-native-button';
import FormattedText from '@components/formatted_text';
import {Authentication} from '@constants';
import {SSO} from '@constants';
import {isMinimumServerVersion} from '@utils/helpers';
import {makeStyleSheetFromTheme} from '@utils/theme';
@@ -14,7 +14,7 @@ const OpenIdOption = ({config, license, onPress, theme}: LoginOptionWithConfigAn
const openIdEnabled = config.EnableSignUpWithOpenId === 'true' && license.IsLicensed === 'true' && isMinimumServerVersion(config.Version, 5, 33, 0);
const handlePress = () => {
onPress(Authentication.OPENID);
onPress(SSO.OPENID);
};
if (openIdEnabled) {

View File

@@ -6,7 +6,7 @@ import {Text} from 'react-native';
import Button from 'react-native-button';
import LocalConfig from '@assets/config.json';
import {Authentication} from '@constants';
import {SSO} from '@constants';
import {makeStyleSheetFromTheme} from '@utils/theme';
const SamlOption = ({config, license, onPress, theme}: LoginOptionWithConfigAndLicenseProps) => {
@@ -15,7 +15,7 @@ const SamlOption = ({config, license, onPress, theme}: LoginOptionWithConfigAndL
const enabled = config.EnableSaml === 'true' && license.IsLicensed === 'true' && license.SAML === 'true';
const handlePress = () => {
onPress(Authentication.SAML);
onPress(SSO.SAML);
};
if (!forceHideFromLocal && enabled) {

View File

@@ -5,7 +5,7 @@ import React, {useState} from 'react';
import {useIntl} from 'react-intl';
import {Client4} from '@client/rest';
import {Authentication} from '@constants';
import {SSO} from '@constants';
import {useManagedConfig} from '@mattermost/react-native-emm';
import {scheduleExpiredNotification} from '@requests/remote/push_notification';
import {ssoLogin} from '@requests/remote/user';
@@ -32,27 +32,27 @@ const SSO = ({config, serverUrl, ssoType, theme}: SSOProps) => {
let completeUrlPath = '';
let loginUrl = '';
switch (ssoType) {
case Authentication.GOOGLE: {
case SSO.GOOGLE: {
completeUrlPath = '/signup/google/complete';
loginUrl = `${serverUrl}/oauth/google/mobile_login`;
break;
}
case Authentication.GITLAB: {
case SSO.GITLAB: {
completeUrlPath = '/signup/gitlab/complete';
loginUrl = `${serverUrl}/oauth/gitlab/mobile_login`;
break;
}
case Authentication.SAML: {
case SSO.SAML: {
completeUrlPath = '/login/sso/saml';
loginUrl = `${serverUrl}/login/sso/saml?action=mobile`;
break;
}
case Authentication.OFFICE365: {
case SSO.OFFICE365: {
completeUrlPath = '/signup/office365/complete';
loginUrl = `${serverUrl}/oauth/office365/mobile_login`;
break;
}
case Authentication.OPENID: {
case SSO.OPENID: {
completeUrlPath = '/signup/openid/complete';
loginUrl = `${serverUrl}/oauth/openid/mobile_login`;
break;

View File

@@ -17,7 +17,7 @@ import urlParse from 'url-parse';
import {Client4} from '@client/rest';
import Loading from '@components/loading';
import {Authentication} from '@constants';
import {SSO} from '@constants';
import {popTopScreen} from '@screens/navigation';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
@@ -177,7 +177,7 @@ const SSOWithWebView = ({completeUrlPath, loginError, loginUrl, onCSRFToken, onM
const parsed = urlParse(url);
let isLastRedirect = url.includes(completeUrlPath);
if (ssoType === Authentication.SAML) {
if (ssoType === SSO.SAML) {
isLastRedirect = isLastRedirect && !parsed.query;
}
@@ -188,7 +188,7 @@ const SSOWithWebView = ({completeUrlPath, loginError, loginUrl, onCSRFToken, onM
const renderWebView = () => {
if (shouldRenderWebView) {
const userAgent = ssoType === Authentication.GOOGLE ? 'Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.117 Mobile Safari/608.2.11' : undefined;
const userAgent = ssoType === SSO.GOOGLE ? 'Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.117 Mobile Safari/608.2.11' : undefined;
return (
<WebView
automaticallyAdjustContentInsets={false}

View File

@@ -1,10 +1,10 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Client4} from '@client/rest';
import urlParse from 'url-parse';
import DatabaseConnectionException from '@database/exceptions/database_connection_exception';
import DatabaseManager from '@database/manager';
import urlParse from 'url-parse';
type SetActiveDatabaseArgs = {
serverUrl: string;
@@ -12,7 +12,7 @@ type SetActiveDatabaseArgs = {
};
export const createAndSetActiveDatabase = async ({serverUrl, displayName}: SetActiveDatabaseArgs) => {
const connectionName = displayName ?? urlParse(Client4.getUrl())?.hostname;
const connectionName = displayName ?? urlParse(serverUrl)?.hostname;
try {
const databaseClient = new DatabaseManager();

View File

@@ -828,8 +828,9 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Mattermost/Mattermost.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 333;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = UQ8HT4Q2XM;
@@ -870,8 +871,9 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Mattermost/Mattermost.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 333;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = UQ8HT4Q2XM;