|
15 | 15 | * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | */ |
17 | 17 |
|
| 18 | +import { ChatListOptions } from '@wppconnect/wa-js/dist/chat'; |
18 | 19 | import { Page } from 'puppeteer'; |
19 | 20 | import { CreateConfig } from '../../config/create-config'; |
20 | 21 | import { SessionToken } from '../../token-store'; |
21 | 22 | import { evaluateAndReturn } from '../helpers'; |
22 | 23 | import { |
23 | 24 | Chat, |
24 | | - Contact, |
25 | 25 | ContactStatus, |
26 | 26 | ProfilePicThumbObj, |
27 | 27 | WhatsappProfile, |
28 | 28 | Wid, |
29 | 29 | } from '../model'; |
30 | 30 | import { SenderLayer } from './sender.layer'; |
31 | | -import { ChatListOptions } from '@wppconnect/wa-js/dist/chat'; |
32 | 31 |
|
33 | 32 | export class RetrieverLayer extends SenderLayer { |
34 | 33 | constructor(public page: Page, session?: string, options?: CreateConfig) { |
@@ -627,4 +626,44 @@ export class RetrieverLayer extends SenderLayer { |
627 | 626 | phoneOrLid |
628 | 627 | ); |
629 | 628 | } |
| 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 | + } |
630 | 669 | } |
0 commit comments