Files
mattermost-mobile/app/database/models/server/thread.ts
Anurag Shivarathri 8d6fc41dd5 [Gekidou MM-41093] CRT - WS Events, Actions, Queries, Thread Follow, Post Query (#6075)
* WS Events, Actions, Queries, Thread Follow, Post Query

* i18n changes

* Misc

* Only unread threads are marked as read

* Mark threads from WS even as visible in Global threads

* Merge fixes

* Update thread_post_list.tsx

* Merge fix

* Feedback fix

* Make teamId in handleThreads optional for unfollowed threads

* Removed unwated type and return

* Review changes

* Removing unused model

* Merge fix

* Misc fixes

* Following button query change
2022-04-04 19:55:13 +05:30

73 lines
3.0 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Query, 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';
import type PostModel from '@typings/database/models/servers/post';
import type ThreadModelInterface from '@typings/database/models/servers/thread';
import type ThreadInTeamModel from '@typings/database/models/servers/thread_in_team';
import type ThreadParticipantModel from '@typings/database/models/servers/thread_participant';
const {POST, THREAD, THREAD_PARTICIPANT, THREADS_IN_TEAM} = MM_TABLES.SERVER;
/**
* The Thread model contains thread information of a post.
*/
export default class ThreadModel extends Model implements ThreadModelInterface {
/** table (name) : Thread */
static table = THREAD;
/** associations : Describes every relationship to this table. */
static associations: Associations = {
/** A THREAD is associated to one POST (relationship is 1:1) */
[POST]: {type: 'belongs_to', key: 'id'},
/** A THREAD can have multiple THREAD_PARTICIPANT. (relationship is 1:N)*/
[THREAD_PARTICIPANT]: {type: 'has_many', foreignKey: 'thread_id'},
/** A THREAD can have multiple THREADS_IN_TEAM. (relationship is 1:N)*/
[THREADS_IN_TEAM]: {type: 'has_many', foreignKey: 'team_id'},
};
/** last_reply_at : The timestamp of when user last replied to the thread. */
@field('last_reply_at') lastReplyAt!: number;
/** last_viewed_at : The timestamp of when user last viewed the thread. */
@field('last_viewed_at') lastViewedAt!: number;
/** reply_count : The total replies to the thread by all the participants. */
@field('reply_count') replyCount!: number;
/** is_following: If user is following the thread or not */
@field('is_following') isFollowing!: boolean;
/** unread_replies : The number of replies that have not been read by the user. */
@field('unread_replies') unreadReplies!: number;
/** unread_mentions : The number of mentions that have not been read by the user. */
@field('unread_mentions') unreadMentions!: number;
/** viewed_at : The timestamp showing when the user's last opened this thread (this is used for the new line message indicator) */
@field('viewed_at') viewedAt!: number;
/** participants : All the participants associated with this Thread */
@children(THREAD_PARTICIPANT) participants!: Query<ThreadParticipantModel>;
/** threadsInTeam : All the threadsInTeam associated with this Thread */
@children(THREADS_IN_TEAM) threadsInTeam!: Query<ThreadInTeamModel>;
/** post : The root post of this thread */
@immutableRelation(POST, 'id') post!: Relation<PostModel>;
async destroyPermanently() {
await this.participants.destroyAllPermanently();
await this.threadsInTeam.destroyAllPermanently();
super.destroyPermanently();
}
}