Skip to content

Commit

Permalink
refactor(provider): remove content of deleted threads before exposing…
Browse files Browse the repository at this point in the history
… them out while getting data
  • Loading branch information
bdbch committed Nov 20, 2024
1 parent 3fe0b91 commit aacfef4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/provider/src/TiptapCollabProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ export class TiptapCollabProvider extends HocuspocusProvider {
* @returns An array of threads as JSON objects
*/
getThreads<Data, CommentData>(): TCollabThread<Data, CommentData>[] {
return this.getYThreads().toJSON() as TCollabThread<Data, CommentData>[]
let threads = this.getYThreads().toJSON() as TCollabThread<Data, CommentData>[]

threads = threads.map(thread => ({
...thread,
deletedComments: thread.deletedComments.map(c => ({
...c,
content: null,
})),
}))

return threads
}

/**
Expand Down Expand Up @@ -263,7 +273,16 @@ export class TiptapCollabProvider extends HocuspocusProvider {
return null
}

return (!deleted ? this.getThread(threadId)?.comments : this.getThread(threadId)?.deletedComments) ?? []
let comments = !deleted ? this.getThread(threadId)?.comments : this.getThread(threadId)?.deletedComments

if (deleted) {
comments = comments?.map(c => ({
...c,
content: null,
}))
}

return comments ?? []
}

/**
Expand Down

0 comments on commit aacfef4

Please sign in to comment.