Files
mattermost-mobile/app/database/models/server/thread_in_team.ts
Kyriakos Z 3326f34933 [Gekidou HOTFIX] fixes saving threads in the DB (#6132)
* [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
2022-04-06 17:37:17 +03:00

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>;
}