Chore: evaluate getUserSelector (#4013)

* update: type for user

* update: LanguageView's user type

* update: UserNotificationPreferencesView's user

* chore: set `enableMessageParserEarlyAdoption` as non-optional
This commit is contained in:
Gerzon Z 2022-04-07 12:27:45 -04:00 committed by GitHub
parent d38c17bcd8
commit 13a2962fa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 35 additions and 91 deletions

View File

@ -7,7 +7,7 @@ export interface ILoggedUser {
id: string;
token: string;
username: string;
name: string;
name?: string;
language?: string;
status: TUserStatus;
statusText?: string;
@ -20,7 +20,7 @@ export interface ILoggedUser {
avatarETag?: string;
showMessageInMainThread?: boolean;
isFromWebView?: boolean;
enableMessageParserEarlyAdoption?: boolean;
enableMessageParserEarlyAdoption: boolean;
}
export interface ILoggedUserResultFromServer

View File

@ -2,20 +2,7 @@ import { StackNavigationProp } from '@react-navigation/stack';
import React from 'react';
import { ProfileStackParamList } from '../stacks/types';
export interface IUser {
id: string;
name: string;
username: string;
emails: {
[index: number]: {
address: string;
};
};
customFields: {
[index: string | number]: string;
};
}
import { IUser } from './IUser';
export interface IParams {
name: string;

View File

@ -115,33 +115,23 @@ export interface INotificationPreferences {
}
export interface IUserPreferences {
user: { _id: string };
user: Pick<IUser, '_id'>;
settings: {
preferences: INotificationPreferences;
};
}
export interface IUser extends IRocketChatRecord, Omit<ILoggedUser, 'username' | 'name' | 'status'> {
export interface IUser extends IRocketChatRecord, ILoggedUser {
_id: string;
id: string;
token: string;
createdAt?: Date;
roles?: string[];
type?: string;
active?: boolean;
username: string;
name?: string;
services?: IUserServices;
emails?: IUserEmail[];
status: TUserStatus;
statusConnection?: string;
lastLogin?: Date;
avatarOrigin?: string;
avatarETag?: string;
utcOffset?: number;
language?: string;
statusDefault?: TUserStatus;
statusText?: string;
oauth?: {
authorizedClients: string[];
};
@ -151,9 +141,6 @@ export interface IUser extends IRocketChatRecord, Omit<ILoggedUser, 'username' |
public_key: string;
};
requirePasswordChange?: boolean;
customFields?: {
[key: string]: any;
};
settings?: IUserSettings;
defaultRoom?: string;
ldap?: boolean;

View File

@ -13,18 +13,17 @@ export interface IServices {
wordpress: { clientId: string; serverURL: string };
}
const getUser = (state: IApplicationState): Partial<IUser> => {
const getUser = (state: IApplicationState): IUser => {
if (!isEmpty(state.share?.user)) {
return state.share.user;
return state.share.user as IUser;
}
return state.login?.user;
return state.login?.user as IUser;
};
const getLoginServices = (state: IApplicationState) => (state.login.services as IServices) || {};
const getShowFormLoginSetting = (state: IApplicationState) => (state.settings.Accounts_ShowFormLogin as boolean) || false;
const getIframeEnabledSetting = (state: IApplicationState) => (state.settings.Accounts_iframe_enabled as boolean) || false;
// TODO: we need to change 42 files to fix a correct type, i believe is better to do this later
export const getUserSelector = createSelector([getUser], user => user) as any;
export const getUserSelector = createSelector([getUser], user => user);
export const getShowLoginButton = createSelector(
[getLoginServices, getShowFormLoginSetting, getIframeEnabledSetting],

View File

@ -23,7 +23,7 @@ import SafeAreaView from '../containers/SafeAreaView';
import RocketChat from '../lib/rocketchat';
import sharedStyles from './Styles';
import { ChatsStackParamList } from '../stacks/types';
import { IApplicationState, IBaseScreen } from '../definitions';
import { IApplicationState, IBaseScreen, IUser } from '../definitions';
const styles = StyleSheet.create({
container: {
@ -90,11 +90,7 @@ interface ICreateChannelViewProps extends IBaseScreen<ChatsStackParamList, 'Crea
isFetching: boolean;
encryptionEnabled: boolean;
users: IOtherUser[];
user: {
id: string;
token: string;
roles: string[];
};
user: IUser;
teamId: string;
createPublicChannelPermission: string[] | undefined;
createPrivateChannelPermission: string[] | undefined;

View File

@ -23,6 +23,7 @@ import EventEmitter from '../utils/events';
import { LISTENER } from '../containers/Toast';
import debounce from '../utils/debounce';
import sharedStyles from './Styles';
import { IUser } from '../definitions';
const styles = StyleSheet.create({
container: {
@ -48,10 +49,7 @@ interface IE2EEncryptionSecurityViewState {
interface IE2EEncryptionSecurityViewProps {
theme: string;
user: {
roles: string[];
id: string;
};
user: IUser;
server: string;
encryptionEnabled: boolean;
logout(): void;

View File

@ -13,6 +13,7 @@ import { events, logEvent } from '../utils/log';
import { isAndroid, isIOS } from '../utils/deviceInfo';
import { withTheme } from '../theme';
import { InsideStackParamList } from '../stacks/types';
import { IApplicationState, IUser } from '../definitions';
const formatUrl = (url: string, baseUrl: string, uriSize: number, avatarAuthURLFragment: string) =>
`${baseUrl}/avatar/${url}?format=png&width=${uriSize}&height=${uriSize}${avatarAuthURLFragment}`;
@ -30,12 +31,7 @@ interface IJitsiMeetViewProps {
route: RouteProp<InsideStackParamList, 'JitsiMeetView'>;
baseUrl: string;
theme: string;
user: {
id: string;
username: string;
name: string;
token: string;
};
user: IUser;
}
class JitsiMeetView extends React.Component<IJitsiMeetViewProps, IJitsiMeetViewState> {
@ -50,12 +46,12 @@ class JitsiMeetView extends React.Component<IJitsiMeetViewProps, IJitsiMeetViewS
this.jitsiTimeout = null;
const { user, baseUrl } = props;
const { name: displayName, id: userId, token, username } = user;
const { name, id: userId, token, username } = user;
const avatarAuthURLFragment = `&rc_token=${token}&rc_uid=${userId}`;
const avatar = formatUrl(username, baseUrl, 100, avatarAuthURLFragment);
this.state = {
userInfo: {
displayName,
displayName: name as string,
avatar
},
loading: true
@ -135,7 +131,7 @@ class JitsiMeetView extends React.Component<IJitsiMeetViewProps, IJitsiMeetViewS
}
}
const mapStateToProps = (state: any) => ({
const mapStateToProps = (state: IApplicationState) => ({
user: getUserSelector(state),
baseUrl: state.server.server
});

View File

@ -9,7 +9,7 @@ import { themes } from '../../lib/constants';
import * as List from '../../containers/List';
import SafeAreaView from '../../containers/SafeAreaView';
import StatusBar from '../../containers/StatusBar';
import { IApplicationState, IBaseScreen, RootEnum } from '../../definitions';
import { IApplicationState, IBaseScreen, IUser, RootEnum } from '../../definitions';
import I18n, { isRTL, LANGUAGES } from '../../i18n';
import database from '../../lib/database';
import RocketChat from '../../lib/rocketchat';
@ -20,10 +20,7 @@ import { showErrorAlert } from '../../utils/info';
import log, { events, logEvent } from '../../utils/log';
interface ILanguageViewProps extends IBaseScreen<SettingsStackParamList, 'LanguageView'> {
user: {
id: string;
language: string;
};
user: IUser;
}
interface ILanguageViewState {
@ -38,7 +35,7 @@ class LanguageView extends React.Component<ILanguageViewProps, ILanguageViewStat
constructor(props: ILanguageViewProps) {
super(props);
this.state = {
language: props.user ? props.user.language : 'en'
language: props.user ? (props.user.language as string) : 'en'
};
}
@ -103,7 +100,7 @@ class LanguageView extends React.Component<ILanguageViewProps, ILanguageViewStat
await serversDB.write(async () => {
try {
const userRecord = await usersCollection.find(user.id);
await userRecord.update((record: any) => {
await userRecord.update(record => {
record.language = params.language;
});
} catch (e) {

View File

@ -37,9 +37,9 @@ import {
INavigationOptions,
IParams,
IProfileViewProps,
IProfileViewState,
IUser
IProfileViewState
} from '../../definitions/IProfileViewInterfaces';
import { IUser } from '../../definitions';
class ProfileView extends React.Component<IProfileViewProps, IProfileViewState> {
private name: any;
@ -116,7 +116,7 @@ class ProfileView extends React.Component<IProfileViewProps, IProfileViewState>
const { name, username, emails, customFields } = user || userProps;
this.setState({
name,
name: name as string,
username,
email: emails ? emails[0].address : null,
newPassword: null,

View File

@ -13,7 +13,7 @@ import Loading from '../containers/Loading';
import SafeAreaView from '../containers/SafeAreaView';
import SearchBox from '../containers/SearchBox';
import StatusBar from '../containers/StatusBar';
import { IApplicationState, IBaseScreen, ISubscription } from '../definitions';
import { IApplicationState, IBaseScreen, ISubscription, IUser } from '../definitions';
import I18n from '../i18n';
import database from '../lib/database';
import RocketChat from '../lib/rocketchat';
@ -39,12 +39,7 @@ interface ISelectedUsersViewProps extends IBaseScreen<ChatsStackParamList, 'Sele
// REDUX STATE
users: ISelectedUser[];
loading: boolean;
user: {
id: string;
token: string;
username: string;
name: string;
};
user: IUser;
baseUrl: string;
}
@ -64,7 +59,7 @@ class SelectedUsersView extends React.Component<ISelectedUsersViewProps, ISelect
};
const { user, dispatch } = this.props;
if (this.isGroupChat()) {
dispatch(addUser({ _id: user.id, name: user.username, fname: user.name }));
dispatch(addUser({ _id: user.id, name: user.username, fname: user.name as string }));
}
this.setHeader(props.route.params?.showButton);
}

View File

@ -15,7 +15,7 @@ import * as List from '../../containers/List';
import SafeAreaView from '../../containers/SafeAreaView';
import StatusBar from '../../containers/StatusBar';
import { LISTENER } from '../../containers/Toast';
import { IApplicationState, IBaseScreen, RootEnum } from '../../definitions';
import { IApplicationState, IBaseScreen, IUser, RootEnum } from '../../definitions';
import I18n from '../../i18n';
import database from '../../lib/database';
import RocketChat from '../../lib/rocketchat';
@ -34,10 +34,7 @@ import SidebarView from '../SidebarView';
interface ISettingsViewProps extends IBaseScreen<SettingsStackParamList, 'SettingsView'> {
server: IServer;
isMasterDetail: boolean;
user: {
roles: [];
id: string;
};
user: IUser;
}
class SettingsView extends React.Component<ISettingsViewProps, any> {

View File

@ -19,7 +19,7 @@ import Navigation from '../../lib/navigation/appNavigation';
import SidebarItem from './SidebarItem';
import styles from './styles';
import { DrawerParamList } from '../../stacks/types';
import { TUserStatus } from '../../definitions';
import { IUser } from '../../definitions';
interface ISeparatorProps {
theme: string;
@ -39,13 +39,7 @@ interface ISidebarProps {
navigation: DrawerNavigationProp<DrawerParamList>;
state: DrawerNavigationState<DrawerParamList>;
Site_Name: string;
user: {
statusText: string;
status: TUserStatus;
username: string;
name: string;
roles: string[];
};
user: IUser;
theme?: string;
loadingServer: boolean;
useRealName: boolean;

View File

@ -64,7 +64,7 @@ interface IStatusViewState {
}
interface IStatusViewProps extends IBaseScreen<any, 'StatusView'> {
user: Pick<IUser, 'id' | 'status' | 'statusText'>;
user: IUser;
isMasterDetail: boolean;
Accounts_AllowInvisibleStatusOption: boolean;
}

View File

@ -15,7 +15,7 @@ import { getUserSelector } from '../../selectors/login';
import sharedStyles from '../Styles';
import { OPTIONS } from './options';
import { ProfileStackParamList } from '../../stacks/types';
import { INotificationPreferences } from '../../definitions';
import { INotificationPreferences, IUser } from '../../definitions';
const styles = StyleSheet.create({
pickerText: {
@ -34,9 +34,7 @@ interface IUserNotificationPreferencesViewState {
interface IUserNotificationPreferencesViewProps {
navigation: StackNavigationProp<ProfileStackParamList, 'UserNotificationPrefView'>;
theme: string;
user: {
id: string;
};
user: IUser;
}
class UserNotificationPreferencesView extends React.Component<