import Model from '@nozbe/watermelondb/Model'; import { TUserStatus } from './TUserStatus'; import { IRocketChatRecord } from './IRocketChatRecord'; import { ILoggedUser } from './ILoggedUser'; export interface ILoginToken { hashedToken: string; twoFactorAuthorizedUntil?: Date; twoFactorAuthorizedHash?: string; } export interface IMeteorLoginToken extends ILoginToken { when: Date; } export interface IPersonalAccessToken extends ILoginToken { type: 'personalAccessToken'; createdAt: Date; lastTokenPart: string; name?: string; bypassTwoFactor?: boolean; } export interface IUserRegistered { _id: string; type: string; status: TUserStatus; active: boolean; name: string; username: string; __rooms: string[]; } export interface IUserEmailVerificationToken { token: string; address: string; when: Date; } export interface IUserEmailCode { code: string; expire: Date; } type LoginToken = IMeteorLoginToken & IPersonalAccessToken; export type Username = string; export type ILoginUsername = | { username: string; } | { email: string; }; export type LoginUsername = string | ILoginUsername; export interface IUserServices { password?: { bcrypt: string; }; passwordHistory?: string[]; email?: { verificationTokens?: IUserEmailVerificationToken[]; }; resume?: { loginTokens?: LoginToken[]; }; google?: any; facebook?: any; github?: any; totp?: { enabled: boolean; hashedBackup: string[]; secret: string; }; email2fa?: { enabled: boolean; changedAt: Date; }; emailCode: IUserEmailCode[]; saml?: { inResponseTo?: string; provider?: string; idp?: string; idpSession?: string; nameID?: string; }; ldap?: { id: string; idAttribute?: string; }; } export interface IUserEmail { address: string; verified: boolean; } export interface IUserSettings { profile: any; preferences: { [key: string]: any; }; } export type TNotifications = 'default' | 'all' | 'mentions' | 'nothing'; export interface INotificationPreferences { id: string; enableMessageParserEarlyAdoption: boolean; desktopNotifications: TNotifications; pushNotifications: TNotifications; emailNotificationMode?: 'mentions' | 'nothing'; language?: string; } export interface IUserPreferences { user: { _id: string }; settings: { preferences: INotificationPreferences; }; } export interface IUser extends IRocketChatRecord, Omit { _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[]; }; statusLivechat?: string; e2e?: { private_key: string; public_key: string; }; requirePasswordChange?: boolean; customFields?: { [key: string]: any; }; settings?: IUserSettings; defaultRoom?: string; ldap?: boolean; muted?: boolean; } export interface IRegisterUser extends IUser { username: string; name: string; } export const isRegisterUser = (user: IUser): user is IRegisterUser => user.username !== undefined && user.name !== undefined; export type IUserDataEvent = { id: unknown; } & ( | ({ type: 'inserted'; } & IUser) | { type: 'removed'; } | { type: 'updated'; diff: Partial; unset: Record; } ); export type TUserModel = IUser & Model;