Skip to content

Commit

Permalink
findOrCreateNewConversation bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweir committed Jan 21, 2025
1 parent 548fa7b commit 9c8ec73
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/utils/src/synergy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,15 @@ async function responsibleForProcessing(
async function findOrCreateNewConversation(perspective: PerspectiveProxy, channelId: string) {
const conversations = await Conversation.query(perspective, { source: channelId });
if (conversations.length) {
// if existing conversations found & last item in last conversation less than 30 mins old, use that conversation
// if existing conversations found & last item in last conversation subgroup less than 30 mins old, use that conversation
const lastConversation = conversations[conversations.length - 1];
const lastConversationItems = await getSynergyItems(perspective, lastConversation.baseExpression);
if (lastConversationItems.length) {
const lastItem = lastConversationItems[lastConversationItems.length - 1];
const conversationSubgroups = await ConversationSubgroup.query(perspective, {
source: lastConversation.baseExpression,
});
const lastSubgroup = conversationSubgroups[conversationSubgroups.length - 1] as any;
const lastSubgroupItems = await getSynergyItems(perspective, lastSubgroup.baseExpression);
if (lastSubgroupItems.length) {
const lastItem = lastSubgroupItems[lastSubgroupItems.length - 1];
const timeSinceLastItemCreated = new Date().getTime() - new Date(lastItem.timestamp).getTime();
const minsSinceLastItemCreated = timeSinceLastItemCreated / (1000 * 60);
if (minsSinceLastItemCreated < 30) return lastConversation;
Expand Down

0 comments on commit 9c8ec73

Please sign in to comment.