Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,25 @@ class ChatwootImport {
return existingSourceIdsSet;
}

const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`); // Make sure the sourceId is always formatted as WAID:1234567890
let query: string;
if (conversationId) {
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2';
} else {
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
}

// Ensure all sourceIds are consistently prefixed with 'WAID:' as required by downstream systems and database queries.
const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`);
const pgClient = postgresClient.getChatwootConnection();
const result = await pgClient.query(query, [formattedSourceIds, conversationId]);

const params = conversationId ? [formattedSourceIds, conversationId] : [formattedSourceIds];

const query = conversationId
? 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2'
: 'SELECT source_id FROM messages WHERE source_id = ANY($1)';

const result = await pgClient.query(query, params);
for (const row of result.rows) {
existingSourceIdsSet.add(row.source_id);
}

return existingSourceIdsSet;
} catch (error) {
return null;
this.logger.error(`Error on getExistingSourceIds: ${error.toString()}`);
return new Set<string>();
}
}

Expand Down Expand Up @@ -336,7 +337,6 @@ class ChatwootImport {

this.deleteHistoryMessages(instance);
this.deleteRepositoryMessagesCache(instance);
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oriondesign2015 Não tem porque ter return 0 aqui. Ninguém espera retorno de importHistoryMessages

}
}

Expand Down
Loading