Skip to content

Commit 03fe90a

Browse files
authored
feat: add IndexedDB functions for message retrieval by rowId (#2709)
1 parent 69f117f commit 03fe90a

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/api/layers/retriever.layer.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@
1515
* along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18+
import { ChatListOptions } from '@wppconnect/wa-js/dist/chat';
1819
import { Page } from 'puppeteer';
1920
import { CreateConfig } from '../../config/create-config';
2021
import { SessionToken } from '../../token-store';
2122
import { evaluateAndReturn } from '../helpers';
2223
import {
2324
Chat,
24-
Contact,
2525
ContactStatus,
2626
ProfilePicThumbObj,
2727
WhatsappProfile,
2828
Wid,
2929
} from '../model';
3030
import { SenderLayer } from './sender.layer';
31-
import { ChatListOptions } from '@wppconnect/wa-js/dist/chat';
3231

3332
export class RetrieverLayer extends SenderLayer {
3433
constructor(public page: Page, session?: string, options?: CreateConfig) {
@@ -627,4 +626,44 @@ export class RetrieverLayer extends SenderLayer {
627626
phoneOrLid
628627
);
629628
}
629+
630+
/**
631+
* Get messages from IndexedDB 'model-storage' database starting from a specific rowId
632+
*
633+
* This function queries the IndexedDB database directly using the rowId index,
634+
* retrieving messages with rowId greater than the specified value.
635+
* It's useful for pagination or fetching messages in chronological order.
636+
*
637+
* @example
638+
* ```javascript
639+
* // Get 1000 messages after rowId 999960610
640+
* const messages = await client.getMessagesFromRowId({ minRowId: 999960610 });
641+
*
642+
* // Get 500 messages after rowId 999960610
643+
* const messages = await client.getMessagesFromRowId({
644+
* minRowId: 999960610,
645+
* limit: 500
646+
* });
647+
*
648+
* // Get all available messages after rowId (use with caution)
649+
* const messages = await client.getMessagesFromRowId({
650+
* minRowId: 999960610,
651+
* limit: -1
652+
* });
653+
* ```
654+
* @category Chat
655+
* @param options Options for fetching messages
656+
* @returns Promise that resolves to an array of message objects from IndexedDB
657+
*/
658+
public async getMessagesFromRowId(options: {
659+
minRowId: number;
660+
limit?: number;
661+
}): Promise<any[]> {
662+
return await evaluateAndReturn(
663+
this.page,
664+
// TODO: Change to WPP.indexdb.getMessagesFromRowId when version is released with this function
665+
(options) => (WPP as any).indexdb.getMessagesFromRowId(options),
666+
options
667+
);
668+
}
630669
}

0 commit comments

Comments
 (0)