@amityco/ts-sdk 0.0.1-beta.27 → 0.0.1-beta.28

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 (185) hide show
  1. package/.eslintrc.json +1 -0
  2. package/dist/@types/core/payload.d.ts +12 -10
  3. package/dist/@types/core/payload.d.ts.map +1 -1
  4. package/dist/@types/domains/channel.d.ts +5 -1
  5. package/dist/@types/domains/channel.d.ts.map +1 -1
  6. package/dist/@types/domains/client.d.ts +13 -0
  7. package/dist/@types/domains/client.d.ts.map +1 -1
  8. package/dist/@types/domains/content.d.ts +26 -3
  9. package/dist/@types/domains/content.d.ts.map +1 -1
  10. package/dist/@types/domains/file.d.ts +36 -3
  11. package/dist/@types/domains/file.d.ts.map +1 -1
  12. package/dist/@types/domains/follow.d.ts +11 -0
  13. package/dist/@types/domains/follow.d.ts.map +1 -1
  14. package/dist/@types/domains/group.d.ts +1 -0
  15. package/dist/@types/domains/group.d.ts.map +1 -1
  16. package/dist/@types/domains/message.d.ts +13 -0
  17. package/dist/@types/domains/message.d.ts.map +1 -1
  18. package/dist/@types/global.d.ts +1 -0
  19. package/dist/@types/global.d.ts.map +1 -1
  20. package/dist/@types/index.d.ts +2 -2
  21. package/dist/@types/index.d.ts.map +1 -1
  22. package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
  23. package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -1
  24. package/dist/channel/api/banChannelMembers.d.ts.map +1 -1
  25. package/dist/channel/api/createChannel.d.ts.map +1 -1
  26. package/dist/channel/api/getChannel.d.ts.map +1 -1
  27. package/dist/channel/api/getChannels.d.ts.map +1 -1
  28. package/dist/channel/api/joinChannel.d.ts.map +1 -1
  29. package/dist/channel/api/leaveChannel.d.ts.map +1 -1
  30. package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
  31. package/dist/channel/api/queryChannels.d.ts.map +1 -1
  32. package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
  33. package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -1
  34. package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -1
  35. package/dist/channel/api/updateChannel.d.ts.map +1 -1
  36. package/dist/channel/events/index.d.ts +1 -0
  37. package/dist/channel/events/index.d.ts.map +1 -1
  38. package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
  39. package/dist/channel/events/onChannelDeleted.d.ts.map +1 -1
  40. package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
  41. package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
  42. package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -1
  43. package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -1
  44. package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
  45. package/dist/channel/observers/index.d.ts +1 -0
  46. package/dist/channel/observers/index.d.ts.map +1 -1
  47. package/dist/channel/observers/observeChannel.d.ts +1 -1
  48. package/dist/channel/observers/observeChannel.d.ts.map +1 -1
  49. package/dist/channel/observers/observeChannels.d.ts +17 -0
  50. package/dist/channel/observers/observeChannels.d.ts.map +1 -0
  51. package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts +2 -0
  52. package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts.map +1 -0
  53. package/dist/channel/utils/index.d.ts +2 -0
  54. package/dist/channel/utils/index.d.ts.map +1 -0
  55. package/dist/channel/utils/prepareChannelPayload.d.ts +3 -0
  56. package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -0
  57. package/dist/client/api/connectClient.d.ts +1 -8
  58. package/dist/client/api/connectClient.d.ts.map +1 -1
  59. package/dist/client/api/createClient.d.ts +8 -1
  60. package/dist/client/api/createClient.d.ts.map +1 -1
  61. package/dist/client/api/getFeedSettings.d.ts +16 -0
  62. package/dist/client/api/getFeedSettings.d.ts.map +1 -0
  63. package/dist/client/api/index.d.ts +1 -0
  64. package/dist/client/api/index.d.ts.map +1 -1
  65. package/dist/core/events.d.ts +3 -3
  66. package/dist/core/events.d.ts.map +1 -1
  67. package/dist/core/query/query.d.ts +1 -1
  68. package/dist/core/tests/query/query/runQuery.test.d.ts +2 -0
  69. package/dist/core/tests/query/query/runQuery.test.d.ts.map +1 -0
  70. package/dist/file/api/createVideo.d.ts +2 -1
  71. package/dist/file/api/createVideo.d.ts.map +1 -1
  72. package/dist/follow/api/queryFollowers.d.ts +1 -5
  73. package/dist/follow/api/queryFollowers.d.ts.map +1 -1
  74. package/dist/follow/api/queryFollowings.d.ts +1 -5
  75. package/dist/follow/api/queryFollowings.d.ts.map +1 -1
  76. package/dist/follow/observers/index.d.ts +2 -0
  77. package/dist/follow/observers/index.d.ts.map +1 -1
  78. package/dist/follow/observers/liveFollowers.d.ts +20 -0
  79. package/dist/follow/observers/liveFollowers.d.ts.map +1 -0
  80. package/dist/follow/observers/liveFollowings.d.ts +20 -0
  81. package/dist/follow/observers/liveFollowings.d.ts.map +1 -0
  82. package/dist/index.cjs.js +553 -111
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.esm.js +543 -112
  86. package/dist/index.umd.js +4 -4
  87. package/dist/message/api/queryMessages.d.ts +1 -10
  88. package/dist/message/api/queryMessages.d.ts.map +1 -1
  89. package/dist/message/observers/index.d.ts +1 -0
  90. package/dist/message/observers/index.d.ts.map +1 -1
  91. package/dist/message/observers/liveMessages.d.ts +20 -0
  92. package/dist/message/observers/liveMessages.d.ts.map +1 -0
  93. package/dist/message/observers/observeMessages.d.ts +0 -1
  94. package/dist/message/observers/observeMessages.d.ts.map +1 -1
  95. package/dist/message/observers/tests/liveMessages.test.d.ts +2 -0
  96. package/dist/message/observers/tests/liveMessages.test.d.ts.map +1 -0
  97. package/dist/post/observers/livePosts.d.ts.map +1 -1
  98. package/dist/utils/constants.d.ts +1 -0
  99. package/dist/utils/constants.d.ts.map +1 -1
  100. package/dist/utils/tests/client.d.ts +5 -2
  101. package/dist/utils/tests/client.d.ts.map +1 -1
  102. package/dist/utils/tests/dummy/channel.d.ts +10 -0
  103. package/dist/utils/tests/dummy/channel.d.ts.map +1 -0
  104. package/dist/utils/tests/dummy/index.d.ts +10 -0
  105. package/dist/utils/tests/dummy/index.d.ts.map +1 -0
  106. package/dist/utils/tests/dummy/message.d.ts +8 -0
  107. package/dist/utils/tests/dummy/message.d.ts.map +1 -0
  108. package/dist/utils/tests/{dummy.d.ts → dummy/post.d.ts} +3 -2
  109. package/dist/utils/tests/dummy/post.d.ts.map +1 -0
  110. package/dist/utils/tests/dummy/user.d.ts +2 -0
  111. package/dist/utils/tests/dummy/user.d.ts.map +1 -0
  112. package/dist/utils/tests/index.d.ts +2 -2
  113. package/dist/utils/tests/index.d.ts.map +1 -1
  114. package/package.json +1 -1
  115. package/src/@types/core/payload.ts +16 -10
  116. package/src/@types/domains/channel.ts +16 -1
  117. package/src/@types/domains/client.ts +17 -0
  118. package/src/@types/domains/content.ts +34 -3
  119. package/src/@types/domains/file.ts +42 -3
  120. package/src/@types/domains/follow.ts +28 -0
  121. package/src/@types/domains/group.ts +1 -0
  122. package/src/@types/domains/message.ts +20 -0
  123. package/src/@types/global.ts +2 -0
  124. package/src/@types/index.ts +3 -2
  125. package/src/channel/api/addChannelMembers.ts +6 -5
  126. package/src/channel/api/addChannelMembersRole.ts +5 -1
  127. package/src/channel/api/banChannelMembers.ts +7 -3
  128. package/src/channel/api/createChannel.ts +6 -2
  129. package/src/channel/api/getChannel.ts +5 -1
  130. package/src/channel/api/getChannels.ts +5 -1
  131. package/src/channel/api/joinChannel.ts +5 -1
  132. package/src/channel/api/leaveChannel.ts +5 -1
  133. package/src/channel/api/queryChannelMembers.ts +16 -12
  134. package/src/channel/api/queryChannels.ts +9 -4
  135. package/src/channel/api/removeChannelMembers.ts +6 -5
  136. package/src/channel/api/removeChannelMembersRole.ts +5 -1
  137. package/src/channel/api/unbanChannelMembers.ts +7 -3
  138. package/src/channel/api/updateChannel.ts +5 -1
  139. package/src/channel/events/index.ts +1 -0
  140. package/src/channel/events/onChannelCreated.ts +6 -2
  141. package/src/channel/events/onChannelDeleted.ts +6 -2
  142. package/src/channel/events/onChannelJoined.ts +6 -2
  143. package/src/channel/events/onChannelLeft.ts +6 -2
  144. package/src/channel/events/onChannelMemberAdded.ts +6 -2
  145. package/src/channel/events/onChannelMemberRemoved.ts +6 -2
  146. package/src/channel/events/onChannelUpdated.ts +6 -2
  147. package/src/channel/observers/index.ts +1 -0
  148. package/src/channel/observers/observeChannel.ts +1 -11
  149. package/src/channel/observers/observeChannels.ts +59 -0
  150. package/src/channel/tests/utils/prepareChannelPayload.test.ts +120 -0
  151. package/src/channel/utils/index.ts +1 -0
  152. package/src/channel/utils/prepareChannelPayload.ts +31 -0
  153. package/src/client/api/connectClient.ts +4 -9
  154. package/src/client/api/createClient.ts +19 -4
  155. package/src/client/api/getFeedSettings.ts +29 -0
  156. package/src/client/api/index.ts +2 -0
  157. package/src/core/events.ts +2 -1
  158. package/src/core/query/query.ts +3 -3
  159. package/src/core/tests/query/query/runQuery.test.ts +182 -0
  160. package/src/file/api/createVideo.ts +6 -0
  161. package/src/follow/api/queryFollowers.ts +3 -5
  162. package/src/follow/api/queryFollowings.ts +3 -5
  163. package/src/follow/api/utils.ts +7 -3
  164. package/src/follow/observers/index.ts +3 -0
  165. package/src/follow/observers/liveFollowers.ts +149 -0
  166. package/src/follow/observers/liveFollowings.ts +149 -0
  167. package/src/index.ts +1 -1
  168. package/src/message/api/queryMessages.ts +3 -10
  169. package/src/message/observers/index.ts +1 -0
  170. package/src/message/observers/liveMessages.ts +141 -0
  171. package/src/message/observers/observeMessages.ts +0 -1
  172. package/src/message/observers/tests/liveMessages.test.ts +133 -0
  173. package/src/post/observers/livePosts.ts +2 -1
  174. package/src/post/tests/api/getPost.test.ts +3 -3
  175. package/src/post/tests/api/queryPosts.test.ts +4 -4
  176. package/src/utils/constants.ts +1 -0
  177. package/src/utils/tests/client.ts +31 -3
  178. package/src/utils/tests/dummy/channel.ts +52 -0
  179. package/src/utils/tests/dummy/index.ts +7 -0
  180. package/src/utils/tests/dummy/message.ts +21 -0
  181. package/src/utils/tests/dummy/post.ts +31 -0
  182. package/src/utils/tests/dummy/user.ts +11 -0
  183. package/src/utils/tests/index.ts +2 -2
  184. package/dist/utils/tests/dummy.d.ts.map +0 -1
  185. package/src/utils/tests/dummy.ts +0 -7
