From 5395024b7fc936788171207f6a578f30370e59dd Mon Sep 17 00:00:00 2001 From: jhweir Date: Mon, 23 Dec 2024 18:08:37 +0000 Subject: [PATCH] Timestamp check --- packages/utils/src/synergy.ts | 43 +++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/utils/src/synergy.ts b/packages/utils/src/synergy.ts index 2ada447e8..e7dc44547 100644 --- a/packages/utils/src/synergy.ts +++ b/packages/utils/src/synergy.ts @@ -31,17 +31,20 @@ async function removeTopics(perspective, itemId) { })) as any; const topicRelationships = allRelationships.filter((r) => r.relevance); return Promise.all( - topicRelationships.map(async (topicRelationship) => new Promise(async (resolve: any) => { - try { - const topic = new Topic(perspective, topicRelationship.tag); - await topic.delete(); - await topicRelationship.delete(); - resolve() - } catch (error) { - resolve(); - } - }) - )); + topicRelationships.map( + async (topicRelationship) => + new Promise(async (resolve: any) => { + try { + const topic = new Topic(perspective, topicRelationship.tag); + await topic.delete(); + await topicRelationship.delete(); + resolve(); + } catch (error) { + resolve(); + } + }) + ) + ); } async function removeProcessedData(perspective, itemId) { @@ -234,7 +237,7 @@ export async function findTopics(perspective, itemId) { baseExpression: r.tag, name: topic.topic, relevance: r.relevance, - }) + }); } catch (error) { resolve(null); } @@ -327,13 +330,15 @@ export async function processItem(perspective, channelId, item, existingItem?: b latestSubgroup.baseExpression ); // calculate time since last item was created - const lastItemTimestamp = latestSubgroupItems[latestSubgroupItems.length - 1].timestamp; - const minsSinceLastItemCreated = - (new Date().getTime() - new Date(lastItemTimestamp).getTime()) / (1000 * 60); - if (minsSinceLastItemCreated < 30 || existingItem) { - // if less than 30 mins, consider the new item part of the latest conversation - conversation = latestConversation; - subgroupItems = latestSubgroupItems; + const lastItem = latestSubgroupItems[latestSubgroupItems.length - 1]; + if (lastItem) { + const minsSinceLastItemCreated = + (new Date().getTime() - new Date(lastItem.timestamp).getTime()) / (1000 * 60); + if (minsSinceLastItemCreated < 30) { + // if less than 30 mins, consider the new item part of the latest conversation + conversation = latestConversation; + subgroupItems = latestSubgroupItems; + } } } }