* Adds threads in team database table and handlers DM/GM channels have no team ID. This makes it troublesome to paginate threads in a team. The issue is that whenever a DM/GM thread is fetched from pagination it will be added in all teams in that server, potentially creating gaps in between threads for those teams. This PR inserts a new table in the DB ThreadsInTeam which will hold references of threads loaded in which server. Thread lists then would have to rely on that table to show threads. Co-authored-by: Elias Nahum <nahumhbl@gmail.com> Co-authored-by: Avinash Lingaloo <avinashlng1080@gmail.com>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 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';
|
|
|
|
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 {
|
|
/** 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: 'team_id'},
|
|
};
|
|
|
|
/** thread_id: Associated thread identifier */
|
|
@field('thread_id') threadId!: string;
|
|
|
|
/** team_id: Associated team identifier */
|
|
@field('team_id') teamId!: string;
|
|
|
|
@immutableRelation(THREAD, 'thread_id') thread!: Relation<ThreadModel>;
|
|
|
|
@immutableRelation(TEAM, 'team_id') team!: Relation<TeamModel>;
|
|
}
|