diff --git a/app/definitions/ILoggedUser.ts b/app/definitions/ILoggedUser.ts index 7aa159403..cf5d65788 100644 --- a/app/definitions/ILoggedUser.ts +++ b/app/definitions/ILoggedUser.ts @@ -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 diff --git a/app/definitions/IProfileViewInterfaces.ts b/app/definitions/IProfileViewInterfaces.ts index ba6d0659b..efd001c78 100644 --- a/app/definitions/IProfileViewInterfaces.ts +++ b/app/definitions/IProfileViewInterfaces.ts @@ -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; diff --git a/app/definitions/IUser.ts b/app/definitions/IUser.ts index a9a803bd1..14328f230 100644 --- a/app/definitions/IUser.ts +++ b/app/definitions/IUser.ts @@ -115,33 +115,23 @@ export interface INotificationPreferences { } export interface IUserPreferences { - user: { _id: string }; + user: Pick; settings: { preferences: INotificationPreferences; }; } -export interface IUser extends IRocketChatRecord, Omit { +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 => { +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], diff --git a/app/views/CreateChannelView.tsx b/app/views/CreateChannelView.tsx index e7893ba12..17b0f533d 100644 --- a/app/views/CreateChannelView.tsx +++ b/app/views/CreateChannelView.tsx @@ -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 `${baseUrl}/avatar/${url}?format=png&width=${uriSize}&height=${uriSize}${avatarAuthURLFragment}`; @@ -30,12 +31,7 @@ interface IJitsiMeetViewProps { route: RouteProp; baseUrl: string; theme: string; - user: { - id: string; - username: string; - name: string; - token: string; - }; + user: IUser; } class JitsiMeetView extends React.Component { @@ -50,12 +46,12 @@ class JitsiMeetView extends React.Component ({ +const mapStateToProps = (state: IApplicationState) => ({ user: getUserSelector(state), baseUrl: state.server.server }); diff --git a/app/views/LanguageView/index.tsx b/app/views/LanguageView/index.tsx index bd68834f6..4e1699cbc 100644 --- a/app/views/LanguageView/index.tsx +++ b/app/views/LanguageView/index.tsx @@ -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 { - user: { - id: string; - language: string; - }; + user: IUser; } interface ILanguageViewState { @@ -38,7 +35,7 @@ class LanguageView extends React.Component { try { const userRecord = await usersCollection.find(user.id); - await userRecord.update((record: any) => { + await userRecord.update(record => { record.language = params.language; }); } catch (e) { diff --git a/app/views/ProfileView/index.tsx b/app/views/ProfileView/index.tsx index 2d0724f8f..91a82d9ef 100644 --- a/app/views/ProfileView/index.tsx +++ b/app/views/ProfileView/index.tsx @@ -37,9 +37,9 @@ import { INavigationOptions, IParams, IProfileViewProps, - IProfileViewState, - IUser + IProfileViewState } from '../../definitions/IProfileViewInterfaces'; +import { IUser } from '../../definitions'; class ProfileView extends React.Component { private name: any; @@ -116,7 +116,7 @@ class ProfileView extends React.Component const { name, username, emails, customFields } = user || userProps; this.setState({ - name, + name: name as string, username, email: emails ? emails[0].address : null, newPassword: null, diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index dfe62aaf4..5b9b3810f 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -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 { server: IServer; isMasterDetail: boolean; - user: { - roles: []; - id: string; - }; + user: IUser; } class SettingsView extends React.Component { diff --git a/app/views/SidebarView/index.tsx b/app/views/SidebarView/index.tsx index 77db882db..5ead8241a 100644 --- a/app/views/SidebarView/index.tsx +++ b/app/views/SidebarView/index.tsx @@ -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; state: DrawerNavigationState; Site_Name: string; - user: { - statusText: string; - status: TUserStatus; - username: string; - name: string; - roles: string[]; - }; + user: IUser; theme?: string; loadingServer: boolean; useRealName: boolean; diff --git a/app/views/StatusView.tsx b/app/views/StatusView.tsx index 07d7138ca..8a11e12cc 100644 --- a/app/views/StatusView.tsx +++ b/app/views/StatusView.tsx @@ -64,7 +64,7 @@ interface IStatusViewState { } interface IStatusViewProps extends IBaseScreen { - user: Pick; + user: IUser; isMasterDetail: boolean; Accounts_AllowInvisibleStatusOption: boolean; } diff --git a/app/views/UserNotificationPreferencesView/index.tsx b/app/views/UserNotificationPreferencesView/index.tsx index fe4bdece8..9dd1d5c28 100644 --- a/app/views/UserNotificationPreferencesView/index.tsx +++ b/app/views/UserNotificationPreferencesView/index.tsx @@ -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; theme: string; - user: { - id: string; - }; + user: IUser; } class UserNotificationPreferencesView extends React.Component<