* Returns all threads matching a given roomId and query. If roomId is not * specified, it will return all threads matching the query, across all * rooms. * * Returns the results in the requested order. Please note: * 'asc' means by createdAt ASC * 'desc' means by updatedAt DES
(
// TODO: Implement caching here
roomId: string | undefined,
query: ThreadsQuery<TM> | undefined,
direction: "asc" | "desc",
subscriptions?: Record<SubscriptionKey, SubscriptionData>
)
| 184 | * Subscriptions are needed to filter threads based on the user's subscriptions. |
| 185 | */ |
| 186 | public findMany( |
| 187 | // TODO: Implement caching here |
| 188 | roomId: string | undefined, |
| 189 | query: ThreadsQuery<TM> | undefined, |
| 190 | direction: "asc" | "desc", |
| 191 | subscriptions?: Record<SubscriptionKey, SubscriptionData> |
| 192 | ): ThreadData<TM, CM>[] { |
| 193 | const index = direction === "desc" ? this.#desc : this.#asc; |
| 194 | const crit: ((thread: ThreadData<TM, CM>) => boolean)[] = []; |
| 195 | if (roomId !== undefined) { |
| 196 | crit.push((t) => t.roomId === roomId); |
| 197 | } |
| 198 | if (query !== undefined) { |
| 199 | crit.push(makeThreadsFilter(query, subscriptions)); |
| 200 | } |
| 201 | return Array.from(index.filter((t) => crit.every((pred) => pred(t)))); |
| 202 | } |
| 203 | } |
no test coverage detected