(input: {
channelId: string;
limit?: number;
includePrivateMessages?: boolean;
server: ServerWithFlags;
})
| 413 | } |
| 414 | // TODO: Paginate get all questions response |
| 415 | export async function findAllChannelQuestions(input: { |
| 416 | channelId: string; |
| 417 | limit?: number; |
| 418 | includePrivateMessages?: boolean; |
| 419 | server: ServerWithFlags; |
| 420 | }) { |
| 421 | const threads = await findAllThreadsByParentId({ |
| 422 | parentId: input.channelId, |
| 423 | limit: input.limit, |
| 424 | }); |
| 425 | |
| 426 | const messages = await findManyMessagesWithAuthors( |
| 427 | threads.map((thread) => thread.id), |
| 428 | ); |
| 429 | |
| 430 | const messagesLookup = new Map( |
| 431 | messages.map((message) => [message.id, message]), |
| 432 | ); |
| 433 | const filteredThreads = threads.filter((thread) => { |
| 434 | const message = messagesLookup.get(thread.id); |
| 435 | if (!message) return false; |
| 436 | return input.includePrivateMessages ? true : message.public; |
| 437 | }); |
| 438 | |
| 439 | return filteredThreads |
| 440 | .map((thread) => { |
| 441 | const message = messagesLookup.get(thread.id); |
| 442 | return { |
| 443 | thread: thread, |
| 444 | message: message, |
| 445 | }; |
| 446 | }) |
| 447 | .filter(Boolean); |
| 448 | } |
| 449 | |
| 450 | export async function deleteMessage(id: string) { |
| 451 | return db.delete(dbMessages).where(eq(dbMessages.id, id)); |
nothing calls this directly
no test coverage detected