stream-chat 9.50.3 → 10.0.0-rc.2

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.
Files changed (242) hide show
  1. package/dist/cjs/index.browser.js +19798 -14472
  2. package/dist/cjs/index.browser.js.map +4 -4
  3. package/dist/cjs/index.node.js +19817 -14482
  4. package/dist/cjs/index.node.js.map +4 -4
  5. package/dist/esm/index.mjs +19795 -14469
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +221 -0
  8. package/dist/types/EventHandlerPipeline.d.ts +104 -0
  9. package/dist/types/api-client.d.ts +26 -0
  10. package/dist/types/campaign.d.ts +0 -44
  11. package/dist/types/channel.d.ts +454 -479
  12. package/dist/types/channel_batch_updater.d.ts +0 -93
  13. package/dist/types/channel_state.d.ts +53 -201
  14. package/dist/types/client.d.ts +451 -1920
  15. package/dist/types/client_state.d.ts +4 -4
  16. package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
  17. package/dist/types/configuration/index.d.ts +1 -0
  18. package/dist/types/configuration/types.d.ts +53 -0
  19. package/dist/types/connection.d.ts +49 -41
  20. package/dist/types/connection_fallback.d.ts +6 -4
  21. package/dist/types/constants.d.ts +0 -4
  22. package/dist/types/custom_types.d.ts +2 -0
  23. package/dist/types/entityStore/EntityStore.d.ts +111 -0
  24. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +60 -0
  25. package/dist/types/entityStore/applyReactionLocally.d.ts +26 -0
  26. package/dist/types/entityStore/index.d.ts +2 -0
  27. package/dist/types/errors.d.ts +10 -2
  28. package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
  29. package/dist/types/gen/chat/ChatApi.d.ts +334 -0
  30. package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
  31. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
  32. package/dist/types/gen/models/index.d.ts +8836 -0
  33. package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
  34. package/dist/types/gen-imports.d.ts +3 -0
  35. package/dist/types/index.d.ts +8 -7
  36. package/dist/types/insights.d.ts +9 -8
  37. package/dist/types/logger.d.ts +9 -0
  38. package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
  39. package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
  40. package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
  41. package/dist/types/messageComposer/configuration/types.d.ts +11 -11
  42. package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
  43. package/dist/types/messageComposer/messageComposer.d.ts +10 -10
  44. package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
  45. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
  46. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
  47. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
  48. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
  49. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
  50. package/dist/types/messageComposer/pollComposer.d.ts +5 -4
  51. package/dist/types/messageComposer/textComposer.d.ts +8 -3
  52. package/dist/types/messageComposer/types.d.ts +6 -28
  53. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
  54. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
  55. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
  56. package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
  57. package/dist/types/messageOperations/index.d.ts +3 -0
  58. package/dist/types/messageOperations/types.d.ts +49 -0
  59. package/dist/types/moderation.d.ts +21 -203
  60. package/dist/types/notifications/types.d.ts +8 -7
  61. package/dist/types/offline-support/offline_support_api.d.ts +111 -87
  62. package/dist/types/offline-support/offline_sync_manager.d.ts +0 -7
  63. package/dist/types/offline-support/types.d.ts +19 -23
  64. package/dist/types/offline-support/util.d.ts +4 -2
  65. package/dist/types/pagination/FilterBuilder.d.ts +1 -1
  66. package/dist/types/pagination/ItemIndex.d.ts +25 -0
  67. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
  68. package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
  69. package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
  70. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
  71. package/dist/types/pagination/filterCompiler.d.ts +7 -0
  72. package/dist/types/pagination/index.d.ts +1 -3
  73. package/dist/types/pagination/paginators/BasePaginator.d.ts +848 -0
  74. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +212 -0
  75. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +282 -0
  76. package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
  77. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
  78. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
  79. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
  80. package/dist/types/pagination/paginators/index.d.ts +7 -0
  81. package/dist/types/pagination/paginators/stateThrottling.d.ts +2 -0
  82. package/dist/types/pagination/sortCompiler.d.ts +49 -0
  83. package/dist/types/pagination/types.normalization.d.ts +11 -0
  84. package/dist/types/pagination/utility.normalization.d.ts +18 -0
  85. package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
  86. package/dist/types/pagination/utility.search.d.ts +13 -0
  87. package/dist/types/permissions.d.ts +1 -1
  88. package/dist/types/poll.d.ts +29 -32
  89. package/dist/types/poll_manager.d.ts +2 -2
  90. package/dist/types/reminders/Reminder.d.ts +2 -5
  91. package/dist/types/reminders/ReminderManager.d.ts +2 -9
  92. package/dist/types/search/MessageSearchSource.d.ts +4 -4
  93. package/dist/types/search/UserSearchSource.d.ts +1 -1
  94. package/dist/types/search/types.d.ts +3 -3
  95. package/dist/types/segment.d.ts +0 -34
  96. package/dist/types/signing.d.ts +105 -65
  97. package/dist/types/store.d.ts +1 -0
  98. package/dist/types/thread.d.ts +70 -34
  99. package/dist/types/thread_manager.d.ts +3 -3
  100. package/dist/types/token_manager.d.ts +15 -10
  101. package/dist/types/types.d.ts +197 -3404
  102. package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
  103. package/dist/types/utils/WithSubscriptions.d.ts +2 -1
  104. package/dist/types/utils/concurrency.d.ts +4 -4
  105. package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
  106. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
  107. package/dist/types/utils/retryable.d.ts +34 -0
  108. package/dist/types/utils/throttling/throttle.d.ts +36 -0
  109. package/dist/types/utils.d.ts +100 -194
  110. package/package.json +7 -3
  111. package/src/ChannelManager.ts +724 -0
  112. package/src/CooldownTimer.ts +2 -2
  113. package/src/EventHandlerPipeline.ts +228 -0
  114. package/src/LiveLocationManager.ts +12 -11
  115. package/src/api-client.ts +275 -0
  116. package/src/campaign.ts +1 -77
  117. package/src/channel.ts +1344 -1282
  118. package/src/channel_batch_updater.ts +1 -211
  119. package/src/channel_state.ts +144 -1013
  120. package/src/client.ts +936 -3995
  121. package/src/client_state.ts +4 -4
  122. package/src/configuration/InstanceConfigurationService.ts +73 -0
  123. package/src/configuration/index.ts +1 -0
  124. package/src/configuration/types.ts +81 -0
  125. package/src/connection.ts +145 -94
  126. package/src/connection_fallback.ts +29 -27
  127. package/src/constants.ts +1 -5
  128. package/src/custom_types.ts +4 -1
  129. package/src/entityStore/EntityStore.ts +208 -0
  130. package/src/entityStore/StoreBackedItemIndex.ts +115 -0
  131. package/src/entityStore/applyReactionLocally.ts +113 -0
  132. package/src/entityStore/index.ts +2 -0
  133. package/src/errors.ts +14 -2
  134. package/src/gen/chat/ChannelApi.ts +275 -0
  135. package/src/gen/chat/ChatApi.ts +2554 -0
  136. package/src/gen/model-decoders/decoders.ts +2680 -0
  137. package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
  138. package/src/gen/models/index.ts +12673 -0
  139. package/src/gen/moderation/ModerationApi.ts +607 -0
  140. package/src/gen-imports.ts +3 -0
  141. package/src/index.ts +11 -12
  142. package/src/insights.ts +6 -5
  143. package/src/logger.ts +28 -0
  144. package/src/messageComposer/LocationComposer.ts +9 -5
  145. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
  146. package/src/messageComposer/attachmentIdentity.ts +16 -9
  147. package/src/messageComposer/attachmentManager.ts +13 -8
  148. package/src/messageComposer/configuration/types.ts +11 -11
  149. package/src/messageComposer/linkPreviewsManager.ts +9 -10
  150. package/src/messageComposer/messageComposer.ts +57 -53
  151. package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
  152. package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
  153. package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
  154. package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
  155. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
  156. package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
  157. package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
  158. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
  159. package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
  160. package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
  161. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
  162. package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
  163. package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
  164. package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
  165. package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
  166. package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
  167. package/src/messageComposer/middleware/textComposer/types.ts +9 -4
  168. package/src/messageComposer/pollComposer.ts +6 -8
  169. package/src/messageComposer/textComposer.ts +27 -2
  170. package/src/messageComposer/types.ts +6 -28
  171. package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
  172. package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
  173. package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
  174. package/src/messageOperations/MessageOperations.ts +212 -0
  175. package/src/messageOperations/index.ts +10 -0
  176. package/src/messageOperations/types.ts +64 -0
  177. package/src/moderation.ts +38 -431
  178. package/src/notifications/types.ts +8 -7
  179. package/src/offline-support/offline_support_api.ts +200 -133
  180. package/src/offline-support/offline_sync_manager.ts +23 -44
  181. package/src/offline-support/types.ts +23 -26
  182. package/src/offline-support/util.ts +5 -4
  183. package/src/pagination/FilterBuilder.ts +4 -1
  184. package/src/pagination/ItemIndex.ts +25 -0
  185. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
  186. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
  187. package/src/pagination/cursorDerivation/index.ts +1 -0
  188. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
  189. package/src/pagination/filterCompiler.ts +196 -0
  190. package/src/pagination/index.ts +1 -3
  191. package/src/pagination/paginators/BasePaginator.ts +2859 -0
  192. package/src/pagination/paginators/ChannelPaginator.ts +729 -0
  193. package/src/pagination/paginators/MessageIntervalPaginator.ts +1116 -0
  194. package/src/pagination/paginators/MessagePaginator.ts +508 -0
  195. package/src/pagination/paginators/PinnedMessagePaginator.ts +108 -0
  196. package/src/pagination/paginators/ReminderPaginator.ts +107 -0
  197. package/src/pagination/paginators/UserGroupPaginator.ts +127 -0
  198. package/src/pagination/paginators/index.ts +7 -0
  199. package/src/pagination/paginators/stateThrottling.ts +31 -0
  200. package/src/pagination/sortCompiler.ts +193 -0
  201. package/src/pagination/types.normalization.ts +14 -0
  202. package/src/pagination/utility.normalization.ts +106 -0
  203. package/src/pagination/utility.queryChannel.ts +84 -0
  204. package/src/pagination/utility.search.ts +80 -0
  205. package/src/permissions.ts +7 -8
  206. package/src/poll.ts +101 -110
  207. package/src/poll_manager.ts +14 -8
  208. package/src/reminders/Reminder.ts +2 -5
  209. package/src/reminders/ReminderManager.ts +19 -21
  210. package/src/search/BaseSearchSource.ts +0 -3
  211. package/src/search/ChannelMemberSearchSource.ts +7 -1
  212. package/src/search/ChannelSearchSource.ts +10 -3
  213. package/src/search/MessageSearchSource.ts +29 -30
  214. package/src/search/UserSearchSource.ts +12 -8
  215. package/src/search/types.ts +3 -4
  216. package/src/segment.ts +1 -95
  217. package/src/signing.ts +107 -67
  218. package/src/store.ts +2 -1
  219. package/src/thread.ts +562 -238
  220. package/src/thread_manager.ts +37 -16
  221. package/src/token_manager.ts +21 -10
  222. package/src/types.ts +364 -4533
  223. package/src/uploadManager.ts +8 -0
  224. package/src/utils/FixedSizeQueueCache.ts +12 -6
  225. package/src/utils/WithSubscriptions.ts +2 -1
  226. package/src/utils/concurrency.ts +4 -4
  227. package/src/utils/mergeWith/mergeWith.ts +3 -3
  228. package/src/utils/mergeWith/mergeWithCore.ts +140 -164
  229. package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
  230. package/src/utils/retryable.ts +117 -0
  231. package/src/utils/throttling/throttle.ts +130 -0
  232. package/src/utils.ts +208 -754
  233. package/dist/types/channel_manager.d.ts +0 -122
  234. package/dist/types/events.d.ts +0 -72
  235. package/dist/types/pagination/BasePaginator.d.ts +0 -69
  236. package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
  237. package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
  238. package/src/channel_manager.ts +0 -830
  239. package/src/events.ts +0 -75
  240. package/src/pagination/BasePaginator.ts +0 -184
  241. package/src/pagination/ReminderPaginator.ts +0 -56
  242. package/src/pagination/UserGroupPaginator.ts +0 -93
