mattermost-mobile/app/database/models/server/user.ts
Miguel Alatzar 134c4a49c5
Integrate react-native-network-client (#5499)
* fix: handle NSMutableData

* feat: integrate react-native-network-client

* fix: typos

* fix: semicolon

* fix: rename to urlVersion

* fix: add returnDataOnly arg

* fix: configure network client

* fix: headers

* fix: handling of serverVersion

* fix: rename requests to actions

* fix: action imports

* fix: no need to stringify body

* fix: sso flow

* fix: address PR feedback

* fix: invalidate client on logout

* fix: address PR feedback take 2

* fix: address PR feedback take 3

* fix: tsc issues

* fix: get csrf token during client creation

* fix: linter

* fix: invalidate client onLogout

* fix: event emitter

* fix: unit tests

* fix: apply linter fixes

* fix lint

* Modify actions to add / update database values

* Rename clien4.d.ts to client.d.ts

* fix empty & missing translations

* cleanup api client

* Cleanup init & squash some TODO's

* Emit certificate errors in NetworkManager

* cleanup user actions

* Fix NetworkManager invalidate client

* Invalidate client when server screen appears

* Update kotlin to 1.4.30 required by network-client

* patch react-native-keychain to remove cached credential

* update react-native-network-client

* Use app.db instead of default.db in native code

* fix use of rnnc on Android

* Init PushNotifications

* No need to reset serverVersion on logout

* fix logout action

* fix deleteServerDatabase

* fix schedule expired session notification

* use safeParseJSON for db json fields

* unsubscribe when database component unmounts

* cleanup init

* session type

* pass launchprops to entire login flow

* Properly remove third party cookies after SSO login

* recreate network client if sso with redirect fails

* add missing launch props from server screen

* use query prefix for database queries

* Add temporary logout function to channel screen

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-07-06 11:16:35 -04:00

138 lines
5.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {children, field, json} from '@nozbe/watermelondb/decorators';
import Model, {Associations} from '@nozbe/watermelondb/Model';
import {MM_TABLES} from '@constants/database';
import {safeParseJSON} from '@utils/helpers';
import type Channel from '@typings/database/models/servers/channel';
import type ChannelMembership from '@typings/database/models/servers/channel_membership';
import type GroupMembership from '@typings/database/models/servers/group_membership';
import type Post from '@typings/database/models/servers/post';
import type Preference from '@typings/database/models/servers/preference';
import type Reaction from '@typings/database/models/servers/reaction';
import type TeamMembership from '@typings/database/models/servers/team_membership';
const {
CHANNEL,
CHANNEL_MEMBERSHIP,
GROUP_MEMBERSHIP,
POST,
PREFERENCE,
REACTION,
TEAM_MEMBERSHIP,
USER,
} = MM_TABLES.SERVER;
/**
* The User model represents the 'USER' table and its relationship to other
* shareholders in the app.
*/
export default class User extends Model {
/** table (name) : User */
static table = USER;
/** associations : Describes every relationship to this table. */
static associations: Associations = {
/** USER has a 1:N relationship with CHANNEL. A user can create multiple channels */
[CHANNEL]: {type: 'has_many', foreignKey: 'creator_id'},
/** USER has a 1:N relationship with CHANNEL_MEMBERSHIP. A user can be part of multiple channels */
[CHANNEL_MEMBERSHIP]: {type: 'has_many', foreignKey: 'user_id'},
/** USER has a 1:N relationship with GROUP_MEMBERSHIP. A user can be part of multiple groups */
[GROUP_MEMBERSHIP]: {type: 'has_many', foreignKey: 'user_id'},
/** USER has a 1:N relationship with POST. A user can author multiple posts */
[POST]: {type: 'has_many', foreignKey: 'user_id'},
/** USER has a 1:N relationship with PREFERENCE. A user can have multiple preferences */
[PREFERENCE]: {type: 'has_many', foreignKey: 'user_id'},
/** USER has a 1:N relationship with REACTION. A user can react to multiple posts */
[REACTION]: {type: 'has_many', foreignKey: 'user_id'},
/** USER has a 1:N relationship with TEAM_MEMBERSHIP. A user can join multiple teams */
[TEAM_MEMBERSHIP]: {type: 'has_many', foreignKey: 'user_id'},
};
/** auth_service : The type of authentication service registered to that user */
@field('auth_service') authService!: string;
/** update_at : The timestamp at which this user account has been updated */
@field('update_at') updateAt!: number;
/** delete_at : The timestamp at which this user account has been archived/deleted */
@field('delete_at') deleteAt!: number;
/** email : The email address for that user */
@field('email') email!: string;
/** first_name : The user's first name */
@field('first_name') firstName!: string;
/** is_bot : Boolean flag indicating if the user is a bot */
@field('is_bot') isBot!: boolean;
/** is_guest : Boolean flag indicating if the user is a guest */
@field('is_guest') isGuest!: boolean;
/** last_name : The user's last name */
@field('last_name') lastName!: string;
/** last_picture_update : The timestamp of the last time the profile picture has been updated */
@field('last_picture_update') lastPictureUpdate!: number;
/** locale : The user's locale */
@field('locale') locale!: string;
/** nickname : The user's nickname */
@field('nickname') nickname!: string;
/** position : The user's position in the company */
@field('position') position!: string;
/** roles : The associated roles that this user has. Multiple roles concatenated together with comma to form a single string. */
@field('roles') roles!: string;
/** status : The presence status for the user */
@field('status') status!: string;
/** username : The user's username */
@field('username') username!: string;
/** notify_props : Notification preferences/configurations */
@json('notify_props', safeParseJSON) notifyProps!: NotifyProps;
/** props : Custom objects ( e.g. custom status) can be stored in there. Its type definition is known as
* 'excess property check' in Typescript land. We keep using it till we build up the final shape of this object.
*/
@json('props', safeParseJSON) props!: UserProps;
/** timezone : The timezone for this user */
@json('timezone', safeParseJSON) timezone!: Timezone;
/** channelsCreated : All the channels that this user created */
@children(CHANNEL) channelsCreated!: Channel[];
/** channels : All the channels that this user is part of */
@children(CHANNEL_MEMBERSHIP) channels!: ChannelMembership[];
/** groups : All the groups that this user is part of */
@children(GROUP_MEMBERSHIP) groups!: GroupMembership[];
/** posts : All the posts that this user has written*/
@children(POST) posts!: Post[];
/** preferences : All user preferences */
@children(PREFERENCE) preferences!: Preference[];
/** reactions : All the reactions to posts that this user had */
@children(REACTION) reactions!: Reaction[];
/** teams : All the team that this user is part of */
@children(TEAM_MEMBERSHIP) teams!: TeamMembership[];
}