MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / findOrCreateThread

Function findOrCreateThread

apps/web/services/threads/index.ts:394–423  ·  view source on GitHub ↗
(thread: {
  channelId: string;
  externalThreadId: string;
  sentAt: number;
  lastReplyAt: number;
  slug?: string;
  messageCount?: number;
  title?: string;
})

Source from the content-addressed store, hash-verified

392}
393
394export const findOrCreateThread = async (thread: {
395 channelId: string;
396 externalThreadId: string;
397 sentAt: number;
398 lastReplyAt: number;
399 slug?: string;
400 messageCount?: number;
401 title?: string;
402}) => {
403 const exist = await prisma.threads.findUnique({
404 where: {
405 channelId_externalThreadId: {
406 channelId: thread.channelId,
407 externalThreadId: thread.externalThreadId,
408 },
409 },
410 include: {
411 messages: true,
412 },
413 });
414 if (exist) {
415 return exist;
416 }
417 return await prisma.threads.create({
418 data: thread,
419 include: {
420 messages: true,
421 },
422 });
423};
424
425export async function updateLastReplyAt({
426 lastReplyAt,

Callers 5

processThreadFunction · 0.90
saveMessagesSynchronousFunction · 0.90
saveMessagesTransactionFunction · 0.90
addMessageFunction · 0.90
changeMessageFunction · 0.90

Calls 1

createMethod · 0.45

Tested by

no test coverage detected