forked from Ivasoft/mattermost-mobile
[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
This commit is contained in:
committed by
GitHub
parent
d1322e84ce
commit
8d6fc41dd5
@@ -4,6 +4,7 @@ import {Q} from '@nozbe/watermelondb';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
import type {Clause} from '@nozbe/watermelondb/QueryDescription';
|
||||
import type {RecordPair, SanitizeThreadParticipantsArgs} from '@typings/database/database';
|
||||
import type ThreadParticipantModel from '@typings/database/models/servers/thread_participant';
|
||||
|
||||
@@ -18,10 +19,20 @@ const {THREAD_PARTICIPANT} = MM_TABLES.SERVER;
|
||||
* @param {UserProfile[]} sanitizeThreadParticipants.rawParticipants
|
||||
* @returns {Promise<{createParticipants: ThreadParticipant[], deleteParticipants: ThreadParticipantModel[]}>}
|
||||
*/
|
||||
export const sanitizeThreadParticipants = async ({database, thread_id, rawParticipants}: SanitizeThreadParticipantsArgs) => {
|
||||
export const sanitizeThreadParticipants = async ({database, skipSync, thread_id, rawParticipants}: SanitizeThreadParticipantsArgs) => {
|
||||
const clauses: Clause[] = [Q.where('thread_id', thread_id)];
|
||||
|
||||
// Check if we already have the participants
|
||||
if (skipSync) {
|
||||
clauses.push(
|
||||
Q.where('user_id', Q.oneOf(
|
||||
rawParticipants.map((participant) => participant.id),
|
||||
)),
|
||||
);
|
||||
}
|
||||
const participants = (await database.collections.
|
||||
get(THREAD_PARTICIPANT).
|
||||
query(Q.where('thread_id', thread_id)).
|
||||
query(...clauses).
|
||||
fetch()) as ThreadParticipantModel[];
|
||||
|
||||
// similarObjects: Contains objects that are in both the RawParticipant array and in the ThreadParticipant table
|
||||
@@ -42,6 +53,10 @@ export const sanitizeThreadParticipants = async ({database, thread_id, rawPartic
|
||||
}
|
||||
}
|
||||
|
||||
if (skipSync) {
|
||||
return {createParticipants, deleteParticipants: []};
|
||||
}
|
||||
|
||||
// finding out elements to delete using array subtract
|
||||
const deleteParticipants = participants.
|
||||
filter((participant) => !similarObjects.includes(participant)).
|
||||
|
||||
Reference in New Issue
Block a user