forked from Ivasoft/mattermost-mobile
Remove posts in thread only when removing root posts (#7116)
This commit is contained in:
committed by
GitHub
parent
5cdcbfb12a
commit
bc3ace278b
@@ -18,7 +18,7 @@ const {SERVER: {POST, POSTS_IN_CHANNEL, POSTS_IN_THREAD}} = MM_TABLES;
|
||||
|
||||
export const prepareDeletePost = async (post: PostModel): Promise<Model[]> => {
|
||||
const preparedModels: Model[] = [post.prepareDestroyPermanently()];
|
||||
const relations: Array<Query<Model>> = [post.drafts, post.postsInThread, post.files, post.reactions];
|
||||
const relations: Array<Query<Model>> = [post.drafts, post.files, post.reactions];
|
||||
for await (const models of relations) {
|
||||
try {
|
||||
models.forEach((m) => {
|
||||
@@ -29,6 +29,20 @@ export const prepareDeletePost = async (post: PostModel): Promise<Model[]> => {
|
||||
}
|
||||
}
|
||||
|
||||
// If the post is a root post, delete the postsInThread model
|
||||
if (!post.rootId) {
|
||||
try {
|
||||
const postsInThread = await post.postsInThread.fetch();
|
||||
if (postsInThread) {
|
||||
postsInThread.forEach((m) => {
|
||||
preparedModels.push(m.prepareDestroyPermanently());
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// Record not found, do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// If thread exists, delete thread, participants and threadsInTeam
|
||||
try {
|
||||
const thread = await post.thread.fetch();
|
||||
|
||||
Reference in New Issue
Block a user