package/dist/index.cjs.js CHANGED
@@ -21,6 +21,38 @@ var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
21
21
  var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
22
22
  var nativeIdGenerator__default = /*#__PURE__*/_interopDefaultLegacy(nativeIdGenerator);
23
23
 
24
+ const ContentFeedType = Object.freeze({
25
+ STORY: 'story',
26
+ CHIP: 'clip',
27
+ CHAT: 'chat',
28
+ POST: 'post',
29
+ });
30
+
31
+ const FileType = Object.freeze({
32
+ FILE: 'file',
33
+ IMAGE: 'image',
34
+ VIDEO: 'video',
35
+ });
36
+ const VideoResolution = Object.freeze({
37
+ '1080P': '1080p',
38
+ '720P': '720p',
39
+ '480P': '480p',
40
+ '360P': '360p',
41
+ ORIGINAL: 'original',
42
+ });
43
+ const VideoTranscodingStatus = Object.freeze({
44
+ UPLOADED: 'uploaded',
45
+ TRANSCODING: 'transcoding',
46
+ TRANSCODED: 'transcoded',
47
+ TRANSCODE_FAILED: 'transcodeFailed',
48
+ });
49
+ const VideoSize = Object.freeze({
50
+ LOW: 'low',
51
+ MEDIUM: 'medium',
52
+ HIGH: 'high',
53
+ ORIGINAL: 'original',
54
+ });
55
+
24
56
  var _a$1;
25
57
  /* eslint-disable no-undef */
26
58
  const theGlobal =