@@ -1,15 +1,14 @@
1
1
  import type { Middleware, MiddlewareExecutionResult } from '../../../middleware';
2
2
  import type {
3
- DraftMessagePayload,
4
3
  LocalMessage,
5
- Message,
4
+ MessageRequest,
6
5
  SendMessageOptions,
7
6
  UpdatedMessage,
8
7
  } from '../../../types';
9
8
  import type { MessageComposer } from '../../messageComposer';
10
9
 
11
10
  export type MessageComposerMiddlewareState = {
12
- message: Message | UpdatedMessage;
11
+ message: MessageRequest | UpdatedMessage;
13
12
  localMessage: LocalMessage;
14
13
  sendOptions: SendMessageOptions;
15
14
  };
@@ -22,7 +21,7 @@ export type MessageComposerMiddlewareExecutorOptions = {
22
21
  };
23
22
 
24
23
  export type MessageDraftComposerMiddlewareValueState = {
25
- draft: DraftMessagePayload;
24
+ draft: MessageRequest;
26
25
  };
27
26
 
28
27
  export type MessageDraftComposerMiddlewareExecutorOptions = {
@@ -4,7 +4,7 @@ import type {
4
4
  MessageCompositionMiddleware,
5
5
  } from './types';
6
6
  import type { MiddlewareHandlerParams } from '../../../middleware';
7
- import type { OwnUserResponse } from '../../../types';
7
+ import type { OwnUserResponse, RequireLiteral } from '../../../types';
8
8
 
9
9
  export const createUserDataInjectionMiddleware = (
10
10
  composer: MessageComposer,
@@ -27,14 +27,18 @@ export const createUserDataInjectionMiddleware = (
27
27
  // precedence after we connectUser the first time and we get the connection health
28
28
  // check event. Due to how liberal the type of client.user is, we have to do it this
29
29
  // way to maintain type safety.
30
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
31
- const { channel_mutes, devices, mutes, ...messageUser } = composer.client
32
- .user as OwnUserResponse;
30
+
31
+ const {
32
+ channel_mutes: _channel_mutes,
33
+ devices: _devices,
34
+ mutes: _mutes,
35
+ ...messageUser
36
+ } = composer.client.user;
33
37
  return next({
34
38
  ...state,
35
39
  localMessage: {
36
40
  ...state.localMessage,
37
- user: messageUser,
41
+ user: messageUser as RequireLiteral<OwnUserResponse, 'blocked_user_ids'>, // TODO: drop RequireLiteral once the oapi spec is adjusted,
38
42
  user_id: messageUser.id,
39
43
  },
40
44
  });
@@ -21,7 +21,6 @@ export type PollStateValidationOutput = Partial<
21
21
 
22
22
  export type PollStateChangeValidator = (params: {
23
23
  data: PollComposerState['data'];
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
24
  value: any;
26
25
  currentError?: PollComposerFieldErrors[keyof PollComposerFieldErrors];
27
26
  }) => PollStateValidationOutput;
@@ -95,7 +94,6 @@ export type PollCompositionStateProcessorOutput = Partial<PollComposerState['dat
95
94
 
96
95
  export type PollCompositionStateProcessor = (params: {
97
96
  data: PollComposerState['data'];
98
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
97
  value: any;
100
98
  }) => PollCompositionStateProcessorOutput;
101
99
 
@@ -1,5 +1,5 @@
1
1
  import type { MiddlewareExecutionResult } from '../../../middleware';
2
- import type { CreatePollData, VotingVisibility } from '../../../types';
2
+ import type { CreatePollRequest, VotingVisibility } from '../../../types';
3
3
 
4
4
  export type PollComposerOption = {
5
5
  id: string;
@@ -19,17 +19,15 @@ export type UpdateFieldsData = Partial<Omit<PollComposerState['data'], 'options'
19
19
  options?: PollComposerOptionUpdate;
20
20
  };
21
21
 
22
- type Id = string;
23
-
24
22
  export type PollComposerFieldErrors = Partial<
25
- Omit<Record<keyof CreatePollData, string>, 'options'> & {
23
+ Omit<Record<keyof CreatePollRequest, string>, 'options'> & {
26
24
  options?: Record<string, string>;
27
25
  }
28
26
  >;
29
27
 
30
28
  export type PollComposerState = {
31
29
  data: {
32
- id: Id;
30
+ id: string;
33
31
  max_votes_allowed: string;
34
32
  name: string;
35
33
  options: PollComposerOption[];
@@ -38,14 +36,13 @@ export type PollComposerState = {
38
36
  description?: string;
39
37
  enforce_unique_vote?: boolean;
40
38
  is_closed?: boolean;
41
- user_id?: string;
42
39
  voting_visibility?: VotingVisibility;
43
40
  };
44
41
  errors: PollComposerFieldErrors;
45
42
  };
46
43
 
47
44
  export type PollComposerCompositionMiddlewareValueState = {
48
- data: CreatePollData;
45
+ data: CreatePollRequest;
49
46
  errors: PollComposerFieldErrors;
50
47
  };
51
48
 
@@ -2,6 +2,7 @@ import { createCommandsMiddleware } from './commands';
2
2
  import { createCommandEffectsMiddleware } from './commandEffects';
3
3
  import { createMentionsMiddleware } from './mentions';
4
4
  import { createTextComposerPreValidationMiddleware } from './validation';
5
+ import { chatLoggerSystem } from '../../../logger';
5
6
  import { MiddlewareExecutor } from '../../../middleware';
6
7
  import type {
7
8
  ExecuteParams,
@@ -16,6 +17,8 @@ import type {
16
17
  TextComposerState,
17
18
  } from './types';
18
19
 
20
+ const logger = chatLoggerSystem.getLogger('text-composer');
21
+
19
22
  export type TextComposerMiddlewareExecutorState<T extends Suggestion = Suggestion> =
20
23
  TextComposerState<T> & {
21
24
  change?: {
@@ -71,7 +74,13 @@ export class TextComposerMiddlewareExecutor<
71
74
  * That means the result of the previous search call as the debounced call result is unknown at the moment.
72
75
  * Custom search source implementation should handle errors meaningfully internally.
73
76
  */
74
- searchSource?.search(query)?.catch(console.error);
77
+ searchSource
78
+ ?.search(query)
79
+ ?.catch((error) =>
80
+ logger
81
+ .withExtraTags('execute')
82
+ .error('Searching for suggestions failed.', { error }),
83
+ );
75
84
 
76
85
  return result;
77
86
  }
@@ -1,5 +1,5 @@
1
1
  import type { Middleware } from '../../../middleware';
2
- import type { CommandResponse } from '../../../types';
2
+ import type { Command } from '../../../types';
3
3
  import type {
4
4
  CommandSuggestion,
5
5
  TextComposerCommandActivationEffect,
@@ -18,14 +18,14 @@ const emptyCommandStateToRestore: TextComposerCommandActivationStateToRestore =
18
18
  };
19
19
 
20
20
  const createCommandActivationEffect = (
21
- command: CommandResponse,
21
+ command: Command,
22
22
  ): TextComposerCommandActivationEffect => ({
23
23
  command,
24
24
  stateToRestore: emptyCommandStateToRestore,
25
25
  type: 'command.activate',
26
26
  });
27
27
 
28
- const isCommandResponse = (suggestion: unknown): suggestion is CommandSuggestion =>
28
+ const isCommand = (suggestion: unknown): suggestion is CommandSuggestion =>
29
29
  typeof (suggestion as CommandSuggestion | undefined)?.name === 'string';
30
30
 
31
31
  export const createCommandEffectsMiddleware = (): CommandEffectsMiddleware => ({
@@ -34,7 +34,7 @@ export const createCommandEffectsMiddleware = (): CommandEffectsMiddleware => ({
34
34
  onSuggestionItemSelect: ({ state, next, forward }) => {
35
35
  const { selectedSuggestion } = state.change ?? {};
36
36
  if (
37
- !isCommandResponse(selectedSuggestion) ||
37
+ !isCommand(selectedSuggestion) ||
38
38
  !state.command ||
39
39
  state.command.name !== selectedSuggestion.name
40
40
  ) {
@@ -1,5 +1,5 @@
1
1
  import type { MessageComposer } from '../../messageComposer';
2
- import type { CommandResponse, UserResponse } from '../../../types';
2
+ import type { Command, UserResponse } from '../../../types';
3
3
  import type { CommandSendability } from '../../configuration';
4
4
  import type { CommandSearchSource } from './commands';
5
5
 
@@ -49,7 +49,7 @@ export const getMentionedUsersInText = (text: string, mentionedUsers: UserRespon
49
49
  export const getCommandByName = (
50
50
  searchSource: CommandSearchSource,
51
51
  commandName?: string,
52
- ): CommandResponse | undefined => {
52
+ ): Command | undefined => {
53
53
  if (!commandName) return;
54
54
 
55
55
  const normalizedCommandName = commandName.toLowerCase();
@@ -58,10 +58,7 @@ export const getCommandByName = (
58
58
  .items.find((command) => command.name?.toLowerCase() === normalizedCommandName);
59
59
  };
60
60
 
61
- export const notifyCommandDisabled = (
62
- composer: MessageComposer,
63
- command: CommandResponse,
64
- ) => {
61
+ export const notifyCommandDisabled = (composer: MessageComposer, command: Command) => {
65
62
  const disabledReason = composer.getCommandDisabledReason(command);
66
63
  if (!disabledReason) return;
67
64
 
@@ -2,7 +2,7 @@ import type { Channel } from '../../../channel';
2
2
  import type { Middleware } from '../../../middleware';
3
3
  import type { SearchSourceOptions } from '../../../search';
4
4
  import { BaseSearchSourceSync } from '../../../search';
5
- import type { CommandResponse } from '../../../types';
5
+ import type { Command } from '../../../types';
6
6
  import { mergeWith } from '../../../utils/mergeWith';
7
7
  import type { MessageComposer } from '../../messageComposer';
8
8
  import type { CommandSuggestion, TextComposerMiddlewareOptions } from './types';
@@ -40,8 +40,8 @@ export class CommandSearchSource extends BaseSearchSourceSync<CommandSuggestion>
40
40
  query(searchQuery: string) {
41
41
  const channelConfig = this.channel.getConfig();
42
42
  const commands = channelConfig?.commands || [];
43
- const selectedCommands: (CommandResponse & { name: string })[] = commands.filter(
44
- (command): command is CommandResponse & { name: string } =>
43
+ const selectedCommands: Command[] = commands.filter(
44
+ (command): command is Command =>
45
45
  !!(
46
46
  command.name &&
47
47
  command.name.toLowerCase().indexOf(searchQuery.toLowerCase()) !== -1
@@ -13,8 +13,8 @@ export const userResponsesToMentionEntities = (users: UserResponse[]) =>
13
13
  users.map(userResponseToMentionEntity);
14
14
 
15
15
  export const mentionEntityToUserResponse = (entity: UserMentionEntity): UserResponse => {
16
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
16
  const { mentionType, ...user } = entity;
17
+ void mentionType;
18
18
  return user;
19
19
  };
20
20
 
@@ -487,7 +487,7 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
487
487
 
488
488
  return this.getMembersAndWatchers()
489
489
  .filter((user) => {
490
- if (user.id === this.client.userID) return false;
490
+ if (user.id === this.client.userId) return false;
491
491
  if (!searchQuery) return true;
492
492
 
493
493
  const updatedId = this.transliterate(removeDiacritics(user.id)).toLowerCase();
@@ -513,7 +513,7 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
513
513
  if (!this.memberSort) return (a.name || '').localeCompare(b.name || '');
514
514
 
515
515
  // Apply each sort criteria in order
516
- for (const [field, direction] of Object.entries(this.memberSort)) {
516
+ for (const { field, direction } of this.memberSort) {
517
517
  const aValue = a[field as keyof UserResponse];
518
518
  const bValue = b[field as keyof UserResponse];
519
519
 
@@ -534,20 +534,22 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
534
534
  ],
535
535
  ...this.userFilters,
536
536
  } as UserFilters,
537
- sort: this.userSort ?? ([{ name: 1 }, { id: 1 }] as UserSort), // todo: document the change - the sort is overridden, not merged
537
+ sort:
538
+ this.userSort ??
539
+ ([
540
+ { field: 'name', direction: 1 },
541
+ { field: 'id', direction: 1 },
542
+ ] satisfies UserSort), // todo: document the change - the sort is overridden, not merged
538
543
  options: { ...this.searchOptions, limit: this.pageSize, offset },
539
544
  });
540
545
 
541
546
  prepareQueryMembersParams = (searchQuery: string, offset = 0) => {
542
547
  // QueryMembers failed with error: \"sort must contain at maximum 1 item\"
543
- const maxSortParamsCount = 1;
544
- let sort: MemberSort = [{ user_id: 1 }];
545
- if (!this.memberSort) {
546
- sort = [{ user_id: 1 }];
547
- } else if (Array.isArray(this.memberSort)) {
548
- sort = this.memberSort[0];
549
- } else if (Object.keys(this.memberSort).length === maxSortParamsCount) {
550
- sort = this.memberSort;
548
+ let sort: MemberSort = [{ field: 'user_id', direction: 1 }];
549
+ if (!this.memberSort || !this.memberSort.length) {
550
+ sort = [{ field: 'user_id', direction: 1 }];
551
+ } else {
552
+ sort = this.memberSort.slice(0, 1);
551
553
  } // todo: document the change - the sort is overridden, not merged
552
554
  return {
553
555
  // todo: document the change - the filter is overridden, not merged
@@ -560,7 +562,13 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
560
562
 
561
563
  queryUsers = async (searchQuery: string, offset = 0) => {
562
564
  const { filters, sort, options } = this.prepareQueryUsersParams(searchQuery, offset);
563
- const { users } = await this.client.queryUsers(filters, sort, options);
565
+ const { users } = await this.client.queryUsers({
566
+ payload: {
567
+ filter_conditions: filters,
568
+ sort,
569
+ ...options,
570
+ },
571
+ });
564
572
  return users;
565
573
  };
566
574
 
@@ -569,7 +577,13 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
569
577
  searchQuery,
570
578
  offset,
571
579
  );
572
- const response = await this.channel.queryMembers(filters, sort, options);
580
+ const response = await this.channel.queryMembers({
581
+ payload: {
582
+ filter_conditions: filters,
583
+ sort,
584
+ ...options,
585
+ },
586
+ });
573
587
 
574
588
  return response.members.map((member) => member.user) as UserResponse[];
575
589
  };
@@ -721,13 +735,15 @@ export class MentionsSearchSource extends BaseSearchSource<MentionSuggestion> {
721
735
  return data.filter(
722
736
  (suggestion) =>
723
737
  suggestion.mentionType === 'user' &&
724
- mutedUsers.some((mute) => mute.target.id === suggestion.id),
738
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
739
+ mutedUsers.some((mute) => mute.target!.id === suggestion.id),
725
740
  );
726
741
  }
727
742
  return data.filter(
728
743
  (suggestion) =>
729
744
  suggestion.mentionType !== 'user' ||
730
- mutedUsers.every((mute) => mute.target.id !== suggestion.id),
745
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
746
+ mutedUsers.every((mute) => mute.target!.id !== suggestion.id),
731
747
  );
732
748
  }
733
749
 
@@ -1,6 +1,6 @@
1
1
  import type { MessageComposer } from '../../messageComposer';
2
2
  import type { MessageComposerEffect } from '../../messageComposer';
3
- import type { CommandResponse, UserResponse } from '../../../types';
3
+ import type { Command, Event, UserResponse } from '../../../types';
4
4
  import type { TokenizationPayload } from './textMiddlewareUtils';
5
5
  import type { SearchSource, SearchSourceSync } from '../../../search';
6
6
  import type { CustomTextComposerSuggestion } from '../../types.custom';
@@ -15,7 +15,7 @@ export type BaseSuggestion = {
15
15
 
16
16
  export type CommandSuggestionDisabledReason = 'editing' | 'quoted_message';
17
17
 
18
- export type CommandSuggestion = BaseSuggestion & CommandResponse;
18
+ export type CommandSuggestion = BaseSuggestion & Command;
19
19
  export type UserSuggestion = BaseSuggestion &
20
20
  UserResponse &
21
21
  TokenizationPayload & {
@@ -90,7 +90,7 @@ export type TextComposerCommandActivationStateToRestore =
90
90
  Partial<TextComposerStateSnapshot>;
91
91
 
92
92
  export type TextComposerCommandActivationEffect = {
93
- command: CommandResponse;
93
+ command: Command;
94
94
  stateToRestore?: TextComposerCommandActivationStateToRestore;
95
95
  type: 'command.activate';
96
96
  };
@@ -126,6 +126,11 @@ export type TextComposerState<T extends Suggestion = Suggestion> = {
126
126
  mentions?: MentionEntity[];
127
127
  selection: TextSelection;
128
128
  text: string;
129
- command?: CommandResponse | null;
129
+ /**
130
+ * Live typing events keyed by user id.
131
+ * Maps `user.id` -> latest typing event (`typing.start`/`typing.stop`) for that user.
132
+ */
133
+ typing: Record<string, Event>;
134
+ command?: Command | null;
130
135
  suggestions?: Suggestions<T>;
131
136
  };
@@ -45,7 +45,6 @@ export class PollComposer {
45
45
  max_votes_allowed: '',
46
46
  name: '',
47
47
  options: [{ id: generateUUIDv4(), text: '' }],
48
- user_id: this.composer.client.user?.id,
49
48
  voting_visibility: VotingVisibility.public,
50
49
  },
51
50
  errors: {},
@@ -76,9 +75,6 @@ export class PollComposer {
76
75
  get options() {
77
76
  return this.state.getLatestValue().data.options;
78
77
  }
79
- get user_id() {
80
- return this.state.getLatestValue().data.user_id;
81
- }
82
78
  get voting_visibility() {
83
79
  return this.state.getLatestValue().data.voting_visibility;
84
80
  }
@@ -86,7 +82,7 @@ export class PollComposer {
86
82
  get canCreatePoll() {
87
83
  const { data, errors } = this.state.getLatestValue();
88
84
  const hasAtLeastOneNonEmptyOption =
89
- data.options.filter((o) => !!o.text.trim()).length > 0;
85
+ Array.isArray(data.options) && data.options.some((o) => !!o.text?.trim());
90
86
  const hasName = !!data.name;
91
87
  const maxVotesAllowedNumber = parseInt(
92
88
  data.max_votes_allowed?.match(VALID_MAX_VOTES_VALUE_REGEX)?.[0] || '',
@@ -116,9 +112,11 @@ export class PollComposer {
116
112
  };
117
113
 
118
114
  /**
119
- * Updates specified fields and generates relevant errors
120
- * @param data
121
- * @param injectedFieldErrors - errors produced externally that will take precedence over the errors generated in the middleware chaing
115
+ * Updates specified fields and generates relevant errors.
116
+ *
117
+ * @param data - Partial poll data with the fields to update.
118
+ * @param injectedFieldErrors - Errors produced externally that will take precedence over the
119
+ * errors generated in the middleware chain.
122
120
  */
123
121
  // FIXME: change method params to a single object with the next major release
124
122
  updateFields = async (
@@ -18,7 +18,7 @@ import {
18
18
  userResponseToMentionEntity,
19
19
  } from './middleware/textComposer/mentionUtils';
20
20
  import type { MessageComposer } from './messageComposer';
21
- import type { CommandResponse, DraftMessage, LocalMessage, UserResponse } from '../types';
21
+ import type { Command, DraftMessage, Event, LocalMessage, UserResponse } from '../types';
22
22
 
23
23
  export type TextComposerOptions = {
24
24
  composer: MessageComposer;
@@ -120,6 +120,7 @@ const initState = ({
120
120
  mentionedUsers: [],
121
121
  mentions: [],
122
122
  text,
123
+ typing: {},
123
124
  selection: { start: text.length, end: text.length },
124
125
  };
125
126
  }
@@ -133,6 +134,7 @@ const initState = ({
133
134
  mentionedUsers,
134
135
  mentions,
135
136
  text,
137
+ typing: {},
136
138
  selection: { start: text.length, end: text.length },
137
139
  };
138
140
  };
@@ -227,6 +229,29 @@ export class TextComposer {
227
229
  return this.state.getLatestValue().text;
228
230
  }
229
231
 
232
+ get typing() {
233
+ return this.state.getLatestValue().typing;
234
+ }
235
+
236
+ set typing(typing: Record<string, Event>) {
237
+ this.state.partialNext({ typing });
238
+ }
239
+
240
+ setTyping = (typing: Record<string, Event>) => {
241
+ this.typing = typing;
242
+ };
243
+
244
+ setTypingEvent = (userId: string, event: Event) => {
245
+ this.typing = { ...this.typing, [userId]: event };
246
+ };
247
+
248
+ removeTypingEvent = (userId: string) => {
249
+ if (!this.typing[userId]) return;
250
+ const typing = { ...this.typing };
251
+ delete typing[userId];
252
+ this.typing = typing;
253
+ };
254
+
230
255
  get textIsEmpty() {
231
256
  return textIsEmpty(this.text);
232
257
  }
@@ -341,7 +366,7 @@ export class TextComposer {
341
366
  this.setMentions(mentions);
342
367
  };
343
368
 
344
- setCommand = (command: CommandResponse | null) => {
369
+ setCommand = (command: Command | null) => {
345
370
  if (!command) {
346
371
  this.clearCommand();
347
372
  return;
@@ -1,4 +1,5 @@
1
- import type { Attachment, FileUploadConfig, GiphyData } from '../types';
1
+ import type { CustomAttachmentData } from '../custom_types';
2
+ import type { Attachment, FileUploadConfig } from '../types';
2
3
 
3
4
  export type LocalAttachment = AnyLocalAttachment | LocalUploadAttachment;
4
5
 
@@ -57,54 +58,31 @@ export type UploadedAttachment =
57
58
  | VoiceRecordingAttachment;
58
59
 
59
60
  export type VoiceRecordingAttachment = Attachment & {
60
- asset_url: string;
61
61
  type: 'voiceRecording';
62
- duration?: number;
63
- file_size?: number;
64
- mime_type?: string;
65
- title?: string;
66
- waveform_data?: Array<number>;
62
+ custom: CustomAttachmentData & {
63
+ duration?: number;
64
+ waveform_data?: Array<number>;
65
+ };
67
66
  };
68
67
 
69
68
  export type FileAttachment = Attachment & {
70
69
  type: 'file';
71
- asset_url?: string;
72
- file_size?: number;
73
- mime_type?: string;
74
- title?: string;
75
70
  };
76
71
 
77
72
  export type AudioAttachment = Attachment & {
78
73
  type: 'audio';
79
- asset_url?: string;
80
- file_size?: number;
81
- mime_type?: string;
82
- title?: string;
83
74
  };
84
75
 
85
76
  export type VideoAttachment = Attachment & {
86
77
  type: 'video';
87
- asset_url?: string;
88
- file_size?: number;
89
- mime_type?: string;
90
- thumb_url?: string;
91
- title?: string;
92
78
  };
93
79
 
94
80
  export type ImageAttachment = Attachment & {
95
81
  type: 'image';
96
- fallback?: string;
97
- image_url?: string;
98
- original_height?: number;
99
- original_width?: number;
100
82
  };
101
83
 
102
84
  export type GiphyAttachment = Attachment & {
103
85
  type: 'giphy';
104
- giphy?: GiphyData;
105
- title?: string;
106
- title_link?: string;
107
- thumbnail_url?: string;
108
86
  };
109
87
 
110
88
  export type BaseLocalAttachmentMetadata = {