Skip to content

Commit

Permalink
Timestamp check
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweir committed Dec 23, 2024
1 parent 801c26d commit 5395024
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions packages/utils/src/synergy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -234,7 +237,7 @@ export async function findTopics(perspective, itemId) {
baseExpression: r.tag,
name: topic.topic,
relevance: r.relevance,
})
});
} catch (error) {
resolve(null);
}
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down

0 comments on commit 5395024

Please sign in to comment.