@@ -368,7 +400,7 @@ const isFresh = (model, lifeSpan = 0) => {
368
400
  * This wrapper is necessary to create for optimistically calls
369
401
  *
370
402
  *
371
- * @param fn A compatible API function from the ts sdk
403
+ * @param func A compatible API function from the ts sdk
372
404
  * @param args The arguments to pass to the function passed as `fn`
373
405
  * @returns A wrapper containing both the function and its future arguments
374
406
  *
@@ -654,8 +686,9 @@ const WS_EVENTS = [
654
686
  'connect_error',
655
687
  'reconnect_error',
656
688
  'reconnect_failed',
689
+ 'v3.channel.didCreate',
657
690
  'v3.channel.didUpdate',
658
- 'v3.channel.didUpdate',
691
+ 'v3.channel.didDelete',
659
692
  'v3.channel.didJoin',
660
693
  'v3.channel.didLeave',
661
694
  'v3.channel.didAddUsers',
@@ -20155,6 +20188,29 @@ const createMqttTransport = (endpoint) => {
20155
20188
  };
20156
20189
  };
20157
20190
 
20191
+ /**
20192
+ * ```js
20193
+ * import { getFeedSettings } from '@amityco/ts-sdk'
20194
+ * const feedSettings = await getFeedSettings()
20195
+ * const postFeedSetting = feedSettings.post
20196
+ * ```
20197
+ *
20198
+ * Fetches a {@link Amity.FeedSettings} object
20199
+ *
20200
+ * @returns A Promise of {@link Amity.FeedSettings} object
20201
+ *
20202
+ * @category Client API
20203
+ * @async
20204
+ */
20205
+ const getFeedSettings = async () => {
20206
+ const client = getActiveClient();
20207
+ const { data } = await client.http.get(`/api/v3/network-settings/feed-setting`);
20208
+ return Object.fromEntries(data.feedSettings.map(({ feedType, contentSettings }) => {
20209
+ return [feedType, contentSettings];
20210
+ }));
20211
+ };
20212
+
20213
+ const DEFAULT_DEBUG_SESSION = 'amity';
20158
20214
  /**
20159
20215
  * ```js
20160
20216
  * import { createClient } from '@amityco/ts-sdk'
@@ -20165,20 +20221,24 @@ const createMqttTransport = (endpoint) => {
20165
20221
  *
20166
20222
  * @param apiKey for the {@link Amity.Client} instance
20167
20223
  * @param apiRegion endpoint to connect to
20224
+ * @param apiEndpoint custom endpoint in case you don't want to use a preset endpoint
20168
20225
  * @param debugSession session's identifier for the client's logger instance
20169
20226
  * @returns A {@link Amity.Client} instance
20170
20227
  *
20171
20228
  * @category Client API
20172
20229
  * */
20173
- const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity') => {
20230
+ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, } = {}) => {
20231
+ var _a, _b;
20174
20232
  const log = createLogger(debugSession);
20175
20233
  log('client/api/createClient', {
20176
20234
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
20177
20235
  apiRegion,
20178
20236
  });
20179
- const http = createHttpTransport(computeUrl('http', apiRegion));
20180
- const ws = createWebsocketTransport(computeUrl('http', apiRegion));
20181
- const mqtt = createMqttTransport(computeUrl('mqtt', apiRegion));
20237
+ const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
20238
+ const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
20239
+ const http = createHttpTransport(httpEndpoint);
20240
+ const ws = createWebsocketTransport(httpEndpoint);
20241
+ const mqtt = createMqttTransport(mqttEndpoint);
20182
20242
  const emitter = createEventEmitter();
20183
20243
  const client = {
20184
20244
  version: `${VERSION$1}`,
@@ -20189,11 +20249,12 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity'
20189
20249
  mqtt,
20190
20250
  emitter,
20191
20251
  use: () => setActiveClient(client),
20252
+ getFeedSettings,
20192
20253
  };
20193
20254
  try {
20194
20255
  getActiveClient();
20195
20256
  }
20196
- catch (_a) {
20257
+ catch (_c) {
20197
20258
  setActiveClient(client);
20198
20259
  }
20199
20260
  return client;
@@ -20262,6 +20323,58 @@ const getDeviceInfo = () => {
20262
20323
  };
20263
20324
  };
20264
20325
 
20326
+ /**
20327
+ * Ingest a payload (v3) into the cache
20328
+ *
20329
+ * @param payload a "backend v3" payload object
20330
+ * @param order the order of the keys to process (in case of need)
20331
+ *
20332
+ * @category Cache
20333
+ * @hidden
20334
+ */
20335
+ const ingestInCache = (payload = {}, options) => {
20336
+ Object.entries(payload).forEach(([key, models]) => {
20337
+ const type = PAYLOAD2MODEL[key];
20338
+ if (!type)
20339
+ return;
20340
+ const resolver = getResolver(type);
20341
+ models.forEach(model => {
20342
+ upsertInCache(
20343
+ // eslint-disable @typescript-eslint no-explicit-any
20344
+ [type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
20345
+ model, options);
20346
+ });
20347
+ });
20348
+ };
20349
+
20350
+ const createUserEventSubscriber = (event, callback) => {
20351
+ const client = getActiveClient();
20352
+ const filter = (payload) => {
20353
+ if (client.cache) {
20354
+ ingestInCache(payload);
20355
+ }
20356
+ callback(payload.users[0]);
20357
+ };
20358
+ return createEventSubscriber(client, event, event, filter);
20359
+ };
20360
+
20361
+ /**
20362
+ * ```js
20363
+ * import { onUserDeleted } from '@amityco/ts-sdk'
20364
+ * const dispose = onUserDeleted(user => {
20365
+ * // ...
20366
+ * })
20367
+ * ```
20368
+ *
20369
+ * Fired when a {@link Amity.User} has been deleted
20370
+ *
20371
+ * @param callback The function to call when the event was fired
20372
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
20373
+ *
20374
+ * @category User Events
20375
+ */
20376
+ const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
20377
+
20265
20378
  /**
20266
20379
  * Retrieves a pair of {@link Amity.Tokens} necessary for connection
20267
20380
  *
@@ -20362,58 +20475,6 @@ const onClientBanned = (callback) => {
20362
20475
  });
20363
20476
  };
20364
20477
 
20365
- /**
20366
- * Ingest a payload (v3) into the cache
20367
- *
20368
- * @param payload a "backend v3" payload object
20369
- * @param order the order of the keys to process (in case of need)
20370
- *
20371
- * @category Cache
20372
- * @hidden
20373
- */
20374
- const ingestInCache = (payload = {}, options) => {
20375
- Object.entries(payload).forEach(([key, models]) => {
20376
- const type = PAYLOAD2MODEL[key];
20377
- if (!type)
20378
- return;
20379
- const resolver = getResolver(type);
20380
- models.forEach(model => {
20381
- upsertInCache(
20382
- // eslint-disable @typescript-eslint no-explicit-any
20383
- [type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
20384
- model, options);
20385
- });
20386
- });
20387
- };
20388
-
20389
- const createUserEventSubscriber = (event, callback) => {
20390
- const client = getActiveClient();
20391
- const filter = (payload) => {
20392
- if (client.cache) {
20393
- ingestInCache(payload);
20394
- }
20395
- callback(payload.users[0]);
20396
- };
20397
- return createEventSubscriber(client, event, event, filter);
20398
- };
20399
-
20400
- /**
20401
- * ```js
20402
- * import { onUserDeleted } from '@amityco/ts-sdk'
20403
- * const dispose = onUserDeleted(user => {
20404
- * // ...
20405
- * })
20406
- * ```
20407
- *
20408
- * Fired when a {@link Amity.User} has been deleted
20409
- *
20410
- * @param callback The function to call when the event was fired
20411
- * @returns an {@link Amity.Unsubscriber} function to stop listening
20412
- *
20413
- * @category User Events
20414
- */
20415
- const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
20416
-
20417
20478
  /* eslint-disable no-param-reassign */
20418
20479
  /**
20419
20480
  * ```js
@@ -20981,17 +21042,21 @@ const fileUrlWithSize = (fileUrl, size) => {
20981
21042
  * Creates an {@link Amity.File<'video'>}
20982
21043
  *
20983
21044
  * @param formData The data necessary to create a new {@link Amity.File<'video'>}
21045
+ * @param feedType The {@link Amity.File<'video'>} feed type
20984
21046
  * @param onProgress The callback to track the upload progress
20985
21047
  * @returns The newly created {@link Amity.File<'video'>}
20986
21048
  *
20987
21049
  * @category File API
20988
21050
  * @async
20989
21051
  */
20990
- const createVideo = async (formData, onProgress) => {
21052
+ const createVideo = async (formData, feedType, onProgress) => {
20991
21053
  const client = getActiveClient();
20992
21054
  client.log('file/createVideo', formData);
20993
21055
  if (!formData.getAll('files').length)
20994
21056
  throw new Error('The formData object must have a `files` key.');
21057
+ if (feedType) {
21058
+ formData.append('feedType', feedType);
21059
+ }
20995
21060
  const headers = 'getHeaders' in formData
20996
21061
  ? formData.getHeaders()
20997
21062
  : { 'content-type': 'multipart/form-data' };
@@ -23765,7 +23830,8 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
23765
23830
  };
23766
23831
 
23767
23832
  const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
23768
- const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
23833
+ const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
23834
+ const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
23769
23835
 
23770
23836
  /**
23771
23837
  * ```js
@@ -23967,6 +24033,23 @@ const isReportedByMe = async (referenceType, referenceId) => {
23967
24033
  return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
23968
24034
  };
23969
24035
 
24036
+ /** @hidden */
24037
+ const prepareChannelPayload = (payload) => {
24038
+ const client = getActiveClient();
24039
+ const channels = payload.channels.map(channel => {
24040
+ const channelUser = payload.channelUsers.find(channelUser => channelUser.userId === client.userId && channel.channelId === channelUser.channelId);
24041
+ const hasMention = channelUser
24042
+ ? channelUser.readToSegment < channelUser.lastMentionedSegment
24043
+ : false;
24044
+ const unreadCount = channelUser && channelUser.membership === 'member' && channel.messageCount
24045
+ ? Math.max(0, channel.messageCount - channelUser.readToSegment)
24046
+ : 0;
24047
+ return Object.assign(Object.assign({}, channel), { hasMention,
24048
+ unreadCount });
24049
+ });
24050
+ return Object.assign(Object.assign({}, payload), { channels });
24051
+ };
24052
+
23970
24053
  /**
23971
24054
  * ```js
23972
24055
  * import { queryChannels } from '@amityco/ts-sdk'
@@ -23990,16 +24073,17 @@ const queryChannels = async (query) => {
23990
24073
  // API-FIX: parameters should be querystring.
23991
24074
  // API-FIX: backend doesnt answer Amity.Response
23992
24075
  // const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
23993
- const { data } = await client.http.get(`/api/v3/channels`, {
24076
+ const { data: queryPayload } = await client.http.get(`/api/v3/channels`, {
23994
24077
  params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
23995
24078
  token: toToken(page, 'skiplimit'),
23996
24079
  } }),
23997
24080
  });
23998
- const { paging } = data, payload = __rest(data, ["paging"]);
23999
- const { channels } = payload;
24081
+ const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
24082
+ const data = prepareChannelPayload(payload);
24083
+ const { channels } = data;
24000
24084
  const cachedAt = client.cache && Date.now();
24001
24085
  if (client.cache) {
24002
- ingestInCache(payload, { cachedAt });
24086
+ ingestInCache(data, { cachedAt });
24003
24087
  const cacheKey = [
24004
24088
  'channel',
24005
24089
  'query',
@@ -24049,9 +24133,10 @@ const getChannels = async (channelIds) => {
24049
24133
  client.log('channel/getChannels', channelIds);
24050
24134
  const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
24051
24135
  // API-FIX: endpoint should not be /list, parameters should be querystring.
24052
- const { data } = await client.http.get(`/api/v3/channels/list`, {
24136
+ const { data: payload } = await client.http.get(`/api/v3/channels/list`, {
24053
24137
  params: { channelIds: encodedChannelIds },
24054
24138
  });
24139
+ const data = prepareChannelPayload(payload);
24055
24140
  const cachedAt = client.cache && Date.now();
24056
24141
  if (client.cache)
24057
24142
  ingestInCache(data, { cachedAt });
@@ -24110,7 +24195,8 @@ const getChannel = async (channelId) => {
24110
24195
  const client = getActiveClient();
24111
24196
  client.log('channel/getChannel', channelId);
24112
24197
  // API-FIX: endpoint should not be /list, parameters should be querystring.
24113
- const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
24198
+ const { data: payload } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
24199
+ const data = prepareChannelPayload(payload);
24114
24200
  const cachedAt = client.cache && Date.now();
24115
24201
  if (client.cache)
24116
24202
  ingestInCache(data, { cachedAt });
@@ -24171,10 +24257,11 @@ const createChannel = async (bundle) => {
24171
24257
  else {
24172
24258
  payload = await client.http.post('/api/v3/channels', bundle);
24173
24259
  }
24260
+ const data = prepareChannelPayload(payload.data);
24174
24261
  const cachedAt = client.cache && Date.now();
24175
24262
  if (client.cache)
24176
- ingestInCache(payload.data, { cachedAt });
24177
- const { channels } = payload.data;
24263
+ ingestInCache(data, { cachedAt });
24264
+ const { channels } = data;
24178
24265
  return {
24179
24266
  data: channels[0],
24180
24267
  cachedAt,
@@ -24199,7 +24286,8 @@ const createChannel = async (bundle) => {
24199
24286
  const updateChannel = async (channelId, patch) => {
24200
24287
  const client = getActiveClient();
24201
24288
  client.log('channel/updateChannel', channelId, patch);
24202
- const { data } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
24289
+ const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
24290
+ const data = prepareChannelPayload(payload);
24203
24291
  const cachedAt = client.cache && Date.now();
24204
24292
  if (client.cache)
24205
24293
  ingestInCache(data, { cachedAt });
@@ -24250,7 +24338,8 @@ const deleteChannel = async (channelId) => {
24250
24338
  const joinChannel = async (channelId) => {
24251
24339
  const client = getActiveClient();
24252
24340
  client.log('channel/joinChannel', channelId);
24253
- const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
24341
+ const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
24342
+ const data = prepareChannelPayload(payload);
24254
24343
  if (client.cache)
24255
24344
  ingestInCache(data);
24256
24345
  const { channelUsers } = data;
@@ -24274,7 +24363,8 @@ const joinChannel = async (channelId) => {
24274
24363
  const leaveChannel = async (channelId) => {
24275
24364
  const client = getActiveClient();
24276
24365
  client.log('channel/leaveChannel', channelId);
24277
- const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
24366
+ const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
24367
+ const data = prepareChannelPayload(payload);
24278
24368
  if (client.cache)
24279
24369
  ingestInCache(data);
24280
24370
  const { channelUsers } = data;
@@ -24299,16 +24389,17 @@ const queryChannelMembers = async (query) => {
24299
24389
  const client = getActiveClient();
24300
24390
  client.log('channel/queryChannelMembers', query);
24301
24391
  const _a = query !== null && query !== void 0 ? query : {}, { page, channelId } = _a, params = __rest(_a, ["page", "channelId"]);
24302
- const { data } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
24392
+ const { data: queryPayload } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
24303
24393
  params: Object.assign(Object.assign({}, params), { options: {
24304
24394
  token: toToken(page, 'skiplimit'),
24305
24395
  } }),
24306
24396
  });
24307
- const { paging } = data, payload = __rest(data, ["paging"]);
24308
- const { channelUsers } = payload;
24397
+ const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
24398
+ const data = prepareChannelPayload(payload);
24399
+ const { channelUsers } = data;
24309
24400
  const cachedAt = client.cache && Date.now();
24310
24401
  if (client.cache) {
24311
- ingestInCache(payload);
24402
+ ingestInCache(data);
24312
24403
  }
24313
24404
  const nextPage = toPage(paging.next);
24314
24405
  const prevPage = toPage(paging.previous);
@@ -24351,13 +24442,11 @@ queryChannelMembers.locally = (query) => {
24351
24442
  const addChannelMembers = async (channelId, userIds) => {
24352
24443
  const client = getActiveClient();
24353
24444
  client.log('channel/addChannelMembers', channelId, userIds);
24354
- const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
24445
+ const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
24446
+ const data = prepareChannelPayload(payload);
24355
24447
  if (client.cache)
24356
24448
  ingestInCache(data);
24357
- fireEvent('v3.channel.didAddUsers', {
24358
- channels: data.channels,
24359
- channelUsers: data.channelUsers,
24360
- });
24449
+ fireEvent('v3.channel.didAddUsers', data);
24361
24450
  const { channelUsers } = data;
24362
24451
  return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
24363
24452
  };
@@ -24380,13 +24469,11 @@ const addChannelMembers = async (channelId, userIds) => {
24380
24469
  const removeChannelMembers = async (channelId, userIds) => {
24381
24470
  const client = getActiveClient();
24382
24471
  client.log('channel/removeChannelMembers', channelId, userIds);
24383
- const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
24472
+ const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
24473
+ const data = prepareChannelPayload(payload);
24384
24474
  if (client.cache)
24385
24475
  ingestInCache(data);
24386
- fireEvent('v3.channel.didRemoveUsers', {
24387
- channels: data.channels,
24388
- channelUsers: data.channelUsers,
24389
- });
24476
+ fireEvent('v3.channel.didRemoveUsers', data);
24390
24477
  const { channelUsers } = data;
24391
24478
  return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
24392
24479
  };
@@ -24410,7 +24497,8 @@ const removeChannelMembers = async (channelId, userIds) => {
24410
24497
  const addChannelMembersRole = async (channelId, roleId, userIds) => {
24411
24498
  const client = getActiveClient();
24412
24499
  client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
24413
- const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
24500
+ const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
24501
+ const data = prepareChannelPayload(payload);
24414
24502
  if (client.cache)
24415
24503
  ingestInCache(data);
24416
24504
  const { channelUsers } = data;
@@ -24436,7 +24524,8 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
24436
24524
  const removeChannelMembersRole = async (channelId, roleId, userIds) => {
24437
24525
  const client = getActiveClient();
24438
24526
  client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
24439
- const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
24527
+ const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
24528
+ const data = prepareChannelPayload(payload);
24440
24529
  if (client.cache)
24441
24530
  ingestInCache(data);
24442
24531
  const { channelUsers } = data;
@@ -24460,13 +24549,14 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
24460
24549
  const banChannelMembers = async (channelId, userIds) => {
24461
24550
  const client = getActiveClient();
24462
24551
  client.log('channel/banChannelMembers', { userIds, channelId });
24463
- const payload = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
24552
+ const { data: payload } = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
24464
24553
  userIds,
24465
24554
  });
24555
+ const data = prepareChannelPayload(payload);
24466
24556
  const cachedAt = client.cache && Date.now();
24467
24557
  if (client.cache)
24468
- ingestInCache(payload.data, { cachedAt });
24469
- const { channelUsers } = payload.data;
24558
+ ingestInCache(data, { cachedAt });
24559
+ const { channelUsers } = data;
24470
24560
  return {
24471
24561
  data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
24472
24562
  cachedAt,
@@ -24490,19 +24580,45 @@ const banChannelMembers = async (channelId, userIds) => {
24490
24580
  const unbanChannelMembers = async (channelId, userIds) => {
24491
24581
  const client = getActiveClient();
24492
24582
  client.log('channel/unbanChannelMembers', { userIds, channelId });
24493
- const payload = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
24583
+ const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
24494
24584
  userIds,
24495
24585
  });
24586
+ const data = prepareChannelPayload(payload);
24496
24587
  const cachedAt = client.cache && Date.now();
24497
24588
  if (client.cache)
24498
- ingestInCache(payload.data, { cachedAt });
24499
- const { channelUsers } = payload.data;
24589
+ ingestInCache(data, { cachedAt });
24590
+ const { channelUsers } = data;
24500
24591
  return {
24501
24592
  data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
24502
24593
  cachedAt,
24503
24594
  };
24504
24595
  };
24505
24596
 
24597
+ /**
24598
+ * ```js
24599
+ * import { onChannelCreated } from '@amityco/ts-sdk'
24600
+ * const dispose = onChannelCreated(channel => {
24601
+ * // ...
24602
+ * })
24603
+ * ```
24604
+ *
24605
+ * Fired when any {@link Amity.Channel} have been created
24606
+ *
24607
+ * @param callback The function to call when the event was fired
24608
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24609
+ *
24610
+ * @category Channel Events
24611
+ */
24612
+ const onChannelCreated = (callback) => {
24613
+ const client = getActiveClient();
24614
+ const filter = (payload) => {
24615
+ const data = prepareChannelPayload(payload);
24616
+ ingestInCache(data);
24617
+ callback(data.channels[0]);
24618
+ };
24619
+ return createEventSubscriber(client, 'onChannelCreated', 'v3.channel.didCreate', filter);
24620
+ };
24621
+
24506
24622
  /**
24507
24623
  * ```js
24508
24624
  * import { onChannelUpdated } from '@amityco/ts-sdk'
@@ -24521,8 +24637,9 @@ const unbanChannelMembers = async (channelId, userIds) => {
24521
24637
  const onChannelUpdated = (callback) => {
24522
24638
  const client = getActiveClient();
24523
24639
  const filter = (payload) => {
24524
- ingestInCache(payload);
24525
- callback(payload.channels[0]);
24640
+ const data = prepareChannelPayload(payload);
24641
+ ingestInCache(data);
24642
+ callback(data.channels[0]);
24526
24643
  };
24527
24644
  return createEventSubscriber(client, 'onChannelUpdated', 'v3.channel.didUpdate', filter);
24528
24645
  };
@@ -24545,8 +24662,9 @@ const onChannelUpdated = (callback) => {
24545
24662
  const onChannelDeleted = (callback) => {
24546
24663
  const client = getActiveClient();
24547
24664
  const filter = (payload) => {
24548
- ingestInCache(payload);
24549
- callback(payload.channels[0]);
24665
+ const data = prepareChannelPayload(payload);
24666
+ ingestInCache(data);
24667
+ callback(data.channels[0]);
24550
24668
  };
24551
24669
  return createEventSubscriber(client, 'onChannelDeleted', 'v3.channel.didDelete', filter);
24552
24670
  };
@@ -24569,8 +24687,9 @@ const onChannelDeleted = (callback) => {
24569
24687
  const onChannelJoined = (callback) => {
24570
24688
  const client = getActiveClient();
24571
24689
  const filter = (payload) => {
24572
- ingestInCache(payload);
24573
- callback(payload.channels[0]);
24690
+ const data = prepareChannelPayload(payload);
24691
+ ingestInCache(data);
24692
+ callback(data.channels[0]);
24574
24693
  };
24575
24694
  return createEventSubscriber(client, 'onChannelJoined', 'v3.channel.didJoin', filter);
24576
24695
  };
@@ -24593,8 +24712,9 @@ const onChannelJoined = (callback) => {
24593
24712
  const onChannelLeft = (callback) => {
24594
24713
  const client = getActiveClient();
24595
24714
  const filter = (payload) => {
24596
- ingestInCache(payload);
24597
- callback(payload.channels[0]);
24715
+ const data = prepareChannelPayload(payload);
24716
+ ingestInCache(data);
24717
+ callback(data.channels[0]);
24598
24718
  };
24599
24719
  return createEventSubscriber(client, 'onChannelLeft', 'v3.channel.didLeave', filter);
24600
24720
  };
@@ -24617,8 +24737,9 @@ const onChannelLeft = (callback) => {
24617
24737
  const onChannelMemberAdded = (callback) => {
24618
24738
  const client = getActiveClient();
24619
24739
  const filter = (payload) => {
24620
- ingestInCache(payload);
24621
- callback(payload.channels[0], payload.channelUsers[0]);
24740
+ const data = prepareChannelPayload(payload);
24741
+ ingestInCache(data);
24742
+ callback(data.channels[0], data.channelUsers[0]);
24622
24743
  };
24623
24744
  return createEventSubscriber(client, 'onChannelMemberAdded', 'v3.channel.didAddUsers', filter);
24624
24745
  };
@@ -24641,8 +24762,9 @@ const onChannelMemberAdded = (callback) => {
24641
24762
  const onChannelMemberRemoved = (callback) => {
24642
24763
  const client = getActiveClient();
24643
24764
  const filter = (payload) => {
24644
- ingestInCache(payload);
24645
- callback(payload.channels[0], payload.channelUsers[0]);
24765
+ const data = prepareChannelPayload(payload);
24766
+ ingestInCache(data);
24767
+ callback(data.channels[0], data.channelUsers[0]);
24646
24768
  };
24647
24769
  return createEventSubscriber(client, 'onChannelMemberRemoved', 'v3.channel.didRemoveUsers', filter);
24648
24770
  };
@@ -24688,6 +24810,40 @@ const observeChannel = (channelId, callback) => {
24688
24810
  };
24689
24811
  };
24690
24812
 
24813
+ /**
24814
+ * ```js
24815
+ * import { observeChannels } from '@amityco/ts-sdk'
24816
+ *
24817
+ * let channels = []
24818
+ * const unsub = observeChannels(channel => merge(channels, channel))
24819
+ * ```
24820
+ *
24821
+ * Observe all mutations on a list of {@link Amity.Channel} for a current user
24822
+ *
24823
+ * @param callback the function to call when new data are available
24824
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
24825
+ *
24826
+ * @category Channel Observer
24827
+ */
24828
+ const observeChannels = (callback) => {
24829
+ const { log } = getActiveClient();
24830
+ const timestamp = Date.now();
24831
+ log(`observeChannels(tmpid: ${timestamp}) > listen`);
24832
+ const disposers = [];
24833
+ const router = (channel, action) => {
24834
+ var _a, _b;
24835
+ if (callback instanceof Function)
24836
+ return callback(channel);
24837
+ (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, channel);
24838
+ (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, channel);
24839
+ };
24840
+ disposers.push(onChannelCreated(data => router(data, 'onCreate')), onChannelUpdated(data => router(data, 'onUpdate')), onChannelDeleted(data => router(data, 'onDelete')), onChannelJoined(data => router(data, 'onJoin')), onChannelLeft(data => router(data, 'onLeft')), onChannelMemberAdded(data => router(data, 'onMemberAdded')), onChannelMemberRemoved(data => router(data, 'onMemberRemoved')));
24841
+ return () => {
24842
+ log(`observeChannels(tmpid: ${timestamp}) > dispose`);
24843
+ disposers.forEach(fn => fn());
24844
+ };
24845
+ };
24846
+
24691
24847
  /**
24692
24848
  * ```js
24693
24849
  * import { onMessageCreated } from '@amityco/ts-sdk'
@@ -24820,7 +24976,6 @@ const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
24820
24976
  *
24821
24977
  * Observe all mutations on a list of {@link Amity.Message} for a given {@link Amity.Channel} object
24822
24978
  *
24823
- * @param client the client to observe the message with
24824
24979
  * @param channelId the ID of the channel where to observe the messages
24825
24980
  * @param callback the function to call when new data are available
24826
24981
  * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
@@ -24848,6 +25003,98 @@ const observeMessages = (channelId, callback) => {
24848
25003
  };
24849
25004
  };
24850
25005
 
25006
+ /**
25007
+ * ```js
25008
+ * import { liveMessages } from '@amityco/ts-sdk'
25009
+ *
25010
+ * let messages = []
25011
+ * const unsub = liveMessages({
25012
+ * channelId: Amity.Channel['channelId'];
25013
+ * }, response => merge(messages, response.data))
25014
+ * ```
25015
+ *
25016
+ * Observe all mutations on a list of {@link Amity.Message} for a given target object
25017
+ *
25018
+ * @param params for querying memssages from a channel
25019
+ * @param callback the function to call when new data are available
25020
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
25021
+ *
25022
+ * @category Messages Live Collection
25023
+ */
25024
+ const liveMessages = (params, callback, config) => {
25025
+ const { log, cache } = getActiveClient();
25026
+ if (!cache) {
25027
+ console.log(ENABLE_CACHE_MESSAGE);
25028
+ }
25029
+ const timestamp = Date.now();
25030
+ log(`liveMessages(tmpid: ${timestamp}) > listen`);
25031
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
25032
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
25033
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
25034
+ const disposers = [];
25035
+ const cacheKey = ['message', 'collection', { channelId: params.channelId }];
25036
+ const responder = (data) => {
25037
+ var _a, _b;
25038
+ let messages = (_a = data.data
25039
+ .map(messageId => pullFromCache(['message', 'get', messageId]))
25040
+ .filter(Boolean)
25041
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
25042
+ /*
25043
+ * for cases when message is deleted via RTE, this flag is used to get
25044
+ * items fro cache that are deleted | !deleted
25045
+ */
25046
+ messages = filterByPropEquality(messages, 'isDeleted', params.isDeleted);
25047
+ callback({
25048
+ onNextPage: onFetch,
25049
+ data: messages,
25050
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
25051
+ loading: data.loading,
25052
+ error: data.error,
25053
+ });
25054
+ };
25055
+ const realtimeRouter = (message, action) => {
25056
+ var _a;
25057
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25058
+ if (params.channelId !== message.channelId || !collection)
25059
+ return;
25060
+ if (action === 'onCreate') {
25061
+ collection.data = [...new Set([message.messageId, ...collection.data])];
25062
+ }
25063
+ else if (['onDelete'].includes(action)) {
25064
+ collection.data = collection.data.filter(m => m !== message.messageId);
25065
+ }
25066
+ pushToCache(cacheKey, collection);
25067
+ responder(collection);
25068
+ };
25069
+ const onFetch = () => {
25070
+ var _a, _b, _c, _d, _e;
25071
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25072
+ const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
25073
+ if (messages.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
25074
+ return;
25075
+ const query = createQuery(queryMessages, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
25076
+ runQuery(query, ({ data: result, error, loading, prevPage: page }) => {
25077
+ const data = {
25078
+ loading,
25079
+ error,
25080
+ params: { page },
25081
+ data: messages,
25082
+ };
25083
+ if (result) {
25084
+ data.data = [...new Set([...messages, ...result.map(getResolver('message'))])];
25085
+ }
25086
+ pushToCache(cacheKey, data);
25087
+ responder(data);
25088
+ }, queryOptions(policy));
25089
+ };
25090
+ disposers.push(onMessageCreated(message => realtimeRouter(message, 'onCreate')), onMessageDeleted(message => realtimeRouter(message, 'onDelete')), onMessageUpdated(message => realtimeRouter(message, 'onUpdate')));
25091
+ onFetch();
25092
+ return () => {
25093
+ log(`liveMessages(tmpid: ${timestamp}) > dispose`);
25094
+ disposers.forEach(fn => fn());
25095
+ };
25096
+ };
25097
+
24851
25098
  const createCommunityEventSubscriber = (event, callback) => {
24852
25099
  const client = getActiveClient();
24853
25100
  const filter = (payload) => {
@@ -25335,9 +25582,9 @@ const queryFollows = async (key, query) => {
25335
25582
  if (client.cache) {
25336
25583
  ingestInCache(payload, { cachedAt });
25337
25584
  const cacheKey = [
25338
- key,
25585
+ 'follow',
25339
25586
  'query',
25340
- Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) }),
25587
+ Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
25341
25588
  ];
25342
25589
  pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
25343
25590
  }
@@ -25352,7 +25599,11 @@ queryFollows.locally = (key, query) => {
25352
25599
  if (!client.cache)
25353
25600
  return;
25354
25601
  const { page } = query, params = __rest(query, ["page"]);
25355
- const queryKey = [key, 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
25602
+ const queryKey = [
25603
+ 'follow',
25604
+ 'query',
25605
+ Object.assign(Object.assign({}, params), { options: Object.assign({}, page), type: key }),
25606
+ ];
25356
25607
  const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
25357
25608
  if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
25358
25609
  return;
@@ -25898,6 +26149,186 @@ const observeFollowings = (userId, callback) => {
25898
26149
  };
25899
26150
  };
25900
26151
 
26152
+ /**
26153
+ * ```js
26154
+ * import { liveFollowers } from '@amityco/ts-sdk'
26155
+ *
26156
+ * let followers = []
26157
+ * const unsub = liveFollowers({
26158
+ * userId: Amity.User['userId'];
26159
+ * }, response => merge(followers, response.data))
26160
+ * ```
26161
+ *
26162
+ * Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
26163
+ *
26164
+ * @param userId the user
26165
+ * @param callback the function to call when new data are available
26166
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
26167
+ *
26168
+ * @category Followers Live Collection
26169
+ */
26170
+ const liveFollowers = (params, callback, config) => {
26171
+ const { log, cache } = getActiveClient();
26172
+ if (!cache) {
26173
+ console.log('For using Live Collection feature you need to enable Cache!');
26174
+ }
26175
+ const timestamp = Date.now();
26176
+ log(`liveFollowers(tmpid: ${timestamp}) > listen`);
26177
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
26178
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
26179
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
26180
+ const disposers = [];
26181
+ const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
26182
+ const responder = (data) => {
26183
+ var _a, _b;
26184
+ let followers = (_a = data.data
26185
+ .map(key => pullFromCache(['follow', 'get', key]))
26186
+ .filter(Boolean)
26187
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
26188
+ if (params.status) {
26189
+ followers = filterByPropEquality(followers, 'status', params.status);
26190
+ }
26191
+ callback({
26192
+ onNextPage: onFetch,
26193
+ data: followers,
26194
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
26195
+ loading: data.loading,
26196
+ error: data.error,
26197
+ });
26198
+ };
26199
+ const realtimeRouter = (followStatus, action) => {
26200
+ var _a;
26201
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26202
+ if (params.userId !== followStatus.to || !collection)
26203
+ return;
26204
+ if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
26205
+ collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
26206
+ }
26207
+ else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
26208
+ collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
26209
+ }
26210
+ pushToCache(cacheKey, collection);
26211
+ responder(collection);
26212
+ };
26213
+ const onFetch = () => {
26214
+ var _a, _b, _c, _d, _e;
26215
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26216
+ const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26217
+ if (followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
26218
+ return;
26219
+ const query = createQuery(queryFollowers, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
26220
+ runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
26221
+ const data = {
26222
+ loading,
26223
+ error,
26224
+ params: { page },
26225
+ data: followers,
26226
+ };
26227
+ if (result) {
26228
+ data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
26229
+ }
26230
+ pushToCache(cacheKey, data);
26231
+ responder(data);
26232
+ }, queryOptions(policy));
26233
+ };
26234
+ disposers.push(onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')), onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')), onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')), onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')), onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')), onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')), onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')));
26235
+ onFetch();
26236
+ return () => {
26237
+ log(`liveFollowers(tmpid: ${timestamp}) > dispose`);
26238
+ disposers.forEach(fn => fn());
26239
+ };
26240
+ };
26241
+
26242
+ /**
26243
+ * ```js
26244
+ * import { liveFollowings } from '@amityco/ts-sdk'
26245
+ *
26246
+ * let followings = []
26247
+ * const unsub = liveFollowings({
26248
+ * userId: Amity.User['userId'];
26249
+ * }, response => merge(followings, response.data))
26250
+ * ```
26251
+ *
26252
+ * Observe all mutations on a list of {@link Amity.FollowStatus} followings for a given userId
26253
+ *
26254
+ * @param userId the user
26255
+ * @param callback the function to call when new data are available
26256
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
26257
+ *
26258
+ * @category Followings Live Collection
26259
+ */
26260
+ const liveFollowings = (params, callback, config) => {
26261
+ const { log, cache } = getActiveClient();
26262
+ if (!cache) {
26263
+ console.log('For using Live Collection feature you need to enable Cache!');
26264
+ }
26265
+ const timestamp = Date.now();
26266
+ log(`liveFollowings(tmpid: ${timestamp}) > listen`);
26267
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
26268
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
26269
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
26270
+ const disposers = [];
26271
+ const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
26272
+ const responder = (data) => {
26273
+ var _a, _b;
26274
+ let followings = (_a = data.data
26275
+ .map(key => pullFromCache(['follow', 'get', key]))
26276
+ .filter(Boolean)
26277
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
26278
+ if (params.status) {
26279
+ followings = filterByPropEquality(followings, 'status', params.status);
26280
+ }
26281
+ callback({
26282
+ onNextPage: onFetch,
26283
+ data: followings,
26284
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
26285
+ loading: data.loading,
26286
+ error: data.error,
26287
+ });
26288
+ };
26289
+ const realtimeRouter = (followStatus, action) => {
26290
+ var _a;
26291
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26292
+ if (params.userId !== followStatus.from || !collection)
26293
+ return;
26294
+ if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
26295
+ collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
26296
+ }
26297
+ else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
26298
+ collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
26299
+ }
26300
+ pushToCache(cacheKey, collection);
26301
+ responder(collection);
26302
+ };
26303
+ const onFetch = () => {
26304
+ var _a, _b, _c, _d, _e;
26305
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26306
+ const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26307
+ if (followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
26308
+ return;
26309
+ const query = createQuery(queryFollowings, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
26310
+ runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
26311
+ const data = {
26312
+ loading,
26313
+ error,
26314
+ params: { page },
26315
+ data: followings,
26316
+ };
26317
+ if (result) {
26318
+ data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
26319
+ }
26320
+ pushToCache(cacheKey, data);
26321
+ responder(data);
26322
+ }, queryOptions(policy));
26323
+ };
26324
+ disposers.push(onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')), onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')), onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')), onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')), onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')), onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')), onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')));
26325
+ onFetch();
26326
+ return () => {
26327
+ log(`liveFollowings(tmpid: ${timestamp}) > dispose`);
26328
+ disposers.forEach(fn => fn());
26329
+ };
26330
+ };
26331
+
25901
26332
  /**
25902
26333
  * ```js
25903
26334
  * import { observePosts } from '@amityco/ts-sdk'
@@ -26006,7 +26437,7 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
26006
26437
  const livePosts = (params, callback, config) => {
26007
26438
  const { log, cache } = getActiveClient();
26008
26439
  if (!cache) {
26009
- console.log('For using Live Collection feature you need to enable Cache!');
26440
+ console.log(ENABLE_CACHE_MESSAGE);
26010
26441
  }
26011
26442
  const timestamp = Date.now();
26012
26443
  log(`livePosts(tmpid: ${timestamp}) > listen`);
@@ -26845,7 +27276,12 @@ const createUserToken = async (apiKey, apiRegion, params) => {
26845
27276
  };
26846
27277
 
26847
27278
  exports.API_REGIONS = API_REGIONS;
27279
+ exports.ContentFeedType = ContentFeedType;
27280
+ exports.FileType = FileType;
26848
27281
  exports.VERSION = VERSION$1;
27282
+ exports.VideoResolution = VideoResolution;
27283
+ exports.VideoSize = VideoSize;
27284
+ exports.VideoTranscodingStatus = VideoTranscodingStatus;
26849
27285
  exports.acceptFollower = acceptFollower;
26850
27286
  exports.addChannelMembers = addChannelMembers;
26851
27287
  exports.addChannelMembersRole = addChannelMembersRole;
@@ -26900,6 +27336,7 @@ exports.getComments = getComments;
26900
27336
  exports.getCommunities = getCommunities;
26901
27337
  exports.getCommunity = getCommunity;
26902
27338
  exports.getCommunityTopic = getCommunityTopic;
27339
+ exports.getFeedSettings = getFeedSettings;
26903
27340
  exports.getFile = getFile;
26904
27341
  exports.getFollowInfo = getFollowInfo;
26905
27342
  exports.getMessage = getMessage;
@@ -26935,10 +27372,14 @@ exports.joinCommunity = joinCommunity;
26935
27372
  exports.leaveChannel = leaveChannel;
26936
27373
  exports.leaveCommunity = leaveCommunity;
26937
27374
  exports.liveComments = liveComments;
27375
+ exports.liveFollowers = liveFollowers;
27376
+ exports.liveFollowings = liveFollowings;
27377
+ exports.liveMessages = liveMessages;
26938
27378
  exports.livePosts = livePosts;
26939
27379
  exports.liveReactions = liveReactions;
26940
27380
  exports.mergeInCache = mergeInCache;
26941
27381
  exports.observeChannel = observeChannel;
27382
+ exports.observeChannels = observeChannels;
26942
27383
  exports.observeComment = observeComment;
26943
27384
  exports.observeComments = observeComments;
26944
27385
  exports.observeCommunity = observeCommunity;
@@ -26952,6 +27393,7 @@ exports.observePoll = observePoll;
26952
27393
  exports.observePost = observePost;
26953
27394
  exports.observePosts = observePosts;
26954
27395
  exports.observeUser = observeUser;
27396
+ exports.onChannelCreated = onChannelCreated;
26955
27397
  exports.onChannelDeleted = onChannelDeleted;
26956
27398
  exports.onChannelJoined = onChannelJoined;
26957
27399
  exports.onChannelLeft = onChannelLeft;