@talkjs/core 1.6.3 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -587,6 +587,67 @@ export declare interface ConversationRef {
587
587
  markAsTyping(): Promise<void>;
588
588
  }
589
589
 
590
+ /**
591
+ * Search object returned by `TalkSession.searchConversations` functions.
592
+ * Used to search for conversations the user is in.
593
+ * @public
594
+ */
595
+ export declare interface ConversationSearch {
596
+ /**
597
+ * Sets the query string for this search and starts searching for conversations whose `subject` or `custom.search` match the query.
598
+ *
599
+ * @remarks
600
+ * This resets the search to its initial state, clearing all previous results.
601
+ * Initially loads 3 results. Call {@link MessageSearch.loadMore} to load additional results.
602
+ *
603
+ * The query matches a conversation when, for each word in the query, that word appears in the conversation's subject or in `conversation.custom.search`.
604
+ * This means one of the words in the string starts with the word from the query.
605
+ * This is case-insensitive and punctuation at the start / end of words is ignored (in both the string and the query).
606
+ *
607
+ * A conversation titled `I like to look at rainbows`, will appear in searches for `rainbows`, `rain`, `look at`, `(look, i *LIKE* rain)`, and `look look look!`.
608
+ * It will not appear in searches for `bows`, `rain-bows`, `look-at`, or `I like to look at rainbows too`.
609
+ *
610
+ * It is not possible to match both a conversation's subject and its `custom.search` field at the same time.
611
+ * A conversation called `Kittens` with `custom.search: "where to buy food"` will not appear in a search for `kitten food`.
612
+ * However, this only applies per-conversation. If there is one conversation with subject `Kittens` and a second conversation with `custom.search: "Kittens"`, then a search for `kittens` will return both conversations.
613
+ *
614
+ * @returns A promise that resolves with the complete first page of results. The promise rejects if the search encounters an error.
615
+ */
616
+ setQuery(query: string): Promise<ConversationSearchState>;
617
+ /**
618
+ * Continues searching for more conversations.
619
+ *
620
+ * @remarks
621
+ * You can only call `loadMore` when the search has a query set, and is idle.
622
+ * Calling `loadMore` before calling `setQuery`, while the `setQuery` promise is still pending, or while another `loadMore` promise is pending, has no effect.
623
+ *
624
+ * @param limit - The number of results to load. `limit` should be between 1 and 50. Default 10.
625
+ * @returns A promise that resolves once finished loading, containing all the results from this page and all previous pages. The promise rejects if the search encounters an error.
626
+ */
627
+ loadMore(limit?: number): Promise<ConversationSearchState>;
628
+ }
629
+
630
+ /**
631
+ * The state of a conversation search in the current step.
632
+ *
633
+ * @public
634
+ */
635
+ export declare interface ConversationSearchState {
636
+ /**
637
+ * The conversations that were found in the search.
638
+ */
639
+ results: ConversationSnapshot[];
640
+ /**
641
+ * Whether all results have been loaded.
642
+ *
643
+ * @remarks
644
+ * Note: When true, this means that the search has reached the oldest matching conversation and no more conversations can be loaded.
645
+ * However, it does not mean that `results` contains every matching conversation.
646
+ * Any conversations that received messages since you called `setQuery`, may be missing from `results`.
647
+ */
648
+ loadedAll: boolean;
649
+ }
650
+
590
651
  /**
591
652
  * A snapshot of a conversation's attributes at a given moment in time.
592
653
  *
@@ -1341,6 +1402,66 @@ export declare interface MessageRef {
1341
1402
  delete(): Promise<void>;
1342
1403
  }
1343
1404
 
1405
+ /**
1406
+ * Search object returned by `TalkSession.searchMessages`.
1407
+ * Used to search for messages in the current user's conversations.
1408
+ *
1409
+ * @public
1410
+ */
1411
+ export declare interface MessageSearch {
1412
+ /**
1413
+ * Sets the query string for this search and starts searching for messages matching the query.
1414
+ *
1415
+ * @remarks
1416
+ * This resets the search to its initial state, clearing all previous results.
1417
+ * Initially loads 3 results. Call {@link MessageSearch.loadMore} to load additional results.
1418
+ *
1419
+ * The query matches a message when, for each word in the query, that word appears in the message text.
1420
+ * This means one of the words in the string starts with the word from the query.
1421
+ * This is case-insensitive and punctuation at the start / end of words is ignored (in both the string and the query).
1422
+ *
1423
+ * Non-text messages (such as uploaded images) are never returned by search.
1424
+ *
1425
+ * A message saying `I like to look at rainbows`, will appear in searches for `rainbows`, `rain`, `look at`, `(look, i *LIKE* rain)`, and `look look look!`.
1426
+ * It will not appear in searches for `bows`, `rain-bows`, `look-at`, or `I like to look at rainbows too`.
1427
+ *
1428
+ * @returns A promise that resolves with the complete first page of results. The promise rejects if the search encounters an error.
1429
+ */
1430
+ setQuery(query: string): Promise<MessageSearchState>;
1431
+ /**
1432
+ * Continues searching for more messages.
1433
+ *
1434
+ * @remarks
1435
+ * You can only call `loadMore` when the search has a query set, and is idle.
1436
+ * Calling `loadMore` before calling `setQuery`, while the `setQuery` promise is still pending, or while another `loadMore` promise is pending, has no effect.
1437
+ *
1438
+ * @param limit - The number of results to load. `limit` should be between 1 and 50. Default 10.
1439
+ * @returns A promise that resolves once finished loading, containing all the results from this page and all previous pages. The promise rejects if the search encounters an error.
1440
+ */
1441
+ loadMore(limit?: number): Promise<MessageSearchState>;
1442
+ }
1443
+
1444
+ /**
1445
+ * The state of a message search in the current step.
1446
+ *
1447
+ * @public
1448
+ */
1449
+ export declare interface MessageSearchState {
1450
+ /**
1451
+ * Contains all messages found by the search. Each message is paired up with the conversation it is from.
1452
+ */
1453
+ results: SearchMessageSnapshot[];
1454
+ /**
1455
+ * Whether all results have been loaded.
1456
+ *
1457
+ * @remarks
1458
+ * Note: When true, this means that the search has reached the oldest matching message and no more messages can be loaded.
1459
+ * However, it does not mean that `results` contains every matching message.
1460
+ * Any messages sent after you called `setQuery` will be missing from `results`.
1461
+ */
1462
+ loadedAll: boolean;
1463
+ }
1464
+
1344
1465
  /**
1345
1466
  * A snapshot of a message's attributes at a given moment in time.
1346
1467
  *
@@ -1884,6 +2005,23 @@ export declare function registerPolyfills({ WebSocket }: {
1884
2005
  WebSocket: object;
1885
2006
  }): void;
1886
2007
 
2008
+ /**
2009
+ * A snapshot of search results in a given moment in time.
2010
+ * contains a message and the conversation it from.
2011
+ *
2012
+ * @public
2013
+ */
2014
+ export declare interface SearchMessageSnapshot {
2015
+ /**
2016
+ * The conversation that the message was found in.
2017
+ */
2018
+ conversation: ConversationSnapshot;
2019
+ /**
2020
+ * The message that was found in the search.
2021
+ */
2022
+ message: MessageSnapshot;
2023
+ }
2024
+
1887
2025
  /**
1888
2026
  * The version of {@link ContentBlock} that is used when sending or editing messages.
1889
2027
  *
@@ -2297,6 +2435,88 @@ export declare interface TalkSession {
2297
2435
  * Remember to call `.unsubscribe` on the subscription once you are done with it.
2298
2436
  */
