forked from Ivasoft/mattermost-mobile
* Refactors thread and threads_in_team tables The convention is that only threads being in the ThreadsInTeam will be shown in a thread list, and that only threads marked as loaded_in_global_threads are being shown in the All threads tab in the list. So when a thread arrives through different means, whether it's a WS event, or just fetching a (*new) thread by opening it in a channel, etc... we'll need to check if it's newer than any of the existing threads in the all threads list. If it is it will be added in the ThreadsInTeam and will be marked as loaded_in_global_threads: true. If it's not newer but it is an unread thread it will still be added in the ThreadsInTeam but marked as loaded_in_global_threads: false. This commit refactors `loaded_in_global_threads` field from the Thread table to the ThreadsInTeam table so that the above is possible. * Update tests * Addresses review comments
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: 'team_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>;
|
|
}
|