@talkjs/core 1.6.2 → 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.
@@ -337,6 +337,8 @@ export declare interface ConversationRef {
337
337
  * Note that `Participant` is not the same as `User`.
338
338
  * A `Participant` represents a user's settings related to a specific conversation.
339
339
  *
340
+ * Calling this method multiple times with the same ID reuses the same {@link ParticipantRef} object.
341
+ *
340
342
  * Calling {@link ConversationRef.createIfNotExists|ConversationRef.createIfNotExists} or {@link ConversationRef.set|ConversationRef.set} will automatically add the current user as a participant.
341
343
  *
342
344
  * @example To add "Alice" to the conversation "Cats"
@@ -364,6 +366,9 @@ export declare interface ConversationRef {
364
366
  *
365
367
  * @remarks
366
368
  * Use this if you need to fetch, delete, or edit a specific message in this conversation, and you know its message ID.
369
+ *
370
+ * Calling this method multiple times with the same ID reuses the same {@link MessageRef} object.
371
+ *
367
372
  * To fetch the most recent messages in this conversation, use {@link ConversationRef.subscribeMessages} instead.
368
373
  * To send a message, use {@link ConversationRef.send}.
369
374
  *
@@ -582,6 +587,67 @@ export declare interface ConversationRef {
582
587
  markAsTyping(): Promise<void>;
583
588
  }
584
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
+
585
651
  /**
586
652
  * A snapshot of a conversation's attributes at a given moment in time.
587
653
  *
@@ -1293,6 +1359,8 @@ export declare interface MessageRef {
1293
1359
  * If you call `.reaction` with an invalid emoji, it will still succeed and you will still get a `ReactionRef`.
1294
1360
  * However, the TalkJS server will reject any calls that use an invalid emoji.
1295
1361
  *
1362
+ * Calling this method multiple times with the same emoji reuses the same {@link ReactionRef} object.
1363
+ *
1296
1364
  * In the future, this will also be used to fetch a full list of people who used that specific reaction on the message.
1297
1365
  *
1298
1366
  * @example Reacting to the message with a Unicode emoji
@@ -1334,6 +1402,66 @@ export declare interface MessageRef {
1334
1402
  delete(): Promise<void>;
1335
1403
  }
1336
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
+
1337
1465
  /**
1338
1466
  * A snapshot of a message's attributes at a given moment in time.
1339
1467
  *
@@ -1877,6 +2005,23 @@ export declare function registerPolyfills({ WebSocket }: {
1877
2005
  WebSocket: object;
1878
2006
  }): void;
1879
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
+
1880
2025
  /**
1881
2026
  * The version of {@link ContentBlock} that is used when sending or editing messages.
1882
2027
  *
@@ -2200,9 +2345,12 @@ export declare interface TalkSession {
2200
2345
  *
2201
2346
  * @remarks
2202
2347
  * This is the entry-point for all operations that affect a user globally, such as editing their name.
2348
+ *
2349
+ * Calling this method multiple times with the same ID reuses the same {@link UserRef} object.
2350
+ *
2203
2351
  * For operations related to a user's participation in a conversation, do: `session.conversation(<convId>).participant(<userId>)`
2204
2352
  *
2205
- * @see {@link Session.currentUser} which is a short-hand for `session.user(session.me.id)`.
2353
+ * @see {@link Session.currentUser} which is a short-hand for `session.user(meId)`.
2206
2354
  *
2207
2355
  * @example Initialising a user
2208
2356
  * ```
@@ -2232,6 +2380,8 @@ export declare interface TalkSession {
2232
2380
  * This is the entry-point for all conversation-related operations.
2233
2381
  * This includes operations affecting conversation attributes, but also anything related to messages and participants.
2234
2382
  *
2383
+ * Calling this method multiple times with the same ID reuses the same {@link ConversationRef} object.
2384
+ *
2235
2385
  * @example Ensure that the conversation exists and you are a participant
2236
2386
  * ```
2237
2387
  * session.conversation("test").createIfNotExists();
@@ -2285,6 +2435,88 @@ export declare interface TalkSession {
2285
2435
  * Remember to call `.unsubscribe` on the subscription once you are done with it.
2286
2436
  */
2287
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;
2288
2520
  /**
2289
2521
  * Upload a generic file without any additional metadata.
2290
2522
  *