2299
2437
  subscribeConversations(onSnapshot?: (snapshot: ConversationSnapshot[], loadedAll: boolean) => void): ConversationListSubscription;
2438
+ /**
2439
+ * Creates a search for messages in all the current user's conversations.
2440
+ *
2441
+ * @remarks
2442
+ * Search is a two-step process. After calling `searchMessages`, call {@link MessageSearch.setQuery} to specify a search query and begin the search.
2443
+ *
2444
+ * As search can be quite slow, there are two different ways of using search:
2445
+ *
2446
+ * Option 1: Processing each search result as soon as it is received:
2447
+ *
2448
+ * ```ts
2449
+ * const search = session.searchMessages((results, status) => {
2450
+ * console.log("Found a new message. All messages found so far:", results);
2451
+ * });
2452
+ * search.setQuery("Hello");
2453
+ * ```
2454
+ *
2455
+ * Option 2: Wait until the full page is received (up to 60s delay) before processing:
2456
+ *
2457
+ * ```ts
2458
+ * const search = session.searchMessages();
2459
+ * const { results, loadedAll } = await search.setQuery("Hello");
2460
+ * console.log("Search completed, first page of messages:", results);
2461
+ * ```
2462
+ *
2463
+ * @param onResults - Callback to run whenever we receive new results or the status changes. Status `searching` means we are actively searching for more messages. `canLoadMore` means that the search is idle, but you can load older results with {@link MessageSearch.loadMore}. `loadedAll` means that there are no more messages to load.
2464
+ * @returns A search object. Call {@link MessageSearch.setQuery} to specify the string to search for, and begin receiving results.
2465
+ *
2466
+ * @example Basic UI integration (search-on-keypress)
2467
+ * ```ts
2468
+ * const search = session.searchMessages((results, status) => {
2469
+ * render(results, status);
2470
+ * });
2471
+ *
2472
+ * const searchInput = document.querySelector("#searchInput");
2473
+ * searchInput.addEventListener("change", () => {
2474
+ * search.setQuery(searchInput.value);
2475
+ * });
2476
+ * ```
2477
+ */
2478
+ searchMessages(onResults?: (results: SearchMessageSnapshot[], status: "searching" | "canLoadMore" | "loadedAll") => void): MessageSearch;
2479
+ /**
2480
+ * Creates a search for all the current user's conversations.
2481
+ *
2482
+ * @remarks
2483
+ * Search is a two-step process. After calling `searchConversations`, call {@link ConversationSearch.setQuery} to specify a search query and begin the search.
2484
+ *
2485
+ * As search can be quite slow, there are two different ways of using search:
2486
+ *
2487
+ * Option 1: Processing each search result as soon as it is received:
2488
+ *
2489
+ * ```ts
2490
+ * const search = session.searchConversations((results, status) => {
2491
+ * console.log("Found a new conversation. All conversations found so far:", results);
2492
+ * });
2493
+ * search.setQuery("Hello");
2494
+ * ```
2495
+ *
2496
+ * Option 2: Wait until the full page is received (up to 60s delay) before processing:
2497
+ *
2498
+ * ```ts
2499
+ * const search = session.searchConversations();
2500
+ * const { results, loadedAll } = await search.setQuery("Hello");
2501
+ * console.log("Search completed, first page of conversations:", results);
2502
+ * ```
2503
+ *
2504
+ * @param onResults - Callback to run whenever we receive new results or the status changes. Status `searching` means we are actively searching for more conversations. `canLoadMore` means that the search is idle, but you can load older results with {@link ConversationSearch.loadMore}. `loadedAll` means that there are no more conversations to load.
2505
+ * @returns A {@link ConversationSearch}. Call {@link ConversationSearch.setQuery} to specify the string to search for, and begin receiving results.
2506
+ *
2507
+ * @example Basic UI integration (search-on-keypress)
2508
+ * ```ts
2509
+ * const search = session.searchConversations((results, status) => {
2510
+ * render(results, status);
2511
+ * });
2512
+ *
2513
+ * const searchInput = document.querySelector("#searchInput");
2514
+ * searchInput.addEventListener("change", () => {
2515
+ * search.setQuery(searchInput.value);
2516
+ * });
2517
+ * ```
2518
+ */
2519
+ searchConversations(onResults?: (results: ConversationSnapshot[], status: "searching" | "canLoadMore" | "loadedAll") => void): ConversationSearch;
2300
2520
  /**
2301
2521
  * Upload a generic file without any additional metadata.
2302
2522
  *