forked from Ivasoft/mattermost-mobile
* [Gekidou HOTFIX] fixes saving threads in the DB `loadedInGlobalThreads` cannot be a property of the thread, the DB will fail with unknown column upon saving. This commit makes it an argument of handleThreads and handleThreadInTeam. Fixes wrong foreignKey in THREAD table associations. * Fixes errors * Fixes error
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Relation} from '@nozbe/watermelondb';
|
|
import {field, immutableRelation} from '@nozbe/watermelondb/decorators';
|
|
import Model, {Associations} from '@nozbe/watermelondb/Model';
|
|
|
|
import {MM_TABLES} from '@constants/database';
|
|
|
|
import type TeamModel from '@typings/database/models/servers/team';
|
|
import type ThreadModel from '@typings/database/models/servers/thread';
|
|
import type ThreadInTeamModelInterface from '@typings/database/models/servers/thread_in_team';
|
|
|
|
const {TEAM, THREAD, THREADS_IN_TEAM} = MM_TABLES.SERVER;
|
|
|
|
/**
|
|
* ThreadInTeam model helps us to combine adjacent threads together without leaving
|
|
* gaps in between for an efficient user reading experience for threads.
|
|
*/
|
|
export default class ThreadInTeamModel extends Model implements ThreadInTeamModelInterface {
|
|
/** table (name) : ThreadsInTeam */
|
|
static table = THREADS_IN_TEAM;
|
|
|
|
/** associations : Describes every relationship to this table. */
|
|
static associations: Associations = {
|
|
|
|
/** A TEAM can have many THREADS_IN_TEAM. (relationship is N:1)*/
|
|
[TEAM]: {type: 'belongs_to', key: 'team_id'},
|
|
|
|
/** A THREAD can have many THREADS_IN_TEAM. (relationship is N:1)*/
|
|
[THREAD]: {type: 'belongs_to', key: 'thread_id'},
|
|
};
|
|
|
|
/** thread_id: Associated thread identifier */
|
|
@field('thread_id') threadId!: string;
|
|
|
|
/** team_id: Associated team identifier */
|
|
@field('team_id') teamId!: string;
|
|
|
|
/** loaded_in_global_threads : Flag to differentiate the unread threads loaded for showing unread counts/mentions */
|
|
@field('loaded_in_global_threads') loadedInGlobalThreads!: boolean;
|
|
|
|
@immutableRelation(THREAD, 'thread_id') thread!: Relation<ThreadModel>;
|
|
|
|
@immutableRelation(TEAM, 'team_id') team!: Relation<TeamModel>;
|
|
}
|