MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / updateMetrics

Method updateMetrics

apps/web/services/threads/index.ts:37–69  ·  view source on GitHub ↗
({
    messageId,
    threadId,
  }: {
    messageId: string;
    threadId: string;
  })

Source from the content-addressed store, hash-verified

35
36class ThreadsServices {
37 static async updateMetrics({
38 messageId,
39 threadId,
40 }: {
41 messageId: string;
42 threadId: string;
43 }) {
44 const thread = await prisma.threads.findUnique({
45 select: { firstManagerReplyAt: true, firstUserReplyAt: true },
46 where: { id: threadId },
47 });
48
49 if (areRepliesAtFilled(thread)) {
50 return Promise.resolve('nothing to update, already updated');
51 } else {
52 const [firstMessage, lastMessage] = await getFirstAndLastMessages(
53 threadId,
54 messageId
55 );
56 if (areAuthorSameAsReplier(firstMessage, lastMessage)) {
57 return Promise.resolve('nothing to update, same author');
58 }
59 if (lastMessage && isReplierManager(thread, lastMessage)) {
60 await updateThreadMetrics(threadId, lastMessage, 'firstManagerReplyAt');
61 return Promise.resolve('done, firstManagerReplyAt');
62 }
63 if (lastMessage && isReplierMember(thread, lastMessage)) {
64 await updateThreadMetrics(threadId, lastMessage, 'firstUserReplyAt');
65 return Promise.resolve('done, firstUserReplyAt');
66 }
67 }
68 return Promise.resolve('nothing to update');
69 }
70
71 static async find({ channelId, cursor, accountId }: FindType) {
72 const channel = await prisma.channels.findFirst({

Callers 1

eventNewMessageFunction · 0.80

Calls 6

areRepliesAtFilledFunction · 0.90
getFirstAndLastMessagesFunction · 0.90
areAuthorSameAsReplierFunction · 0.90
isReplierManagerFunction · 0.90
updateThreadMetricsFunction · 0.90
isReplierMemberFunction · 0.90

Tested by

no test coverage detected