forked from Ivasoft/mattermost-mobile
[Gekidou] Login entry point (#5568)
* Login entry point * feedback review * sort imports * Fix model relations * Handle when no current team or current channel has been selected * Fix MFA unit test * update prepareCommonSystemValues arguments
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Q, Query, Relation} from '@nozbe/watermelondb';
|
||||
import {children, field, immutableRelation, lazy} from '@nozbe/watermelondb/decorators';
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {children, field, immutableRelation} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
@@ -42,9 +42,6 @@ export default class ChannelModel extends Model {
|
||||
/** associations : Describes every relationship to this table. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A CHANNEL is associated with only one CHANNEL_INFO (relationship is 1:1) */
|
||||
[CHANNEL_INFO]: {type: 'has_many', foreignKey: 'channel_id'},
|
||||
|
||||
/** A CHANNEL can be associated with multiple CHANNEL_MEMBERSHIP (relationship is 1:N) */
|
||||
[CHANNEL_MEMBERSHIP]: {type: 'has_many', foreignKey: 'channel_id'},
|
||||
|
||||
@@ -54,12 +51,6 @@ export default class ChannelModel extends Model {
|
||||
/** A CHANNEL can be associated with multiple GROUPS_IN_CHANNEL (relationship is 1:N) */
|
||||
[GROUPS_IN_CHANNEL]: {type: 'has_many', foreignKey: 'channel_id'},
|
||||
|
||||
/** A CHANNEL is associated with only one MY_CHANNEL (relationship is 1:1) */
|
||||
[MY_CHANNEL]: {type: 'has_many', foreignKey: 'channel_id'},
|
||||
|
||||
/** A CHANNEL is associated to only one MY_CHANNEL_SETTINGS (relationship is 1:1) */
|
||||
[MY_CHANNEL_SETTINGS]: {type: 'has_many', foreignKey: 'channel_id'},
|
||||
|
||||
/** A CHANNEL can be associated with multiple POSTS_IN_CHANNEL (relationship is 1:N) */
|
||||
[POSTS_IN_CHANNEL]: {type: 'has_many', foreignKey: 'id'},
|
||||
|
||||
@@ -125,11 +116,12 @@ export default class ChannelModel extends Model {
|
||||
@immutableRelation(USER, 'creator_id') creator!: Relation<UserModel>;
|
||||
|
||||
/** info : Query returning extra information about this channel from CHANNEL_INFO table */
|
||||
@lazy info = this.collections.get(CHANNEL_INFO).query(Q.on(CHANNEL, 'id', this.id)) as Query<ChannelInfoModel>;
|
||||
// @lazy info = this.collections.get(CHANNEL_INFO).query(Q.on(CHANNEL, 'id', this.id)) as Query<ChannelInfoModel>;
|
||||
@immutableRelation(CHANNEL_INFO, 'id') info!: Relation<ChannelInfoModel>;
|
||||
|
||||
/** membership : Query returning the membership data for the current user if it belongs to this channel */
|
||||
@lazy membership = this.collections.get(MY_CHANNEL).query(Q.on(CHANNEL, 'id', this.id)) as Query<MyChannelModel>;
|
||||
@immutableRelation(MY_CHANNEL, 'id') membership!: Relation<MyChannelModel>;
|
||||
|
||||
/** settings: User specific settings/preferences for this channel */
|
||||
@lazy settings = this.collections.get(MY_CHANNEL_SETTINGS).query(Q.on(CHANNEL, 'id', this.id)) as Query<MyChannelSettingsModel>;
|
||||
@immutableRelation(MY_CHANNEL_SETTINGS, 'id') settings!: Relation<MyChannelSettingsModel>;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {field, immutableRelation} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import Model from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
@@ -20,13 +20,6 @@ export default class ChannelInfoModel extends Model {
|
||||
/** table (name) : ChannelInfo */
|
||||
static table = CHANNEL_INFO;
|
||||
|
||||
/** associations : Describes every relationship to this table. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A CHANNEL is associated with only one CHANNEL_INFO (relationship is 1:1) */
|
||||
[CHANNEL]: {type: 'belongs_to', key: 'id'},
|
||||
};
|
||||
|
||||
/** guest_count : The number of guest in this channel */
|
||||
@field('guest_count') guestCount!: number;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {field, immutableRelation} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import Model from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
@@ -18,13 +18,6 @@ export default class MyChannelModel extends Model {
|
||||
/** table (name) : MyChannel */
|
||||
static table = MY_CHANNEL;
|
||||
|
||||
/** associations : Describes every relationship to this table. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A CHANNEL can be associated to only one record from the MY_CHANNEL table (relationship is 1:1) */
|
||||
[CHANNEL]: {type: 'belongs_to', key: 'id'},
|
||||
};
|
||||
|
||||
/** last_post_at : The timestamp for any last post on this channel */
|
||||
@field('last_post_at') lastPostAt!: number;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {immutableRelation, json} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import Model from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import {safeParseJSON} from '@utils/helpers';
|
||||
@@ -20,13 +20,6 @@ export default class MyChannelSettingsModel extends Model {
|
||||
/** table (name) : MyChannelSettings */
|
||||
static table = MY_CHANNEL_SETTINGS;
|
||||
|
||||
/** associations : Describes every relationship to this table. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A CHANNEL is related to only one MY_CHANNEL_SETTINGS (relationship is 1:1) */
|
||||
[CHANNEL]: {type: 'belongs_to', key: 'id'},
|
||||
};
|
||||
|
||||
/** notify_props : Configurations with regards to this channel */
|
||||
@json('notify_props', safeParseJSON) notifyProps!: ChannelNotifyProps;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {field, relation} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import Model from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
@@ -18,13 +18,6 @@ export default class MyTeamModel extends Model {
|
||||
/** table (name) : MyTeam */
|
||||
static table = MY_TEAM;
|
||||
|
||||
/** associations : Describes every relationship to this table. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** TEAM and MY_TEAM have a 1:1 relationship. */
|
||||
[TEAM]: {type: 'belongs_to', key: 'id'},
|
||||
};
|
||||
|
||||
/** is_unread : Boolean flag for unread messages on team level */
|
||||
@field('is_unread') isUnread!: boolean;
|
||||
|
||||
@@ -35,5 +28,5 @@ export default class MyTeamModel extends Model {
|
||||
@field('roles') roles!: string;
|
||||
|
||||
/** team : The relation to the TEAM, that this user belongs to */
|
||||
@relation(MY_TEAM, 'id') team!: Relation<TeamModel>;
|
||||
@relation(TEAM, 'id') team!: Relation<TeamModel>;
|
||||
}
|
||||
|
||||
@@ -40,9 +40,6 @@ export default class PostModel extends Model {
|
||||
/** A POST can have multiple POSTS_IN_THREAD. (relationship is 1:N)*/
|
||||
[POSTS_IN_THREAD]: {type: 'has_many', foreignKey: 'id'},
|
||||
|
||||
/** A POST can have POST_METADATA. (relationship is 1:1)*/
|
||||
[POST_METADATA]: {type: 'has_many', foreignKey: 'id'},
|
||||
|
||||
/** A POST can have multiple REACTION. (relationship is 1:N)*/
|
||||
[REACTION]: {type: 'has_many', foreignKey: 'post_id'},
|
||||
|
||||
@@ -102,7 +99,7 @@ export default class PostModel extends Model {
|
||||
@children(FILE) files!: FileModel[];
|
||||
|
||||
/** metadata: All the extra data associated with this Post */
|
||||
@children(POST_METADATA) metadata!: PostMetadataModel[];
|
||||
@immutableRelation(POST_METADATA, 'id') metadata!: Relation<PostMetadataModel>;
|
||||
|
||||
/** reactions: All the reactions associated with this Post */
|
||||
@children(REACTION) reactions!: ReactionModel[];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {immutableRelation, json} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import Model from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import {safeParseJSON} from '@utils/helpers';
|
||||
@@ -19,13 +19,6 @@ export default class PostMetadataModel extends Model {
|
||||
/** table (name) : PostMetadata */
|
||||
static table = POST_METADATA;
|
||||
|
||||
/** associations : Describes every relationship to this table. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A POST can have multiple POST_METADATA.(relationship is 1:N)*/
|
||||
[POST]: {type: 'belongs_to', key: 'id'},
|
||||
};
|
||||
|
||||
/** data : Different types of data ranging from embeds to images. */
|
||||
@json('data', safeParseJSON) data!: PostMetadata;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Q, Query} from '@nozbe/watermelondb';
|
||||
import {children, field, lazy} from '@nozbe/watermelondb/decorators';
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {children, field, immutableRelation} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
@@ -42,15 +42,9 @@ export default class TeamModel extends Model {
|
||||
/** A TEAM has a 1:N relationship with GROUPS_IN_TEAM. A TEAM can possess multiple groups */
|
||||
[GROUPS_IN_TEAM]: {type: 'has_many', foreignKey: 'team_id'},
|
||||
|
||||
/** A TEAM has a 1:1 relationship with MY_TEAM. */
|
||||
[MY_TEAM]: {type: 'has_many', foreignKey: 'team_id'},
|
||||
|
||||
/** A TEAM has a 1:N relationship with SLASH_COMMAND. A TEAM can possess multiple slash commands */
|
||||
[SLASH_COMMAND]: {type: 'has_many', foreignKey: 'team_id'},
|
||||
|
||||
/** A TEAM has a 1:1 relationship with TEAM_CHANNEL_HISTORY.*/
|
||||
[TEAM_CHANNEL_HISTORY]: {type: 'has_many', foreignKey: 'team_id'},
|
||||
|
||||
/** A TEAM has a 1:N relationship with TEAM_MEMBERSHIP. A TEAM can regroup multiple users */
|
||||
[TEAM_MEMBERSHIP]: {type: 'has_many', foreignKey: 'team_id'},
|
||||
|
||||
@@ -91,14 +85,14 @@ export default class TeamModel extends Model {
|
||||
/** groupsInTeam : All the groups associated with this team */
|
||||
@children(GROUPS_IN_TEAM) groupsInTeam!: GroupsInTeamModel[];
|
||||
|
||||
/** myTeam : Retrieves additional information about the team that this user is possibly part of. This query might yield no result if the user isn't part of a team. */
|
||||
@lazy myTeam = this.collections.get(MY_TEAM).query(Q.on(TEAM, 'id', this.id)) as Query<MyTeamModel>;
|
||||
/** myTeam : Retrieves additional information about the team that this user is possibly part of. */
|
||||
@immutableRelation(MY_TEAM, 'id') myTeam!: Relation<MyTeamModel>;
|
||||
|
||||
/** slashCommands : All the slash commands associated with this team */
|
||||
@children(SLASH_COMMAND) slashCommands!: SlashCommandModel[];
|
||||
|
||||
/** teamChannelHistory : A history of the channels in this team that has been visited, ordered by the most recent and capped to the last 5 */
|
||||
@lazy teamChannelHistory = this.collections.get(TEAM_CHANNEL_HISTORY).query(Q.on(TEAM, 'id', this.id)) as Query<TeamChannelHistoryModel>;
|
||||
@immutableRelation(TEAM_CHANNEL_HISTORY, 'id') teamChannelHistory!: Relation<TeamChannelHistoryModel>;
|
||||
|
||||
/** members : All the users associated with this team */
|
||||
@children(TEAM_MEMBERSHIP) members!: TeamMembershipModel[];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import {Relation} from '@nozbe/watermelondb';
|
||||
import {immutableRelation, json} from '@nozbe/watermelondb/decorators';
|
||||
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
||||
import Model from '@nozbe/watermelondb/Model';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
import {safeParseJSON} from '@utils/helpers';
|
||||
@@ -20,13 +20,6 @@ export default class TeamChannelHistoryModel extends Model {
|
||||
/** table (name) : TeamChannelHistory */
|
||||
static table = TEAM_CHANNEL_HISTORY;
|
||||
|
||||
/** associations : Describes every relationship to this table. */
|
||||
static associations: Associations = {
|
||||
|
||||
/** A TEAM and TEAM_CHANNEL_HISTORY share a 1:1 relationship */
|
||||
[TEAM]: {type: 'belongs_to', key: 'id'},
|
||||
};
|
||||
|
||||
/** channel_ids : An array containing the last 5 channels visited within this team order by recency */
|
||||
@json('channel_ids', safeParseJSON) channelIds!: string[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user