forked from Ivasoft/mattermost-mobile
* MM_30475 : ADDED default schema
* MM_30475 : ADDED todo for field 'value' of default/Global entity
* MM_30476 : Created schema for SERVER DB
* MM_30476 : Server model [ IN PROGRESS ]
* MM_30476 : Including types for group, groups_in_channel and role
* MM_30476 : ADDED models for Group
- @typings absolute path has been added to the tsconfig.json
* MM_30476 : ADDED typings to current models
* MM_30476 : ADDED typings to current models
* MM_30476 : ADDED models related to TEAM section of the ERD
* MM_30476 : ADDED models for User section of the ERD
* MM_30476 : ADDED models for POST section of the ERD
* MM_30476 : ADDED models for Channel section of the ERD
* MM_30475 : Updated typings and references to MM_TABLES
* MM_30476 : Verified all field names
* MM_30476 : Verified every table associations
* MM_30476 : Verified all relation fields
* MM_30476 : Updated primary id of the main models
We will override the wdb id at component level when we create a new records. This involves the models : channel, group, post, team and user.
* MM_30476 : Including 1:1 relationship amongs some entities
* MM_30476 : ADDED Schema Managers
* The migration array will hold all the migration steps.
* The initial app release (e.g. v2 )will have an empty array and subsequent releases (e.g. v2.1 ) will have the steps listed in that array.
* On initialization, the database will perform the migration to accomodate for new columns/tables creation and while it will conserve the mobile phone's data, it will also make it conform to this new schema.
* If a migration fails, the migration process will rollback any changes. This migration will be thoroughly tested in development before pushing it live.
* Revert "MM_30476 : ADDED Schema Managers"
This reverts commit a505bd5e11.
* MM_30478 : Converted schema_manager into a function
* MM_30478 : Updated schema manager and included patch for wdb
* MM_30478: Updated watermelondb patch package
* MM_30478 : Update function create_schema_manager to createSqliteAdaptorOptions
* MM_30476 : Update constant name to reflect directory name
* MM_30476 : Updated msgCount from my_channel model to message_count in server schema
* MM_30482 : Added tests for schema_manager
* MM_30482 : Database Manager [ IN PROGRESS ]
* MM_30478 : Returning an sqliteAdapter instead of an object
* MM_30476 : Apply suggestions from code review
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
* MM_30476 : Updated all imports as per instruction.
* MM_30476 : Shortening object chains by destructuring
* MM_30476 : Updated schema file structure
* MM_30476 : Prettifying @typings folder
* MM_30476 : Removing useless ids
* MM_30476 : Prettify imports for decorators
* MM_30476 : ADDED documentations and lazy queries to Channel and Channel_Info
* MM_30476 : ADDED documentations for default schema
* MM_30476 : Documentation [ IN PROGRESS ]
- Following JSDoc syntax for single line comment
- Removed redundant fields in the 'membership' tables and left only the @relation records.
* MM_30476 : Documentations [ IN PROGRESS ]
* MM_30476 : Documentations [ IN PROGRESS ]
* MM_30476 : Documentations [ IN PROGRESS ]
* MM_30476 : Documentations [ IN PROGRESS]
Updated
1) my_team and team,
2) my_channel and channel,
to each have 1:1 relationship with one another
* MM_30476 : Updated all Typescript definitions
* MM_30476 :Updated @relation to @immutableRelation
* MM_30476 : Updated description for previous_post_id
* MM_30478 : Updated patch package for wdb module
* MM_30478: DB Manager [IN PROGRESS ]
* MM_30478: DB Manager [IN PROGRESS]
* MM_30478: DB Manager [IN PROGRESS]
* MM_30478 : DB Manager [IN PROGRESS]
* MM_30478 : Deleting .db file on iOS
* MM_30478: Successfully deleting .db files and directory on iOS side
* MM_30478 : Update definition for default/global
* MM_30478 : Updated all models
* MM_30478 : Doing a bit of house cleaning
* MM_30478: Record of new server connection added to default/servers db
* TS Definitely Typed Assignment issue is now FIXED
* MM_30478 : TS Definitely Typed Assignment \n Removed all the constructors but error still in editor tabs. But this time the app is not crashing
* MM_30478 : Attempt 1 [SUCCESSFUL]
* MM_30478 : Removing useDefineForClassFields
* MM_30478 : Retrieving the servers in a list + Improved the DB Manager and Babel config
* MM_30478 : Updated babel.config.js
* MM_30478 : Minor UI correction
* MM_30478 : Jest and Typescript configuration
* MM_30478 : A bit of housekeeping
* MM_30478 : Installed WDB on Android
* MM_30478 : Deletes new server record from default DB
* MM_30478 : Returns subset of server db instances
* MM_30478 : Code clean up
* MM_30478 : Code clean up on db manager
* MM_30478 : House keeping + Patch for WDB
* MM_30478 : Android - Saving & Deleting in FilesDir [COMPLETED]
* MM_30478 : Code clean up
* MM_30478 : Code clean up
* MM_30478 : Code clean up
* MM_30478 : Test successful on Android device
* MM_30478 : Rolling back change to jest.config.js
* MM_30478 : Updated test to test_integration
* MM_30478 : Fix imports
* MM_30478 : Refactored the manual testscript
* MM_30478 : Renamed database manager test file
* MM_30478 : Code clean up
* MM_30478 : Updated manual test file with a note.
* MM_30478 : Fixed JEST issue with TS
* MM_30478 : Fixed JEST issue with TS
* MM_30478 : Fixed JEST issue with TS
* MM_30478 : Implementing JEST test cases
* MM_30478 : Implementing JEST last test cases
* MM_30478 : Jest fixing ts errors
* MM_30478 : Database Manager Jest testing [ IN PROGRESS ]
* Update mobile v2 detox deps
* MM_30478 : Add uniqueness check for duplicates server creation
* MM_30478 : Corrections from Joseph reviews
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
Co-authored-by: Avinash Lingaloo <>
Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>
134 lines
5.0 KiB
TypeScript
134 lines
5.0 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 Channel from '@typings/database/channel';
|
|
import ChannelMembership from '@typings/database/channel_membership';
|
|
import GroupMembership from '@typings/database/group_membership';
|
|
import Post from '@typings/database/post';
|
|
import Preference from '@typings/database/preference';
|
|
import Reaction from '@typings/database/reaction';
|
|
import TeamMembership from '@typings/database/team_membership';
|
|
|
|
const {
|
|
CHANNEL,
|
|
CHANNEL_MEMBERSHIP,
|
|
GROUP_MEMBERSHIP,
|
|
POST,
|
|
PREFERENCE,
|
|
REACTION,
|
|
TEAM_MEMBERSHIP,
|
|
USER,
|
|
} = MM_TABLES.SERVER;
|
|
|
|
/**
|
|
* The User model represents the 'USER' entity and its relationship to other
|
|
* shareholders in the app.
|
|
*/
|
|
export default class User extends Model {
|
|
/** table (entity name) : User */
|
|
static table = USER;
|
|
|
|
/** associations : Describes every relationship to this entity. */
|
|
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;
|
|
|
|
/** 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 */
|
|
@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', (rawJson) => rawJson) 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', (rawJson) => rawJson) props!: UserProps;
|
|
|
|
/** timezone : The timezone for this user */
|
|
@json('timezone', (rawJson) => rawJson) 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[];
|
|
}
|