stream-chat 10.2.0 → 10.3.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.
- package/dist/cjs/index.browser.js +4712 -2818
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +4733 -2818
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +4712 -2818
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/channel.d.ts +62 -3
- package/dist/types/client.d.ts +9 -1
- package/dist/types/configuration/types.d.ts +2 -0
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +1 -0
- package/dist/types/gen/chat/ChatApi.d.ts +12 -1
- package/dist/types/gen/models/index.d.ts +659 -11
- package/dist/types/gen/moderation/ModerationApi.d.ts +3 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/messageComposer/attachmentManager.d.ts +2 -0
- package/dist/types/messageComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +1 -0
- package/dist/types/messageComposer/messageComposer.d.ts +33 -7
- package/dist/types/messageComposer/middleware/messageComposer/compositionValidation.d.ts +1 -2
- package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/middleware/messageComposer/scheduledMessage.d.ts +4 -0
- package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +1 -0
- package/dist/types/messageComposer/scheduledMessageComposition.d.ts +32 -0
- package/dist/types/messageMarks/MessageMarkManager.d.ts +44 -0
- package/dist/types/messageMarks/index.d.ts +1 -0
- package/dist/types/messageOperations/MessageOperations.d.ts +12 -1
- package/dist/types/messageOperations/index.d.ts +1 -0
- package/dist/types/messageOperations/reflectMessageMarkEvent.d.ts +9 -0
- package/dist/types/messageOperations/sendOrdering.d.ts +4 -3
- package/dist/types/messageOperations/types.d.ts +6 -2
- package/dist/types/notifications/types.d.ts +4 -0
- package/dist/types/offline-support/offline_support_api.d.ts +19 -1
- package/dist/types/offline-support/types.d.ts +19 -1
- package/dist/types/pagination/PaginatorView.d.ts +55 -0
- package/dist/types/pagination/index.d.ts +1 -0
- package/dist/types/pagination/paginators/BasePaginator.d.ts +41 -0
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +0 -9
- package/dist/types/pagination/paginators/MessageMarkPaginator.d.ts +61 -0
- package/dist/types/pagination/paginators/ScheduledMessagePaginator.d.ts +83 -0
- package/dist/types/pagination/paginators/index.d.ts +2 -0
- package/dist/types/scheduledMessages/ScheduledMessagePaginatorsManager.d.ts +47 -0
- package/dist/types/scheduledMessages/ScheduledMessageStatePolicy.d.ts +12 -0
- package/dist/types/scheduledMessages/ScheduledMessagesView.d.ts +38 -0
- package/dist/types/scheduledMessages/composition.d.ts +5 -0
- package/dist/types/scheduledMessages/constants.d.ts +56 -0
- package/dist/types/scheduledMessages/editResolvers.d.ts +4 -0
- package/dist/types/scheduledMessages/errors.d.ts +3 -0
- package/dist/types/scheduledMessages/eventHandlers.d.ts +8 -0
- package/dist/types/scheduledMessages/index.d.ts +7 -0
- package/dist/types/scheduledMessages/limits.d.ts +6 -0
- package/dist/types/scheduledMessages/types.d.ts +65 -0
- package/dist/types/thread.d.ts +12 -1
- package/dist/types/utils.d.ts +7 -0
- package/package.json +1 -1
- package/src/channel.ts +231 -7
- package/src/client.ts +46 -2
- package/src/configuration/keys.ts +2 -0
- package/src/configuration/shape.ts +15 -0
- package/src/configuration/types.ts +3 -1
- package/src/connection/ConnectionRecoveryManager.ts +7 -0
- package/src/errors.ts +11 -0
- package/src/gen/chat/ChatApi.ts +60 -3
- package/src/gen/models/index.ts +794 -23
- package/src/gen/moderation/ModerationApi.ts +24 -3
- package/src/index.ts +2 -0
- package/src/messageComposer/attachmentManager.ts +43 -24
- package/src/messageComposer/index.ts +1 -0
- package/src/messageComposer/messageComposer.ts +140 -32
- package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +2 -0
- package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +40 -47
- package/src/messageComposer/middleware/messageComposer/index.ts +1 -0
- package/src/messageComposer/middleware/messageComposer/scheduledMessage.ts +38 -0
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +8 -0
- package/src/messageComposer/scheduledMessageComposition.ts +324 -0
- package/src/messageMarks/MessageMarkManager.ts +145 -0
- package/src/messageMarks/index.ts +1 -0
- package/src/messageOperations/MessageOperationStatePolicy.ts +7 -0
- package/src/messageOperations/MessageOperations.ts +154 -1
- package/src/messageOperations/index.ts +1 -0
- package/src/messageOperations/reflectMessageMarkEvent.ts +47 -0
- package/src/messageOperations/reflectReactionEvent.ts +3 -0
- package/src/messageOperations/sendOrdering.ts +11 -4
- package/src/messageOperations/types.ts +6 -2
- package/src/notifications/types.ts +4 -0
- package/src/offline-support/offline_support_api.ts +61 -1
- package/src/offline-support/queueableOperations.ts +6 -0
- package/src/offline-support/types.ts +28 -0
- package/src/pagination/PaginatorView.ts +103 -0
- package/src/pagination/index.ts +1 -0
- package/src/pagination/paginators/BasePaginator.ts +179 -27
- package/src/pagination/paginators/ChannelPaginator.ts +8 -28
- package/src/pagination/paginators/MessageIntervalPaginator.ts +4 -1
- package/src/pagination/paginators/MessageMarkPaginator.ts +222 -0
- package/src/pagination/paginators/ScheduledMessagePaginator.ts +352 -0
- package/src/pagination/paginators/index.ts +2 -0
- package/src/scheduledMessages/ScheduledMessagePaginatorsManager.ts +268 -0
- package/src/scheduledMessages/ScheduledMessageStatePolicy.ts +42 -0
- package/src/scheduledMessages/ScheduledMessagesView.ts +57 -0
- package/src/scheduledMessages/composition.ts +129 -0
- package/src/scheduledMessages/constants.ts +79 -0
- package/src/scheduledMessages/editResolvers.ts +51 -0
- package/src/scheduledMessages/errors.ts +45 -0
- package/src/scheduledMessages/eventHandlers.ts +58 -0
- package/src/scheduledMessages/index.ts +7 -0
- package/src/scheduledMessages/limits.ts +32 -0
- package/src/scheduledMessages/types.ts +124 -0
- package/src/thread.ts +41 -17
- package/src/utils.ts +18 -0
package/src/thread.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { createMessageOperations } from './messageOperations';
|
|
|
24
24
|
import type { MessageOperations } from './messageOperations';
|
|
25
25
|
import { nowNs } from './utils/time';
|
|
26
26
|
import { WithSubscriptions } from './utils/WithSubscriptions';
|
|
27
|
+
import { ScheduledMessagesView } from './scheduledMessages/ScheduledMessagesView';
|
|
27
28
|
import { MessagePaginator } from './pagination';
|
|
28
29
|
import type { PaginatorCursor, ReconcileNewestMessagesOptions } from './pagination';
|
|
29
30
|
import { applyInstanceConfiguration } from './configuration/utils/applyInstanceConfiguration';
|
|
@@ -113,6 +114,13 @@ export class Thread extends WithSubscriptions {
|
|
|
113
114
|
public readonly messageComposer: MessageComposer;
|
|
114
115
|
public readonly messageOperations: MessageOperations;
|
|
115
116
|
public readonly messagePaginator: MessagePaginator;
|
|
117
|
+
/**
|
|
118
|
+
* The current user's scheduled replies in this thread: a view of the channel's
|
|
119
|
+
* `scheduledMessagesPaginator`, which holds the channel's scheduled messages and replies alike
|
|
120
|
+
* (the server cannot filter them by thread). Follows it while the thread's subscriptions are
|
|
121
|
+
* registered.
|
|
122
|
+
*/
|
|
123
|
+
public readonly scheduledMessages: ScheduledMessagesView;
|
|
116
124
|
|
|
117
125
|
private client: StreamChat;
|
|
118
126
|
private failedRepliesMap: Map<string, LocalMessage> = new Map();
|
|
@@ -230,6 +238,11 @@ export class Thread extends WithSubscriptions {
|
|
|
230
238
|
compositionContext: this,
|
|
231
239
|
});
|
|
232
240
|
|
|
241
|
+
this.scheduledMessages = new ScheduledMessagesView({
|
|
242
|
+
paginator: this.channel.scheduledMessagesPaginator,
|
|
243
|
+
scope: { parentId: this.id, type: 'thread' },
|
|
244
|
+
});
|
|
245
|
+
|
|
233
246
|
this.messageOperations = createMessageOperations(this);
|
|
234
247
|
|
|
235
248
|
// Same derivation path as `config.reset()`. Idempotent: re-applies what the constructors set.
|
|
@@ -440,7 +453,10 @@ export class Thread extends WithSubscriptions {
|
|
|
440
453
|
this.addUnsubscribeFunction(this.subscribeParentMessageFromStore());
|
|
441
454
|
this.addUnsubscribeFunction(this.subscribeMarkActiveThreadRead());
|
|
442
455
|
this.addUnsubscribeFunction(this.subscribeReloadActiveStaleThread());
|
|
456
|
+
this.addUnsubscribeFunction(this.subscribeLoadScheduledMessagesWhenActive());
|
|
443
457
|
this.addUnsubscribeFunction(this.subscribeMarkStaleOnStopWatching());
|
|
458
|
+
this.scheduledMessages.registerSubscriptions();
|
|
459
|
+
this.addUnsubscribeFunction(() => this.scheduledMessages.unregisterSubscriptions());
|
|
444
460
|
};
|
|
445
461
|
|
|
446
462
|
/**
|
|
@@ -501,6 +517,14 @@ export class Thread extends WithSubscriptions {
|
|
|
501
517
|
},
|
|
502
518
|
);
|
|
503
519
|
|
|
520
|
+
private subscribeLoadScheduledMessagesWhenActive = () =>
|
|
521
|
+
this.state.subscribeWithSelector(
|
|
522
|
+
({ active }) => ({ active }),
|
|
523
|
+
({ active }) => {
|
|
524
|
+
if (active) this.channel.ensureScheduledMessagesLoaded();
|
|
525
|
+
},
|
|
526
|
+
);
|
|
527
|
+
|
|
504
528
|
/**
|
|
505
529
|
* A watch stopped while the connection stays up (`NotWatching`) ends the channel's events with no
|
|
506
530
|
* reconnect to catch it. A dropped connection (`WasWatching`) is left to recovery.
|
|
@@ -633,24 +657,21 @@ export class Thread extends WithSubscriptions {
|
|
|
633
657
|
|
|
634
658
|
public handleMessageUpdated = (event: PipelineEvent) => {
|
|
635
659
|
if (!event.message) return;
|
|
636
|
-
//
|
|
637
|
-
|
|
638
|
-
const message =
|
|
660
|
+
// Events carry `own_reactions: []` and no marks; keep both from the held copy.
|
|
661
|
+
const held =
|
|
639
662
|
event.message.parent_id === this.id
|
|
640
|
-
?
|
|
641
|
-
...event.message,
|
|
642
|
-
own_reactions:
|
|
643
|
-
this.messagePaginator.getItem(event.message.id)?.own_reactions ??
|
|
644
|
-
event.message.own_reactions,
|
|
645
|
-
}
|
|
663
|
+
? this.messagePaginator.getItem(event.message.id)
|
|
646
664
|
: !event.message.parent_id && event.message.id === this.id
|
|
647
|
-
?
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
: event.message
|
|
665
|
+
? this.state.getLatestValue().parentMessage
|
|
666
|
+
: undefined;
|
|
667
|
+
const message = held
|
|
668
|
+
? {
|
|
669
|
+
...event.message,
|
|
670
|
+
own_reactions: held.own_reactions ?? event.message.own_reactions,
|
|
671
|
+
mark_groups: event.message.mark_groups ?? held.mark_groups,
|
|
672
|
+
own_marks: event.message.own_marks ?? held.own_marks,
|
|
673
|
+
}
|
|
674
|
+
: event.message;
|
|
654
675
|
this.updateParentMessageOrReplyLocally(message);
|
|
655
676
|
this.messagePaginator.reflectQuotedMessageUpdate(formatMessage(event.message));
|
|
656
677
|
};
|
|
@@ -842,7 +863,9 @@ const mergeThreadParticipants = (
|
|
|
842
863
|
/** `participant_limit` of the single-thread requests (`getThreadAndHydrate`, `reload()`). */
|
|
843
864
|
export const DEFAULT_THREAD_PARTICIPANT_LIMIT = 100;
|
|
844
865
|
|
|
845
|
-
/**
|
|
866
|
+
/**
|
|
867
|
+
* The thread's channel, with the members, custom data and server config of `threadData` applied.
|
|
868
|
+
*/
|
|
846
869
|
export const ensureThreadChannel = (
|
|
847
870
|
client: StreamChat,
|
|
848
871
|
threadData: ThreadStateResponse,
|
|
@@ -850,6 +873,7 @@ export const ensureThreadChannel = (
|
|
|
850
873
|
if (!threadData.channel) {
|
|
851
874
|
throw new Error('Thread channel is required when threadData is provided');
|
|
852
875
|
}
|
|
876
|
+
client._addChannelConfig(threadData.channel);
|
|
853
877
|
const channel = client.channelManager.ensure({
|
|
854
878
|
type: threadData.channel.type,
|
|
855
879
|
id: threadData.channel.id,
|
package/src/utils.ts
CHANGED
|
@@ -69,6 +69,17 @@ export function isFunction(value: unknown): value is (...args: unknown[]) => unk
|
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
export const pickFields = <T extends object, K extends keyof T>(
|
|
73
|
+
source: T,
|
|
74
|
+
fields: readonly K[],
|
|
75
|
+
): Pick<T, K> =>
|
|
76
|
+
Object.fromEntries(
|
|
77
|
+
fields.filter((field) => field in source).map((field) => [field, source[field]]),
|
|
78
|
+
) as Pick<T, K>;
|
|
79
|
+
|
|
80
|
+
export const omitFields = <T extends object>(source: T, fields: ReadonlySet<string>) =>
|
|
81
|
+
Object.fromEntries(Object.entries(source).filter(([field]) => !fields.has(field)));
|
|
82
|
+
|
|
72
83
|
export const chatCodes = {
|
|
73
84
|
TOKEN_EXPIRED: 40,
|
|
74
85
|
WS_CLOSED_SUCCESS: 1000,
|
|
@@ -107,6 +118,13 @@ export const channelHasReadEvents = (channel?: Channel) => {
|
|
|
107
118
|
return !(Array.isArray(ownCapabilities) && !ownCapabilities.includes('read-events'));
|
|
108
119
|
};
|
|
109
120
|
|
|
121
|
+
export const channelCanScheduleMessages = (channel?: Channel) => {
|
|
122
|
+
const ownCapabilities = channel?.data?.own_capabilities;
|
|
123
|
+
return !(
|
|
124
|
+
Array.isArray(ownCapabilities) && !ownCapabilities.includes('schedule-message')
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
110
128
|
/** Whether read events are off and the channel keeps a client-local unread count. */
|
|
111
129
|
export const channelTracksReadLocally = (channel?: Channel) =>
|
|
112
130
|
!!channel &&
|