Skip to content

Commit a817d62

Browse files
committed
Enhance message filtering in ChannelStartupService to support timestamp range queries
- Added support for filtering messages based on a timestamp range in the `ChannelStartupService`. - Introduced a `timestampFilter` object to handle `gte` and `lte` conditions for `messageTimestamp`. - Updated message count queries to include the new timestamp filtering logic.
1 parent 5404672 commit a817d62

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/api/services/channel.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,23 @@ export class ChannelStartupService {
551551
participants?: string;
552552
};
553553

554+
const timestampFilter = {};
555+
if (query?.where?.messageTimestamp) {
556+
if (query.where.messageTimestamp['gte'] && query.where.messageTimestamp['lte']) {
557+
timestampFilter['messageTimestamp'] = {
558+
gte: Math.floor(new Date(query.where.messageTimestamp['gte']).getTime() / 1000),
559+
lte: Math.floor(new Date(query.where.messageTimestamp['lte']).getTime() / 1000),
560+
};
561+
}
562+
}
563+
554564
const count = await this.prismaRepository.message.count({
555565
where: {
556566
instanceId: this.instanceId,
557567
id: query?.where?.id,
558568
source: query?.where?.source,
559569
messageType: query?.where?.messageType,
570+
...timestampFilter,
560571
AND: [
561572
keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {},
562573
keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {},
@@ -580,6 +591,7 @@ export class ChannelStartupService {
580591
id: query?.where?.id,
581592
source: query?.where?.source,
582593
messageType: query?.where?.messageType,
594+
...timestampFilter,
583595
AND: [
584596
keyFilters?.id ? { key: { path: ['id'], equals: keyFilters?.id } } : {},
585597
keyFilters?.fromMe ? { key: { path: ['fromMe'], equals: keyFilters?.fromMe } } : {},

0 commit comments

Comments
 (0)