@amityco/ts-sdk 7.7.1-00acca4a.0 → 7.7.1-0c84fd02.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/core/payload.d.ts +8 -3
  2. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/core/payload.d.ts.map +1 -1
  3. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/core/payload.js.map +1 -1
  4. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +4 -0
  5. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
  6. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
  7. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +0 -31
  8. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
  9. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js +1 -21
  10. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
  11. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/channelRepository/events/onChannelSetMuted.d.ts.map +1 -1
  12. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/channelRepository/events/onChannelSetMuted.js +6 -8
  13. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/channelRepository/events/onChannelSetMuted.js.map +1 -1
  14. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  15. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  16. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js +21 -0
  17. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js.map +1 -0
  18. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +1 -0
  19. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
  20. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js +1 -0
  21. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
  22. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +0 -1
  23. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
  24. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js +0 -1
  25. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
  26. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/streamRepository/events/onStreamViewerBanned.d.ts.map +1 -1
  27. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/streamRepository/events/onStreamViewerBanned.js +5 -8
  28. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/streamRepository/events/onStreamViewerBanned.js.map +1 -1
  29. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/streamRepository/events/onStreamViewerUnbanned.d.ts.map +1 -1
  30. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/streamRepository/events/onStreamViewerUnbanned.js +3 -6
  31. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/streamRepository/events/onStreamViewerUnbanned.js.map +1 -1
  32. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
  33. package/dist/@types/core/payload.d.ts +8 -3
  34. package/dist/@types/core/payload.d.ts.map +1 -1
  35. package/dist/@types/domains/client.d.ts +4 -0
  36. package/dist/@types/domains/client.d.ts.map +1 -1
  37. package/dist/@types/domains/feed.d.ts +0 -31
  38. package/dist/@types/domains/feed.d.ts.map +1 -1
  39. package/dist/channelRepository/events/onChannelSetMuted.d.ts.map +1 -1
  40. package/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  41. package/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  42. package/dist/client/api/index.d.ts +1 -0
  43. package/dist/client/api/index.d.ts.map +1 -1
  44. package/dist/feedRepository/index.d.ts +0 -1
  45. package/dist/feedRepository/index.d.ts.map +1 -1
  46. package/dist/index.cjs.js +1114 -1338
  47. package/dist/index.esm.js +1113 -1337
  48. package/dist/index.umd.js +1 -1
  49. package/dist/streamRepository/events/onStreamViewerBanned.d.ts.map +1 -1
  50. package/dist/streamRepository/events/onStreamViewerUnbanned.d.ts.map +1 -1
  51. package/package.json +1 -1
  52. package/src/@types/core/payload.ts +4 -3
  53. package/src/@types/domains/client.ts +5 -0
  54. package/src/@types/domains/feed.ts +0 -43
  55. package/src/channelRepository/events/onChannelSetMuted.ts +6 -8
  56. package/src/client/api/getShareableLinkConfiguration.ts +26 -0
  57. package/src/client/api/index.ts +2 -0
  58. package/src/feedRepository/index.ts +0 -1
  59. package/src/streamRepository/events/onStreamViewerBanned.ts +5 -8
  60. package/src/streamRepository/events/onStreamViewerUnbanned.ts +4 -6
  61. package/tsconfig.tsbuildinfo +1 -1
  62. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +0 -14
  63. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +0 -1
  64. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js +0 -129
  65. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js.map +0 -1
  66. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +0 -5
  67. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +0 -1
  68. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js +0 -15
  69. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js.map +0 -1
  70. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +0 -15
  71. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +0 -1
  72. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js +0 -78
  73. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js.map +0 -1
  74. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts +0 -23
  75. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts.map +0 -1
  76. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js +0 -46
  77. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js.map +0 -1
  78. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +0 -2
  79. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +0 -1
  80. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +0 -2
  81. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +0 -1
  82. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +0 -14
  83. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +0 -1
  84. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +0 -5
  85. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +0 -1
  86. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +0 -15
  87. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +0 -1
  88. package/dist/feedRepository/observers/getUserFeed.d.ts +0 -23
  89. package/dist/feedRepository/observers/getUserFeed.d.ts.map +0 -1
  90. package/dist/feedRepository/observers/index.d.ts +0 -2
  91. package/dist/feedRepository/observers/index.d.ts.map +0 -1
  92. package/src/feedRepository/observers/getUserFeed/LiveCollectionController.ts +0 -193
  93. package/src/feedRepository/observers/getUserFeed/PaginationController.ts +0 -37
  94. package/src/feedRepository/observers/getUserFeed/QueryStreamController.ts +0 -119
  95. package/src/feedRepository/observers/getUserFeed.ts +0 -56
  96. package/src/feedRepository/observers/index.ts +0 -1
package/dist/index.cjs.js CHANGED
@@ -6362,19 +6362,17 @@ const dispose$7 = (cb) => {
6362
6362
  const onChannelSetMuted = (callback) => {
6363
6363
  if (callbacks$7.length === 0) {
6364
6364
  const client = getActiveClient();
6365
- const filter = async (payloads) => {
6365
+ const filter = async (payload) => {
6366
6366
  var _a;
6367
- payloads.forEach(payload => {
6368
- upsertInCache(['channel', 'get', payload.channelId], {
6369
- // If muteTimeout > now => user is muted
6370
- // Otherwise => user is unmuted
6371
- isMuted: Date.parse(payload.muteTimeout) > Date.now(),
6372
- });
6367
+ upsertInCache(['channel', 'get', payload.channelId], {
6368
+ // If muteTimeout > now => user is muted
6369
+ // Otherwise => user is unmuted
6370
+ isMuted: Date.parse(payload.muteTimeout) > Date.now(),
6373
6371
  });
6374
6372
  const channel = (_a = pullFromCache([
6375
6373
  'channel',
6376
6374
  'get',
6377
- payloads[0].channelId,
6375
+ payload.channelId,
6378
6376
  ])) === null || _a === void 0 ? void 0 : _a.data;
6379
6377
  if (channel) {
6380
6378
  callbacks$7.forEach(cb => cb(channel));
@@ -9783,6 +9781,26 @@ const fetchLinkPreview = async (url) => {
9783
9781
  return data;
9784
9782
  };
9785
9783
 
9784
+ /**
9785
+ * ```js
9786
+ * import Client from '@amityco/ts-sdk'
9787
+ * const shareableLinkConfiguration = await Client.getShareableLinkConfiguration()
9788
+ * const postLinkPattern = shareableLinkConfiguration.post
9789
+ * ```
9790
+ *
9791
+ * Fetches a {@link Amity.ShareableLinkConfiguration} object
9792
+ *
9793
+ * @returns A Promise of {@link Amity.ShareableLinkConfiguration} object
9794
+ *
9795
+ * @category Client API
9796
+ * @async
9797
+ */
9798
+ const getShareableLinkConfiguration = async () => {
9799
+ const client = getActiveClient();
9800
+ const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
9801
+ return data;
9802
+ };
9803
+
9786
9804
  /**
9787
9805
  * ```js
9788
9806
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk'
@@ -10152,6 +10170,7 @@ var index$o = /*#__PURE__*/Object.freeze({
10152
10170
  enableUnreadCount: enableUnreadCount,
10153
10171
  setUploadedFileAccessType: setUploadedFileAccessType,
10154
10172
  fetchLinkPreview: fetchLinkPreview,
10173
+ getShareableLinkConfiguration: getShareableLinkConfiguration,
10155
10174
  onConnectionError: onConnectionError,
10156
10175
  onClientDisconnected: onClientDisconnected,
10157
10176
  onClientBanned: onClientBanned,
@@ -17737,23 +17756,20 @@ const onStreamViewerBanned = (callback) => {
17737
17756
  const client = getActiveClient();
17738
17757
  const filter = (payloads) => {
17739
17758
  var _a;
17740
- payloads.forEach(streamBanned => {
17759
+ const { list } = payloads;
17760
+ list.forEach(payload => {
17741
17761
  var _a;
17742
- mergeInCache(['stream', 'get', streamBanned.streamId], { watcherUrl: null });
17762
+ mergeInCache(['stream', 'get', payload.streamId], { watcherUrl: null });
17743
17763
  // Update isDeleted = true in banned user's messages
17744
17764
  const messageCache = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(
17745
17765
  // Check if creator id and user id are internal or external id
17746
- ({ data }) => data.creatorId === streamBanned.userId);
17766
+ ({ data }) => data.creatorId === payload.userId);
17747
17767
  // Update isDeleted for each relavant messages
17748
17768
  messageCache === null || messageCache === void 0 ? void 0 : messageCache.forEach(message => {
17749
17769
  mergeInCache(message.key, { isDeleted: true });
17750
17770
  });
17751
17771
  });
17752
- const stream = (_a = pullFromCache([
17753
- 'stream',
17754
- 'get',
17755
- payloads[0].streamId,
17756
- ])) === null || _a === void 0 ? void 0 : _a.data;
17772
+ const stream = (_a = pullFromCache(['stream', 'get', list[0].streamId])) === null || _a === void 0 ? void 0 : _a.data;
17757
17773
  if (!stream)
17758
17774
  return;
17759
17775
  callback(stream);
@@ -23181,1035 +23197,1010 @@ getCustomRankingGlobalFeed.locally = (query) => {
23181
23197
  : undefined;
23182
23198
  };
23183
23199
 
23184
- class UserFeedPaginationController extends PaginationController {
23185
- async getRequest(queryParams, token) {
23186
- const { userId, feedSources, dataTypes, includeDeleted, matchingOnlyParentPost, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["userId", "feedSources", "dataTypes", "includeDeleted", "matchingOnlyParentPost", "limit"]);
23187
- const options = token ? { token } : { limit };
23188
- const { data: queryResponse } = await this.http.get(`/api/v4/user-feeds/${userId}`, {
23189
- params: Object.assign(Object.assign({}, params), { options, dataTypes: (dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length) ? dataTypes : undefined, includePostedFeed: feedSources, isDeleted: inferIsDeleted(includeDeleted), matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length) }),
23190
- });
23191
- return queryResponse;
23192
- }
23193
- }
23194
-
23195
- var EnumPostActions;
23196
- (function (EnumPostActions) {
23197
- EnumPostActions["OnPostCreated"] = "onPostCreated";
23198
- EnumPostActions["OnPostUpdated"] = "onPostUpdated";
23199
- EnumPostActions["OnPostDeleted"] = "onPostDeleted";
23200
- EnumPostActions["OnPostFlagged"] = "onPostFlagged";
23201
- EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
23202
- EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
23203
- EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
23204
- EnumPostActions["OnPostApproved"] = "onPostApproved";
23205
- EnumPostActions["OnPostDeclined"] = "onPostDeclined";
23206
- })(EnumPostActions || (EnumPostActions = {}));
23207
-
23208
- class UserFeedQueryStreamController extends QueryStreamController {
23209
- constructor(query, cacheKey, notifyChange, preparePayload) {
23210
- super(query, cacheKey);
23211
- this.notifyChange = notifyChange;
23212
- this.preparePayload = preparePayload;
23213
- }
23214
- async saveToMainDB(response) {
23215
- const processedPayload = await this.preparePayload(response);
23216
- const client = getActiveClient();
23217
- const cachedAt = client.cache && Date.now();
23218
- if (client.cache) {
23219
- ingestInCache(processedPayload, { cachedAt });
23220
- }
23221
- }
23222
- appendToQueryStream(response, direction, refresh = false) {
23223
- var _a, _b;
23224
- if (refresh) {
23225
- pushToCache(this.cacheKey, {
23226
- data: response.posts.map(getResolver('post')),
23227
- });
23228
- }
23229
- else {
23230
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23231
- const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23232
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
23233
- }
23234
- }
23235
- reactor(action) {
23236
- return (post) => {
23237
- var _a, _b;
23238
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23239
- if (!collection)
23240
- return;
23241
- // if the collection is parent post collection and
23242
- // post is not included in the collection or post is child post
23243
- if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
23244
- !collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
23245
- return;
23246
- if (action === EnumPostActions.OnPostDeleted) {
23247
- collection.data = collection.data.filter(postId => postId !== post.postId);
23248
- }
23249
- if (post.parentPostId && post.isDeleted) {
23250
- const parentPost = (_b = pullFromCache([
23251
- 'post',
23252
- 'get',
23253
- post.parentPostId,
23254
- ])) === null || _b === void 0 ? void 0 : _b.data;
23255
- if (!parentPost)
23256
- return;
23257
- parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
23258
- pushToCache(['post', 'get', parentPost.postId], parentPost);
23259
- }
23260
- if (action === EnumPostActions.OnPostDeclined) {
23261
- collection.data = collection.data.filter(postId => postId !== post.postId);
23262
- }
23263
- if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
23264
- if (this.query.dataTypes &&
23265
- this.query.dataTypes.length > 0 &&
23266
- !this.query.dataTypes.includes(post.dataType)) {
23267
- return;
23268
- }
23269
- collection.data = [...new Set([post.postId, ...collection.data])];
23270
- }
23271
- pushToCache(this.cacheKey, collection);
23272
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
23273
- };
23274
- }
23275
- subscribeRTE(createSubscriber) {
23276
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
23277
- }
23278
- }
23200
+ var index$a = /*#__PURE__*/Object.freeze({
23201
+ __proto__: null,
23202
+ queryGlobalFeed: queryGlobalFeed,
23203
+ getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
23204
+ });
23279
23205
 
23280
23206
  /* begin_public_function
23281
- id: comment.get_by_ids
23207
+ id: post.get_by_ids
23282
23208
  */
23283
23209
  /**
23284
23210
  * ```js
23285
- * import { CommentRepository } from '@amityco/ts-sdk'
23286
- * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
23211
+ * import { getPostByIds } from '@amityco/ts-sdk'
23212
+ * const { data: posts } = await getPostByIds(['foo', 'bar'])
23287
23213
  * ```
23288
23214
  *
23289
- * Fetches a collection of {@link Amity.Comment} objects
23215
+ * Fetches a collection of {@link Amity.Post} objects
23290
23216
  *
23291
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23292
- * @returns the associated collection of {@link Amity.Comment} objects
23217
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
23218
+ * @returns the associated collection of {@link Amity.Post} objects
23293
23219
  *
23294
- * @category Comment API
23220
+ * @category Post API
23295
23221
  * @async
23296
23222
  */
23297
- const getCommentByIds = async (commentIds) => {
23223
+ const getPostByIds = async (postIds) => {
23298
23224
  const client = getActiveClient();
23299
- client.log('comment/getCommentByIds', commentIds);
23300
- const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
23301
- let data;
23225
+ client.log('post/getPostByIds', postIds);
23226
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
23227
+ let payload;
23302
23228
  try {
23303
23229
  // API-FIX: endpoint should not be /list, parameters should be querystring.
23304
- const response = await client.http.get(`/api/v3/comments/list`, {
23305
- params: { commentIds: encodedCommentIds },
23230
+ const response = await client.http.get(`/api/v3/posts/list`, {
23231
+ params: { postIds: encodedPostIds },
23306
23232
  });
23307
- data = response.data;
23233
+ payload = response.data;
23308
23234
  }
23309
23235
  catch (error) {
23310
- commentIds.forEach(commentId => {
23236
+ postIds.forEach(postId => {
23311
23237
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23312
- pushToTombstone('comment', commentId);
23238
+ pushToTombstone('post', postId);
23313
23239
  }
23314
23240
  });
23315
23241
  throw error;
23316
23242
  }
23243
+ const data = prepareMembershipPayload(payload, 'communityUsers');
23317
23244
  const cachedAt = client.cache && Date.now();
23318
23245
  if (client.cache)
23319
23246
  ingestInCache(data, { cachedAt });
23320
23247
  return {
23321
- data: data.comments.map(comment => LinkedObject.comment(comment)),
23248
+ data: data.posts.map(LinkedObject.post),
23322
23249
  cachedAt,
23323
23250
  };
23324
23251
  };
23325
23252
  /* end_public_function */
23326
23253
  /**
23327
23254
  * ```js
23328
- * import { getCommentByIds } from '@amityco/ts-sdk'
23329
- * const comments = getCommentByIds.locally(['foo', 'bar'])
23255
+ * import { getPostByIds } from '@amityco/ts-sdk'
23256
+ * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
23330
23257
  * ```
23331
23258
  *
23332
- * Fetches a collection of {@link Amity.Comment} objects from cache
23259
+ * Fetches a collection of {@link Amity.Post} objects from cache
23333
23260
  *
23334
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23335
- * @returns the associated collection of {@link Amity.Comment} objects
23261
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
23262
+ * @returns the associated collection of {@link Amity.Post} objects
23336
23263
  *
23337
- * @category Comment API
23264
+ * @category Post API
23338
23265
  */
23339
- getCommentByIds.locally = (commentIds) => {
23266
+ getPostByIds.locally = (postIds) => {
23340
23267
  var _a;
23341
23268
  const client = getActiveClient();
23342
- client.log('comment/getCommentByIds.locally', commentIds);
23269
+ client.log('post/getPostByIds.locally', postIds);
23343
23270
  if (!client.cache)
23344
23271
  return;
23345
- const cached = commentIds
23346
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
23272
+ const cached = postIds
23273
+ .map(postId => pullFromCache(['post', 'get', postId]))
23347
23274
  .filter(Boolean);
23348
- const comments = cached.map(({ data }) => data);
23275
+ const posts = cached.map(({ data }) => data);
23349
23276
  const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
23350
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
23277
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
23351
23278
  return;
23352
23279
  return {
23353
- data: comments.map(comment => LinkedObject.comment(comment)),
23280
+ data: posts.map(LinkedObject.post),
23354
23281
  cachedAt: oldest.cachedAt,
23355
23282
  };
23356
23283
  };
23357
23284
 
23358
23285
  /* begin_public_function
23359
- id: comment.create
23286
+ id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
23360
23287
  */
23361
23288
  /**
23362
23289
  * ```js
23363
- * import { CommentRepository } from '@amityco/ts-sdk'
23364
- * const newComment = await CommentRepository.createComment(bundle)
23290
+ * import { PostRepository } from '@amityco/ts-sdk'
23291
+ * const created = await PostRepository.createPost({
23292
+ * targetType: 'user',
23293
+ * targetId: 'foobar',
23294
+ * data: { text: 'hello world' }
23295
+ * }))
23365
23296
  * ```
23366
23297
  *
23367
- * Creates an {@link Amity.Comment}
23298
+ * Creates an {@link Amity.Post}
23368
23299
  *
23369
- * @param bundle The data necessary to create a new {@link Amity.Comment}
23370
- * @returns The newly created {@link Amity.Comment}
23300
+ * @param bundle The data necessary to create a new {@link Amity.Post}
23301
+ * @returns The newly created {@link Amity.Post}
23371
23302
  *
23372
- * @category Comment API
23303
+ * @category Post API
23373
23304
  * @async
23374
23305
  */
23375
- const createComment = async (bundle) => {
23376
- var _a;
23306
+ const createPost = async (bundle) => {
23377
23307
  const client = getActiveClient();
23378
- client.log('comment/createComment', bundle);
23379
- const { data } = await client.http.post('/api/v3/comments', bundle);
23380
- const { comments } = data;
23381
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
23382
- if (comments.length === 0)
23383
- throw new Error('Comment not created');
23308
+ client.log('post/createPost', bundle);
23309
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
23310
+ // eslint-disable-next-line no-param-reassign
23311
+ delete bundle.dataType;
23312
+ }
23313
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
23314
+ fireEvent('post.created', payload);
23315
+ const data = preparePostPayload(payload);
23384
23316
  const cachedAt = client.cache && Date.now();
23385
23317
  if (client.cache)
23386
23318
  ingestInCache(data, { cachedAt });
23387
- if (['post', 'content'].includes(bundle.referenceType)) {
23388
- const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23389
- if (post) {
23390
- post.commentsCount += 1;
23391
- fireEvent('local.post.updated', {
23392
- posts: [post],
23393
- categories: [],
23394
- comments: [],
23395
- communities: [],
23396
- communityUsers: data.communityUsers,
23397
- feeds: [],
23398
- files: data.files,
23399
- postChildren: [],
23400
- users: data.users,
23401
- videoStreamings: [],
23402
- });
23403
- }
23404
- }
23405
- else if (bundle.referenceType === 'story') {
23406
- const storyIndex = pullFromCache([
23407
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23408
- bundle.referenceId,
23409
- ]);
23410
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
23411
- const cacheStory = pullFromCache([
23412
- "story" /* STORY_KEY_CACHE.STORY */,
23413
- 'get',
23414
- storyIndex.data,
23415
- ]);
23416
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
23417
- fireEvent('story.updated', {
23418
- stories: [
23419
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
23420
- ],
23421
- categories: [],
23422
- comments,
23423
- communities: [],
23424
- communityUsers: data.communityUsers,
23425
- files: data.files,
23426
- users: data.users,
23427
- });
23428
- }
23429
- }
23430
- }
23431
- fireEvent('local.comment.created', data);
23319
+ const { posts } = data;
23432
23320
  return {
23433
- data: LinkedObject.comment(comments[0]),
23321
+ data: LinkedObject.post(posts[0]),
23434
23322
  cachedAt,
23435
23323
  };
23436
23324
  };
23437
23325
  /* end_public_function */
23438
23326
 
23439
23327
  /* begin_public_function
23440
- id: comment.update_comment
23328
+ id: post.edit, post.edit.custom_post
23441
23329
  */
23442
23330
  /**
23443
23331
  * ```js
23444
- * import { CommentRepository } from '@amityco/ts-sdk'
23445
- * const updated = await CommentRepository.updateComment(commentId, {
23332
+ * import { PostRepository } from '@amityco/ts-sdk'
23333
+ * const updated = await PostRepository.editPost(postId, {
23446
23334
  * data: { text: 'hello world' }
23447
23335
  * })
23448
23336
  * ```
23449
23337
  *
23450
- * Updates an {@link Amity.Comment}
23338
+ * Updates an {@link Amity.Post}
23451
23339
  *
23452
- * @param commentId The ID of the {@link Amity.Comment} to edit
23340
+ * @param postId The ID of the {@link Amity.Post} to edit
23453
23341
  * @param patch The patch data to apply
23454
- * @returns the updated {@link Amity.Comment} object
23342
+ * @returns the updated {@link Amity.Post} object
23455
23343
  *
23456
- * @category Comment API
23344
+ * @category Post API
23457
23345
  * @async
23458
23346
  */
23459
- const updateComment = async (commentId, patch) => {
23347
+ const editPost = async (postId, patch) => {
23460
23348
  const client = getActiveClient();
23461
- client.log('user/updateComment', patch);
23462
- const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
23349
+ client.log('user/editPost', patch);
23350
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
23351
+ const data = prepareMembershipPayload(payload, 'communityUsers');
23463
23352
  const cachedAt = client.cache && Date.now();
23464
23353
  if (client.cache)
23465
23354
  ingestInCache(data, { cachedAt });
23466
- fireEvent('comment.updated', data);
23467
- const { comments } = data;
23355
+ fireEvent('local.post.updated', data);
23356
+ const { posts } = data;
23468
23357
  return {
23469
- data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
23358
+ data: LinkedObject.post(posts.find(post => post.postId === postId)),
23470
23359
  cachedAt,
23471
23360
  };
23472
23361
  };
23473
23362
  /* end_public_function */
23474
23363
 
23475
- // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
23476
- const applyMissingField = (rawData, isCreated = false) => {
23477
- const { storyId, referenceId } = rawData;
23478
- if (!isCreated) {
23479
- if (referenceId)
23480
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
23481
- }
23482
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
23483
- };
23484
- const convertRawStoryToInternal = (data, isCreated = false) => {
23485
- const { stories } = data;
23486
- const storiesData = stories.map(story => applyMissingField(story, isCreated));
23487
- return Object.assign(Object.assign({}, data), { stories: storiesData });
23488
- };
23489
-
23490
- const getStoryByStoryId$1 = async (storyId) => {
23491
- const client = getActiveClient();
23492
- client.log('story/getStoryByStoryId', storyId);
23493
- // Get story referenceId from cache
23494
- const cacheReferenceId = pullFromCache([
23495
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23496
- storyId,
23497
- ]);
23498
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23499
- const { data: referenceId } = cacheReferenceId;
23500
- isInTombstone('story', referenceId);
23501
- }
23502
- let data;
23503
- try {
23504
- const response = await client.http.get(`/api/v4/stories/${storyId}`);
23505
- data = convertRawStoryToInternal(response.data);
23506
- }
23507
- catch (error) {
23508
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23509
- pushToTombstone('story', storyId);
23510
- }
23511
- throw error;
23512
- }
23513
- const cachedAt = client.cache && Date.now();
23514
- if (client.cache) {
23515
- ingestInCache(data, { cachedAt });
23516
- }
23517
- return {
23518
- data: data.stories[0],
23519
- cachedAt,
23520
- };
23521
- };
23522
- getStoryByStoryId$1.locally = (storyId) => {
23523
- const client = getActiveClient();
23524
- client.log('story/getStorybyStoryId', storyId);
23525
- // Get story referenceId from cache
23526
- const cacheReferenceId = pullFromCache([
23527
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23528
- storyId,
23529
- ]);
23530
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23531
- const { data: referenceId } = cacheReferenceId;
23532
- isInTombstone('story', referenceId);
23533
- }
23534
- const cachedAt = client.cache && Date.now();
23535
- const storyCache = pullFromCache(['story', 'get', storyId]);
23536
- if (!storyCache)
23537
- return;
23538
- return {
23539
- data: storyCache.data,
23540
- cachedAt,
23541
- };
23542
- };
23543
-
23544
- /* begin_public_function
23545
- id: comment.soft_delete, comment.hard_delete
23546
- */
23547
23364
  /**
23548
23365
  * ```js
23549
- * import { CommentRepository } from '@amityco/ts-sdk'
23550
- * const success = await CommentRepository.deleteComment('foobar')
23366
+ * import { deletePost } from '@amityco/ts-sdk'
23367
+ * const success = await deletePost('foobar')
23551
23368
  * ```
23552
23369
  *
23553
- * Deletes a {@link Amity.Comment}
23370
+ * Deletes a {@link Amity.Post}
23554
23371
  *
23555
- * @param commentId The {@link Amity.Comment} ID to delete
23556
- * @return A success boolean if the {@link Amity.Comment} was deleted
23372
+ * @param postId The {@link Amity.Post} ID to delete
23373
+ * @return A success boolean if the {@link Amity.Post} was deleted
23557
23374
  *
23558
- * @category Comment API
23375
+ * @private
23559
23376
  * @async
23560
23377
  */
23561
- const deleteComment = async (commentId, permanent = false) => {
23378
+ const deletePost = async (postId, permanent = false) => {
23562
23379
  var _a;
23563
23380
  const client = getActiveClient();
23564
- const comment = await getComment$2(commentId);
23565
- // API-FIX: This endpoint has not been implemented yet.
23566
- await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
23381
+ const post = await getPost$2(postId);
23382
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
23567
23383
  params: {
23568
- commentId,
23384
+ postId,
23569
23385
  permanent,
23570
23386
  },
23571
23387
  });
23572
- // to support hard deletion
23573
- const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
23574
- if (comment.data.referenceType === 'story') {
23575
- const story = await getStoryByStoryId$1(comment.data.referenceId);
23576
- fireEvent('local.story.updated', {
23577
- stories: [story.data],
23388
+ // there is currently a limitation which doesn't allow us to fire event to tell that community
23389
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
23390
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
23391
+ // later when realtime events covers that for us.
23392
+ if (post.data.targetType === 'community') {
23393
+ const community = await getCommunity$1(post.data.targetId);
23394
+ const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
23395
+ const communityUsers = communityUsersCache
23396
+ .filter(({ key }) => {
23397
+ // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
23398
+ if (key[0] !== 'communityUsers')
23399
+ return false;
23400
+ if (key[1] !== 'get')
23401
+ return false;
23402
+ if (typeof key[2] === 'string')
23403
+ return key[2].includes(community.data.communityId);
23404
+ return false;
23405
+ })
23406
+ .map(({ data }) => data);
23407
+ fireEvent('community.updated', {
23408
+ communities: [community.data],
23578
23409
  categories: [],
23579
- comments: [],
23580
- communities: [],
23581
- communityUsers: [],
23410
+ communityUsers,
23411
+ feeds: [],
23582
23412
  files: [],
23583
23413
  users: [],
23584
23414
  });
23585
23415
  }
23416
+ // to support hard deletion
23417
+ const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
23418
+ if (permanent) {
23419
+ setTimeout(() => {
23420
+ pushToTombstone('post', postId);
23421
+ }, 0);
23422
+ }
23586
23423
  else {
23587
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23588
- if (post) {
23589
- let removeCount;
23590
- if (!deleted.parentId) {
23591
- // NOTE: delete the parent comment will remove all children comments
23592
- removeCount = deleted.childrenNumber + 1;
23593
- }
23594
- else
23595
- removeCount = 1;
23596
- post.commentsCount -= removeCount;
23597
- fireEvent('local.post.updated', {
23598
- posts: [post],
23599
- categories: [],
23600
- comments: [],
23601
- communities: [],
23602
- communityUsers: [],
23603
- feeds: [],
23604
- files: [],
23605
- postChildren: [],
23606
- users: [],
23607
- videoStreamings: [],
23608
- });
23609
- }
23424
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
23610
23425
  }
23611
- fireEvent('local.comment.deleted', {
23612
- comments: [deleted],
23613
- commentChildren: [],
23426
+ fireEvent('local.post.deleted', {
23427
+ posts: [deleted],
23428
+ categories: [],
23429
+ comments: [],
23430
+ communities: [],
23431
+ communityUsers: [],
23432
+ feeds: [],
23614
23433
  files: [],
23434
+ postChildren: [],
23615
23435
  users: [],
23616
- communityUsers: [],
23436
+ videoStreamings: [],
23617
23437
  });
23618
- if (permanent) {
23619
- scheduleTask(() => pushToTombstone('comment', commentId));
23620
- }
23621
- else {
23622
- upsertInCache(['comment', 'get', commentId], { isDeleted: true });
23623
- }
23624
- return deleted;
23438
+ return LinkedObject.post(deleted);
23625
23439
  };
23626
- /* end_public_function */
23627
23440
 
23628
23441
  /* begin_public_function
23629
- id: comment.soft_delete
23442
+ id: post.soft_delete
23630
23443
  */
23631
23444
  /**
23632
23445
  * ```js
23633
- * import { CommentRepository } from '@amityco/ts-sdk'
23634
- * const success = await CommentRepository.softDeleteComment('foobar')
23446
+ * import { PostRepository } from '@amityco/ts-sdk'
23447
+ * const success = await PostRepository.softDeletePost('foobar')
23635
23448
  * ```
23636
23449
  *
23637
- * Deletes a {@link Amity.Comment}
23450
+ * Soft deletes a {@link Amity.Post}
23638
23451
  *
23639
- * @param commentId The {@link Amity.Comment} ID to delete
23640
- * @return A success boolean if the {@link Amity.Comment} was deleted
23452
+ * @param postId The {@link Amity.Post} ID to soft delete
23453
+ * @return A success boolean if the {@link Amity.Post} was deleted
23641
23454
  *
23642
- * @category Comment API
23455
+ * @category Post API
23643
23456
  * @async
23644
23457
  */
23645
- const softDeleteComment = async (commentId) => {
23458
+ const softDeletePost = async (postId) => {
23646
23459
  const client = getActiveClient();
23647
- client.log('comment/softDeleteComment', commentId);
23648
- const softDeleted = deleteComment(commentId);
23649
- return softDeleted;
23460
+ client.log('post/softDeletePost', postId);
23461
+ const softDeleted = await deletePost(postId, false);
23462
+ return LinkedObject.post(softDeleted);
23650
23463
  };
23651
23464
  /* end_public_function */
23652
23465
 
23653
23466
  /* begin_public_function
23654
- id: comment.hard_delete
23467
+ id: post.hard_delete
23655
23468
  */
23656
23469
  /**
23657
23470
  * ```js
23658
- * import { CommentRepository } from '@amityco/ts-sdk'
23659
- * const success = await CommentRepository.hardDeleteComment('foobar')
23471
+ * import { hardDeletePost } from '@amityco/ts-sdk'
23472
+ * const success = await hardDeletePost('foobar')
23660
23473
  * ```
23661
23474
  *
23662
- * Deletes a {@link Amity.Comment}
23475
+ * Hard deletes a {@link Amity.Post}
23663
23476
  *
23664
- * @param commentId The {@link Amity.Comment} ID to delete
23665
- * @return A success boolean if the {@link Amity.Comment} was deleted
23477
+ * @param postId The {@link Amity.Post} ID to be hard delete
23478
+ * @return A success boolean if the {@link Amity.Post} was deleted
23666
23479
  *
23667
- * @category Comment API
23480
+ * @category Post API
23668
23481
  * @async
23669
23482
  */
23670
- const hardDeleteComment = async (commentId) => {
23483
+ const hardDeletePost = async (postId) => {
23671
23484
  const client = getActiveClient();
23672
- client.log('comment/hardDeleteComment', commentId);
23673
- const hardDeleted = deleteComment(commentId, true);
23674
- return hardDeleted;
23485
+ client.log('post/hardDeletePost', postId);
23486
+ const hardDeleted = await deletePost(postId, true);
23487
+ return LinkedObject.post(hardDeleted);
23675
23488
  };
23676
23489
  /* end_public_function */
23677
23490
 
23678
23491
  /* begin_public_function
23679
- id: comment.flag
23492
+ id: post.approve
23680
23493
  */
23681
23494
  /**
23682
23495
  * ```js
23683
- * import { CommentRepository } from '@amityco/ts-sdk'
23684
- * const flagged = await CommentRepository.flagComment(commentId, reason)
23496
+ * import { approvePost } from '@amityco/ts-sdk'
23497
+ *
23498
+ * const { data: post } = await approvePost('postId')
23685
23499
  * ```
23686
23500
  *
23687
- * @param commentId The ID of the comment to flag
23688
- * @param reason the reason to flag the comment
23689
- * @returns the created report result
23501
+ * Approves a {@link Amity.Post}
23690
23502
  *
23691
- * @category Comment API
23692
- * @async
23693
- * */
23694
- const flagComment = async (commentId, reason) => {
23503
+ * @param postId The {@link Amity.Post} ID to be approved
23504
+ * @return A {@link Amity.Post} that was approved
23505
+ *
23506
+ * @category Post API
23507
+ * @async
23508
+ */
23509
+ const approvePost = async (postId) => {
23695
23510
  const client = getActiveClient();
23696
- client.log('comment/flagComment', commentId);
23511
+ client.log('post/approvePost', postId);
23512
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
23513
+ fireEvent('post.approved', payload);
23514
+ // fire virtual event for community update
23515
+ if (payload.posts[0].targetType === 'community') {
23516
+ fireEvent('community.updated', payload);
23517
+ }
23518
+ const data = prepareMembershipPayload(payload, 'communityUsers');
23519
+ const cachedAt = client.cache && Date.now();
23520
+ if (client.cache)
23521
+ ingestInCache(data, { cachedAt });
23522
+ return {
23523
+ data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
23524
+ cachedAt,
23525
+ };
23526
+ };
23527
+ /* end_public_function */
23528
+
23529
+ /* begin_public_function
23530
+ id: post.decline
23531
+ */
23532
+ /**
23533
+ * ```js
23534
+ * import { declinePost } from '@amityco/ts-sdk'
23535
+ *
23536
+ * const {data: post} = await declinePost('postId')
23537
+ * ```
23538
+ *
23539
+ * Declines a {@link Amity.Post}
23540
+ *
23541
+ * @param postId The {@link Amity.Post} ID to be declined
23542
+ * @return A {@link Amity.Post} that was declined
23543
+ *
23544
+ * @category Post API
23545
+ * @async
23546
+ */
23547
+ const declinePost = async (postId) => {
23548
+ const client = getActiveClient();
23549
+ client.log('post/declinePost', postId);
23550
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
23551
+ // fire virtual event
23552
+ if (payload.posts[0].targetType === 'community') {
23553
+ fireEvent('community.updated', payload);
23554
+ }
23555
+ fireEvent('post.declined', payload);
23556
+ const data = prepareMembershipPayload(payload, 'communityUsers');
23557
+ const cachedAt = client.cache && Date.now();
23558
+ if (client.cache)
23559
+ ingestInCache(data, { cachedAt });
23560
+ return {
23561
+ data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
23562
+ cachedAt,
23563
+ };
23564
+ };
23565
+ /* end_public_function */
23566
+
23567
+ /* begin_public_function
23568
+ id: post.flag
23569
+ */
23570
+ /**
23571
+ * ```js
23572
+ * import { PostRepository } from '@amityco/ts-sdk'
23573
+ * const flagged = await PostRepository.flagPost(postId, reason)
23574
+ * ```
23575
+ *
23576
+ * @param postId of the post to flag
23577
+ * @param reason the reason to flag the post
23578
+ * @returns a boolean
23579
+ *
23580
+ * @category Post API
23581
+ * @async
23582
+ * */
23583
+ const flagPost = async (postId, reason) => {
23584
+ const client = getActiveClient();
23585
+ client.log('post/flagPost', postId);
23697
23586
  const isPredefinedReason = reason &&
23698
23587
  Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
23699
23588
  const body = {
23700
23589
  reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
23701
23590
  detail: reason && !isPredefinedReason ? reason : '',
23702
23591
  };
23703
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
23592
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
23704
23593
  if (client.cache) {
23705
- ingestInCache(payload);
23594
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
23706
23595
  }
23707
- fireEvent('comment.flagged', payload);
23596
+ fireEvent('post.flagged', payload);
23708
23597
  return !!payload;
23709
23598
  };
23710
23599
  /* end_public_function */
23711
23600
 
23712
23601
  /* begin_public_function
23713
- id: comment.unflag
23602
+ id: post.unflag
23714
23603
  */
23715
23604
  /**
23716
23605
  * ```js
23717
- * import { CommentRepository } from '@amityco/ts-sdk'
23718
- * const unflagged = await CommentRepository.unflagComment('commentId')
23606
+ * import { PostRepository } from '@amityco/ts-sdk'
23607
+ * const unflagged = await PostRepository.unflagPost(postId)
23719
23608
  * ```
23720
23609
  *
23721
- * @param commentId The ID of comment to unflag
23722
- * @returns the unflagged result
23610
+ * @param postId of the post to unflag
23611
+ * @returns the unflag post result
23723
23612
  *
23724
- * @category Comment API
23613
+ * @category Post API
23725
23614
  * @async
23726
23615
  * */
23727
- const unflagComment = async (commentId) => {
23616
+ const unflagPost = async (postId) => {
23728
23617
  const client = getActiveClient();
23729
- client.log('comment/unflagComment', commentId);
23730
- const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
23618
+ client.log('post/unflagPost', postId);
23619
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
23731
23620
  if (client.cache) {
23732
- ingestInCache(payload);
23621
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
23733
23622
  }
23734
- fireEvent('comment.unflagged', payload);
23623
+ fireEvent('post.unflagged', payload);
23735
23624
  return !!payload;
23736
23625
  };
23737
23626
  /* end_public_function */
23738
23627
 
23739
23628
  /* begin_public_function
23740
- id: comment.check_flag_by_me
23629
+ id: post.check_flag_by_me
23741
23630
  */
23742
23631
  /**
23743
23632
  * ```js
23744
- * import { CommentRepository } from '@amityco/ts-sdk'
23745
- * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
23633
+ * import { PostRepository } from '@amityco/ts-sdk'
23634
+ * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
23746
23635
  * ```
23747
23636
  *
23748
- * @param commentId The ID of the comment to check if flagged by current user
23749
- * @returns `true` if the comment is flagged by me, `false` if doesn't.
23637
+ * @param postId of the post to check if flagged by current user
23638
+ * @returns `true` if the post is flagged by me, `false` if doesn't.
23750
23639
  *
23751
- * @category Comment API
23640
+ * @category Post API
23752
23641
  * @async
23753
23642
  * */
23754
- const isCommentFlaggedByMe = async (commentId) => {
23643
+ const isPostFlaggedByMe = async (postId) => {
23755
23644
  const client = getActiveClient();
23756
- client.log('comment/isCommentFlaggedByMe', commentId);
23757
- const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
23645
+ client.log('post/isPostFlaggedByMe', postId);
23646
+ const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
23758
23647
  return result;
23759
23648
  };
23760
23649
  /* end_public_function */
23761
23650
 
23762
- const getComment$1 = async (commentId) => {
23651
+ /* begin_public_function
23652
+ id: post.create.clip_post
23653
+ */
23654
+ /**
23655
+ * ```js
23656
+ * import { PostRepository } from '@amityco/ts-sdk'
23657
+ * const created = await PostRepository.createClipPost({
23658
+ * targetType: 'user',
23659
+ * targetId: 'foobar',
23660
+ * dataType: 'clip',
23661
+ * data: { text: 'hello world' },
23662
+ * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
23663
+ * }))
23664
+ * ```
23665
+ *
23666
+ * Creates an {@link Amity.Post}
23667
+ *
23668
+ * @param bundle The data necessary to create a new {@link Amity.Post}
23669
+ * @returns The newly created {@link Amity.Post}
23670
+ *
23671
+ * @category Post API
23672
+ * @async
23673
+ */
23674
+ const createClipPost = async (bundle) => {
23763
23675
  const client = getActiveClient();
23764
- client.log('comment/getComment', commentId);
23765
- isInTombstone('comment', commentId);
23676
+ client.log('post/createPost', bundle);
23677
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
23678
+ fireEvent('post.created', payload);
23679
+ const data = prepareMembershipPayload(payload, 'communityUsers');
23680
+ const cachedAt = client.cache && Date.now();
23681
+ if (client.cache)
23682
+ ingestInCache(data, { cachedAt });
23683
+ const { posts } = data;
23684
+ return {
23685
+ data: LinkedObject.post(posts[0]),
23686
+ cachedAt,
23687
+ };
23688
+ };
23689
+ /* end_public_function */
23690
+
23691
+ /* begin_public_function
23692
+ id: comment.get_by_ids
23693
+ */
23694
+ /**
23695
+ * ```js
23696
+ * import { CommentRepository } from '@amityco/ts-sdk'
23697
+ * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
23698
+ * ```
23699
+ *
23700
+ * Fetches a collection of {@link Amity.Comment} objects
23701
+ *
23702
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23703
+ * @returns the associated collection of {@link Amity.Comment} objects
23704
+ *
23705
+ * @category Comment API
23706
+ * @async
23707
+ */
23708
+ const getCommentByIds = async (commentIds) => {
23709
+ const client = getActiveClient();
23710
+ client.log('comment/getCommentByIds', commentIds);
23711
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
23766
23712
  let data;
23767
23713
  try {
23768
23714
  // API-FIX: endpoint should not be /list, parameters should be querystring.
23769
- const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
23715
+ const response = await client.http.get(`/api/v3/comments/list`, {
23716
+ params: { commentIds: encodedCommentIds },
23717
+ });
23770
23718
  data = response.data;
23771
23719
  }
23772
23720
  catch (error) {
23773
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23774
- pushToTombstone('comment', commentId);
23775
- }
23721
+ commentIds.forEach(commentId => {
23722
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23723
+ pushToTombstone('comment', commentId);
23724
+ }
23725
+ });
23776
23726
  throw error;
23777
23727
  }
23778
23728
  const cachedAt = client.cache && Date.now();
23779
23729
  if (client.cache)
23780
23730
  ingestInCache(data, { cachedAt });
23781
- const { comments } = data;
23782
23731
  return {
23783
- data: comments.find(comment => comment.commentId === commentId),
23732
+ data: data.comments.map(comment => LinkedObject.comment(comment)),
23784
23733
  cachedAt,
23785
23734
  };
23786
23735
  };
23787
- getComment$1.locally = (commentId) => {
23736
+ /* end_public_function */
23737
+ /**
23738
+ * ```js
23739
+ * import { getCommentByIds } from '@amityco/ts-sdk'
23740
+ * const comments = getCommentByIds.locally(['foo', 'bar'])
23741
+ * ```
23742
+ *
23743
+ * Fetches a collection of {@link Amity.Comment} objects from cache
23744
+ *
23745
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
23746
+ * @returns the associated collection of {@link Amity.Comment} objects
23747
+ *
23748
+ * @category Comment API
23749
+ */
23750
+ getCommentByIds.locally = (commentIds) => {
23751
+ var _a;
23788
23752
  const client = getActiveClient();
23789
- client.log('comment/getComment.locally', commentId);
23753
+ client.log('comment/getCommentByIds.locally', commentIds);
23790
23754
  if (!client.cache)
23791
23755
  return;
23792
- const cached = pullFromCache(['comment', 'get', commentId]);
23793
- if (!cached)
23756
+ const cached = commentIds
23757
+ .map(commentId => pullFromCache(['comment', 'get', commentId]))
23758
+ .filter(Boolean);
23759
+ const comments = cached.map(({ data }) => data);
23760
+ const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
23761
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
23794
23762
  return;
23795
23763
  return {
23796
- data: cached.data,
23797
- cachedAt: cached.cachedAt,
23764
+ data: comments.map(comment => LinkedObject.comment(comment)),
23765
+ cachedAt: oldest.cachedAt,
23798
23766
  };
23799
23767
  };
23800
23768
 
23769
+ /* begin_public_function
23770
+ id: comment.create
23771
+ */
23801
23772
  /**
23802
23773
  * ```js
23803
- * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
23804
- * const dispose = onCommentDeleteLocal(comment => {
23805
- * // ...
23806
- * })
23774
+ * import { CommentRepository } from '@amityco/ts-sdk'
23775
+ * const newComment = await CommentRepository.createComment(bundle)
23807
23776
  * ```
23808
23777
  *
23809
- * Fired when a {@link Amity.InternalComment} has been deleted
23778
+ * Creates an {@link Amity.Comment}
23810
23779
  *
23811
- * @param callback The function to call when the event was fired
23812
- * @returns an {@link Amity.Unsubscriber} function to stop listening
23780
+ * @param bundle The data necessary to create a new {@link Amity.Comment}
23781
+ * @returns The newly created {@link Amity.Comment}
23813
23782
  *
23814
- * @category Comment Events
23815
- */
23816
- const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
23817
-
23818
- /**
23819
- * ```js
23820
- * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
23821
- * const dispose = onLocalCommentReactionAdded(comment => {
23822
- * // ...
23823
- * })
23824
- * ```
23825
- *
23826
- * Fired when a {@link Amity.InternalComment} has been reacted
23827
- *
23828
- * @param callback The function to call when the event was fired
23829
- * @returns an {@link Amity.Unsubscriber} function to stop listening
23830
- *
23831
- * @category Comment Events
23783
+ * @category Comment API
23784
+ * @async
23832
23785
  */
23833
- const onLocalCommentReactionAdded = (callback) => {
23786
+ const createComment = async (bundle) => {
23787
+ var _a;
23834
23788
  const client = getActiveClient();
23835
- const filter = ({ comment }) => {
23836
- if (!client.cache) {
23837
- callback(comment);
23789
+ client.log('comment/createComment', bundle);
23790
+ const { data } = await client.http.post('/api/v3/comments', bundle);
23791
+ const { comments } = data;
23792
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
23793
+ if (comments.length === 0)
23794
+ throw new Error('Comment not created');
23795
+ const cachedAt = client.cache && Date.now();
23796
+ if (client.cache)
23797
+ ingestInCache(data, { cachedAt });
23798
+ if (['post', 'content'].includes(bundle.referenceType)) {
23799
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23800
+ if (post) {
23801
+ post.commentsCount += 1;
23802
+ fireEvent('local.post.updated', {
23803
+ posts: [post],
23804
+ categories: [],
23805
+ comments: [],
23806
+ communities: [],
23807
+ communityUsers: data.communityUsers,
23808
+ feeds: [],
23809
+ files: data.files,
23810
+ postChildren: [],
23811
+ users: data.users,
23812
+ videoStreamings: [],
23813
+ });
23838
23814
  }
23839
- else {
23840
- upsertInCache(['comment', 'get', comment.commentId], comment);
23841
- callback(commentLinkedObject(comment));
23815
+ }
23816
+ else if (bundle.referenceType === 'story') {
23817
+ const storyIndex = pullFromCache([
23818
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23819
+ bundle.referenceId,
23820
+ ]);
23821
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
23822
+ const cacheStory = pullFromCache([
23823
+ "story" /* STORY_KEY_CACHE.STORY */,
23824
+ 'get',
23825
+ storyIndex.data,
23826
+ ]);
23827
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
23828
+ fireEvent('story.updated', {
23829
+ stories: [
23830
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
23831
+ ],
23832
+ categories: [],
23833
+ comments,
23834
+ communities: [],
23835
+ communityUsers: data.communityUsers,
23836
+ files: data.files,
23837
+ users: data.users,
23838
+ });
23839
+ }
23842
23840
  }
23841
+ }
23842
+ fireEvent('local.comment.created', data);
23843
+ return {
23844
+ data: LinkedObject.comment(comments[0]),
23845
+ cachedAt,
23843
23846
  };
23844
- return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
23845
23847
  };
23848
+ /* end_public_function */
23846
23849
 
23850
+ /* begin_public_function
23851
+ id: comment.update_comment
23852
+ */
23847
23853
  /**
23848
23854
  * ```js
23849
- * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
23850
- * const dispose = onLocalCommentReactionRemoved(comment => {
23851
- * // ...
23855
+ * import { CommentRepository } from '@amityco/ts-sdk'
23856
+ * const updated = await CommentRepository.updateComment(commentId, {
23857
+ * data: { text: 'hello world' }
23852
23858
  * })
23853
23859
  * ```
23854
23860
  *
23855
- * Fired when a {@link Amity.InternalComment} has been reacted
23861
+ * Updates an {@link Amity.Comment}
23856
23862
  *
23857
- * @param callback The function to call when the event was fired
23858
- * @returns an {@link Amity.Unsubscriber} function to stop listening
23863
+ * @param commentId The ID of the {@link Amity.Comment} to edit
23864
+ * @param patch The patch data to apply
23865
+ * @returns the updated {@link Amity.Comment} object
23859
23866
  *
23860
- * @category Comment Events
23867
+ * @category Comment API
23868
+ * @async
23861
23869
  */
23862
- const onLocalCommentReactionRemoved = (callback) => {
23870
+ const updateComment = async (commentId, patch) => {
23863
23871
  const client = getActiveClient();
23864
- const filter = ({ comment }) => {
23865
- if (!client.cache) {
23866
- callback(comment);
23867
- }
23868
- else {
23869
- upsertInCache(['comment', 'get', comment.commentId], comment);
23870
- callback(commentLinkedObject(comment));
23872
+ client.log('user/updateComment', patch);
23873
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
23874
+ const cachedAt = client.cache && Date.now();
23875
+ if (client.cache)
23876
+ ingestInCache(data, { cachedAt });
23877
+ fireEvent('comment.updated', data);
23878
+ const { comments } = data;
23879
+ return {
23880
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
23881
+ cachedAt,
23882
+ };
23883
+ };
23884
+ /* end_public_function */
23885
+
23886
+ // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
23887
+ const applyMissingField = (rawData, isCreated = false) => {
23888
+ const { storyId, referenceId } = rawData;
23889
+ if (!isCreated) {
23890
+ if (referenceId)
23891
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
23892
+ }
23893
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
23894
+ };
23895
+ const convertRawStoryToInternal = (data, isCreated = false) => {
23896
+ const { stories } = data;
23897
+ const storiesData = stories.map(story => applyMissingField(story, isCreated));
23898
+ return Object.assign(Object.assign({}, data), { stories: storiesData });
23899
+ };
23900
+
23901
+ const getStoryByStoryId$1 = async (storyId) => {
23902
+ const client = getActiveClient();
23903
+ client.log('story/getStoryByStoryId', storyId);
23904
+ // Get story referenceId from cache
23905
+ const cacheReferenceId = pullFromCache([
23906
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23907
+ storyId,
23908
+ ]);
23909
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23910
+ const { data: referenceId } = cacheReferenceId;
23911
+ isInTombstone('story', referenceId);
23912
+ }
23913
+ let data;
23914
+ try {
23915
+ const response = await client.http.get(`/api/v4/stories/${storyId}`);
23916
+ data = convertRawStoryToInternal(response.data);
23917
+ }
23918
+ catch (error) {
23919
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23920
+ pushToTombstone('story', storyId);
23871
23921
  }
23922
+ throw error;
23923
+ }
23924
+ const cachedAt = client.cache && Date.now();
23925
+ if (client.cache) {
23926
+ ingestInCache(data, { cachedAt });
23927
+ }
23928
+ return {
23929
+ data: data.stories[0],
23930
+ cachedAt,
23931
+ };
23932
+ };
23933
+ getStoryByStoryId$1.locally = (storyId) => {
23934
+ const client = getActiveClient();
23935
+ client.log('story/getStorybyStoryId', storyId);
23936
+ // Get story referenceId from cache
23937
+ const cacheReferenceId = pullFromCache([
23938
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
23939
+ storyId,
23940
+ ]);
23941
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
23942
+ const { data: referenceId } = cacheReferenceId;
23943
+ isInTombstone('story', referenceId);
23944
+ }
23945
+ const cachedAt = client.cache && Date.now();
23946
+ const storyCache = pullFromCache(['story', 'get', storyId]);
23947
+ if (!storyCache)
23948
+ return;
23949
+ return {
23950
+ data: storyCache.data,
23951
+ cachedAt,
23872
23952
  };
23873
- return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
23874
23953
  };
23875
23954
 
23876
23955
  /* begin_public_function
23877
- id: comment.get
23956
+ id: comment.soft_delete, comment.hard_delete
23878
23957
  */
23879
23958
  /**
23880
23959
  * ```js
23881
- * import { CommentRepository } from '@amityco/ts-sdk';
23882
- *
23883
- * let comment;
23884
- *
23885
- * const unsub = CommentRepository.getComment(commentId, response => {
23886
- * comment = response.data;
23887
- * });
23960
+ * import { CommentRepository } from '@amityco/ts-sdk'
23961
+ * const success = await CommentRepository.deleteComment('foobar')
23888
23962
  * ```
23889
23963
  *
23890
- * Observe all mutation on a given {@link Amity.Comment}
23964
+ * Deletes a {@link Amity.Comment}
23891
23965
  *
23892
- * @param commentId the ID of the comment to observe
23893
- * @param callback the function to call when new data are available
23894
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
23966
+ * @param commentId The {@link Amity.Comment} ID to delete
23967
+ * @return A success boolean if the {@link Amity.Comment} was deleted
23895
23968
  *
23896
- * @category Comment Live Object
23969
+ * @category Comment API
23970
+ * @async
23897
23971
  */
23898
- const getComment = (commentId, callback) => {
23899
- return liveObject(commentId, callback, 'commentId', getComment$1, [
23900
- onCommentDeleteLocal,
23901
- onCommentDeleted,
23902
- onCommentFlagged,
23903
- onCommentReactionAdded,
23904
- onCommentReactionRemoved,
23905
- onCommentUnflagged,
23906
- onCommentUpdated,
23907
- onLocalCommentReactionAdded,
23908
- onLocalCommentReactionRemoved,
23909
- ]);
23910
- };
23911
- /* end_public_function */
23912
-
23913
- class CommentPaginationController extends PaginationController {
23914
- async getRequest(queryParams, token) {
23915
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
23916
- const baseOptions = {
23917
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
23918
- };
23919
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
23920
- const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
23921
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
23922
- });
23923
- return queryResponse;
23924
- }
23925
- }
23926
-
23927
- var EnumCommentActions;
23928
- (function (EnumCommentActions) {
23929
- EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
23930
- EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
23931
- EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
23932
- EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
23933
- EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
23934
- EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
23935
- EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
23936
- })(EnumCommentActions || (EnumCommentActions = {}));
23937
-
23938
- class CommentQueryStreamController extends QueryStreamController {
23939
- constructor(query, cacheKey, notifyChange, preparePayload) {
23940
- super(query, cacheKey);
23941
- this.notifyChange = notifyChange;
23942
- this.preparePayload = preparePayload;
23943
- }
23944
- async saveToMainDB(response) {
23945
- const processedPayload = await this.preparePayload(response);
23946
- const client = getActiveClient();
23947
- const cachedAt = client.cache && Date.now();
23948
- if (client.cache) {
23949
- ingestInCache(processedPayload, { cachedAt });
23950
- }
23972
+ const deleteComment = async (commentId, permanent = false) => {
23973
+ var _a;
23974
+ const client = getActiveClient();
23975
+ const comment = await getComment$2(commentId);
23976
+ // API-FIX: This endpoint has not been implemented yet.
23977
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
23978
+ params: {
23979
+ commentId,
23980
+ permanent,
23981
+ },
23982
+ });
23983
+ // to support hard deletion
23984
+ const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
23985
+ if (comment.data.referenceType === 'story') {
23986
+ const story = await getStoryByStoryId$1(comment.data.referenceId);
23987
+ fireEvent('local.story.updated', {
23988
+ stories: [story.data],
23989
+ categories: [],
23990
+ comments: [],
23991
+ communities: [],
23992
+ communityUsers: [],
23993
+ files: [],
23994
+ users: [],
23995
+ });
23951
23996
  }
23952
- appendToQueryStream(response, direction, refresh = false) {
23953
- var _a, _b;
23954
- if (refresh) {
23955
- pushToCache(this.cacheKey, {
23956
- data: response.comments.map(getResolver('comment')),
23997
+ else {
23998
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
23999
+ if (post) {
24000
+ let removeCount;
24001
+ if (!deleted.parentId) {
24002
+ // NOTE: delete the parent comment will remove all children comments
24003
+ removeCount = deleted.childrenNumber + 1;
24004
+ }
24005
+ else
24006
+ removeCount = 1;
24007
+ post.commentsCount -= removeCount;
24008
+ fireEvent('local.post.updated', {
24009
+ posts: [post],
24010
+ categories: [],
24011
+ comments: [],
24012
+ communities: [],
24013
+ communityUsers: [],
24014
+ feeds: [],
24015
+ files: [],
24016
+ postChildren: [],
24017
+ users: [],
24018
+ videoStreamings: [],
23957
24019
  });
23958
24020
  }
23959
- else {
23960
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23961
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23962
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
23963
- }
23964
24021
  }
23965
- reactor(action) {
23966
- return (comment) => {
23967
- var _a;
23968
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23969
- if (this.query.referenceId !== comment.referenceId ||
23970
- this.query.referenceType !== comment.referenceType ||
23971
- !collection) {
23972
- return;
23973
- }
23974
- if (this.query.parentId && this.query.parentId !== comment.parentId) {
23975
- return;
23976
- }
23977
- if (!this.query.parentId && comment.parentId) {
23978
- return;
23979
- }
23980
- if (action === EnumCommentActions.OnCommentCreated) {
23981
- collection.data = [...new Set([comment.commentId, ...collection.data])];
23982
- }
23983
- pushToCache(this.cacheKey, collection);
23984
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
23985
- };
24022
+ fireEvent('local.comment.deleted', {
24023
+ comments: [deleted],
24024
+ commentChildren: [],
24025
+ files: [],
24026
+ users: [],
24027
+ communityUsers: [],
24028
+ });
24029
+ if (permanent) {
24030
+ scheduleTask(() => pushToTombstone('comment', commentId));
23986
24031
  }
23987
- subscribeRTE(createSubscriber) {
23988
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24032
+ else {
24033
+ upsertInCache(['comment', 'get', commentId], { isDeleted: true });
23989
24034
  }
23990
- }
24035
+ return deleted;
24036
+ };
24037
+ /* end_public_function */
23991
24038
 
24039
+ /* begin_public_function
24040
+ id: comment.soft_delete
24041
+ */
23992
24042
  /**
23993
24043
  * ```js
23994
- * import { onCommentCreated } from '@amityco/ts-sdk'
23995
- * const dispose = onCommentCreated(comment => {
23996
- * // ...
23997
- * })
24044
+ * import { CommentRepository } from '@amityco/ts-sdk'
24045
+ * const success = await CommentRepository.softDeleteComment('foobar')
23998
24046
  * ```
23999
24047
  *
24000
- * Fired when a {@link Amity.InternalComment} has been created
24048
+ * Deletes a {@link Amity.Comment}
24001
24049
  *
24002
- * @param callback The function to call when the event was fired
24003
- * @returns an {@link Amity.Unsubscriber} function to stop listening
24050
+ * @param commentId The {@link Amity.Comment} ID to delete
24051
+ * @return A success boolean if the {@link Amity.Comment} was deleted
24004
24052
  *
24005
- * @category Comment Events
24053
+ * @category Comment API
24054
+ * @async
24006
24055
  */
24007
- const onCommentCreatedLocal = (callback) => {
24008
- return createLocalCommentEventSubscriber('local.comment.created', callback);
24056
+ const softDeleteComment = async (commentId) => {
24057
+ const client = getActiveClient();
24058
+ client.log('comment/softDeleteComment', commentId);
24059
+ const softDeleted = deleteComment(commentId);
24060
+ return softDeleted;
24009
24061
  };
24010
-
24011
- class CommentLiveCollectionController extends LiveCollectionController {
24012
- constructor(query, callback) {
24013
- const queryStreamId = hash__default["default"](query);
24014
- const cacheKey = ['comments', 'collection', queryStreamId];
24015
- const paginationController = new CommentPaginationController(query);
24016
- super(paginationController, queryStreamId, cacheKey, callback);
24017
- this.query = query;
24018
- this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
24019
- this.callback = callback.bind(this);
24020
- this.loadPage({ initial: true });
24021
- }
24022
- setup() {
24023
- var _a;
24024
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24025
- if (!collection) {
24026
- pushToCache(this.cacheKey, {
24027
- data: [],
24028
- params: {},
24029
- });
24030
- }
24031
- }
24032
- async persistModel(queryPayload) {
24033
- await this.queryStreamController.saveToMainDB(queryPayload);
24034
- }
24035
- persistQueryStream({ response, direction, refresh, }) {
24036
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
24037
- }
24038
- startSubscription() {
24039
- return this.queryStreamController.subscribeRTE([
24040
- { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
24041
- { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
24042
- { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
24043
- { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
24044
- { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
24045
- { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
24046
- { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
24047
- { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24048
- { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24049
- { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24050
- { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24051
- ]);
24052
- }
24053
- notifyChange({ origin, loading, error }) {
24054
- var _a, _b;
24055
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24056
- if (!collection)
24057
- return;
24058
- const data = this.applyFilter((_b = collection.data
24059
- .map(id => pullFromCache(['comment', 'get', id]))
24060
- .filter(isNonNullable)
24061
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
24062
- if (!this.shouldNotify(data) && origin === 'event')
24063
- return;
24064
- this.callback({
24065
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
24066
- data,
24067
- hasNextPage: !!this.paginationController.getNextToken(),
24068
- loading,
24069
- error,
24070
- });
24071
- }
24072
- applyFilter(data) {
24073
- let comments = data;
24074
- if (!this.query.includeDeleted) {
24075
- comments = filterByPropEquality(comments, 'isDeleted', false);
24076
- }
24077
- if (this.query.parentId) {
24078
- comments = comments.filter(comment => comment.parentId === this.query.parentId);
24079
- }
24080
- if (typeof this.query.hasFlag === 'boolean') {
24081
- if (this.query.hasFlag) {
24082
- comments = comments.filter(comment => comment.hashFlag != null);
24083
- }
24084
- else {
24085
- comments = comments.filter(comment => comment.hashFlag == null);
24086
- }
24087
- }
24088
- if (this.query.dataTypes) {
24089
- if (this.query.dataTypes.matchType === 'exact') {
24090
- comments = comments.filter(comment => {
24091
- var _a, _b;
24092
- const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
24093
- const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
24094
- if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
24095
- return false;
24096
- }
24097
- return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
24098
- });
24099
- }
24100
- if (this.query.dataTypes.matchType === 'any') {
24101
- comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
24102
- }
24103
- }
24104
- switch (this.query.sortBy) {
24105
- case 'firstCreated':
24106
- comments = comments.sort(sortByFirstCreated);
24107
- break;
24108
- case 'lastCreated':
24109
- default:
24110
- comments = comments.sort(sortByLastCreated);
24111
- break;
24112
- }
24113
- return comments;
24114
- }
24115
- }
24062
+ /* end_public_function */
24116
24063
 
24117
24064
  /* begin_public_function
24118
- id: comment.query
24065
+ id: comment.hard_delete
24119
24066
  */
24120
24067
  /**
24121
24068
  * ```js
24122
- * import { getComments } from '@amityco/ts-sdk'
24123
- *
24124
- * let comments = []
24125
- * const unsub = getComments({
24126
- * referenceType: Amity.InternalComment['referenceType'];
24127
- * referenceId: Amity.InternalComment['referenceId'];
24128
- * }, response => merge(comments, response.data))
24069
+ * import { CommentRepository } from '@amityco/ts-sdk'
24070
+ * const success = await CommentRepository.hardDeleteComment('foobar')
24129
24071
  * ```
24130
24072
  *
24131
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
24073
+ * Deletes a {@link Amity.Comment}
24132
24074
  *
24133
- * @param referenceType the type of the target
24134
- * @param referenceId the ID of the target
24135
- * @param callback the function to call when new data are available
24136
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24075
+ * @param commentId The {@link Amity.Comment} ID to delete
24076
+ * @return A success boolean if the {@link Amity.Comment} was deleted
24137
24077
  *
24138
- * @category Comments Live Collection
24078
+ * @category Comment API
24079
+ * @async
24139
24080
  */
24140
- const getComments = (params, callback, config) => {
24141
- const { log, cache } = getActiveClient();
24142
- if (!cache) {
24143
- console.log('For using Live Collection feature you need to enable Cache!');
24144
- }
24145
- const timestamp = Date.now();
24146
- log(`getComments(tmpid: ${timestamp}) > listen`);
24147
- const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
24148
- const disposers = commentsLiveCollection.startSubscription();
24149
- const cacheKey = commentsLiveCollection.getCacheKey();
24150
- disposers.push(() => dropFromCache(cacheKey));
24151
- return () => {
24152
- log(`getComments(tmpid: ${timestamp}) > dispose`);
24153
- disposers.forEach(fn => fn());
24081
+ const hardDeleteComment = async (commentId) => {
24082
+ const client = getActiveClient();
24083
+ client.log('comment/hardDeleteComment', commentId);
24084
+ const hardDeleted = deleteComment(commentId, true);
24085
+ return hardDeleted;
24086
+ };
24087
+ /* end_public_function */
24088
+
24089
+ /* begin_public_function
24090
+ id: comment.flag
24091
+ */
24092
+ /**
24093
+ * ```js
24094
+ * import { CommentRepository } from '@amityco/ts-sdk'
24095
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
24096
+ * ```
24097
+ *
24098
+ * @param commentId The ID of the comment to flag
24099
+ * @param reason the reason to flag the comment
24100
+ * @returns the created report result
24101
+ *
24102
+ * @category Comment API
24103
+ * @async
24104
+ * */
24105
+ const flagComment = async (commentId, reason) => {
24106
+ const client = getActiveClient();
24107
+ client.log('comment/flagComment', commentId);
24108
+ const isPredefinedReason = reason &&
24109
+ Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
24110
+ const body = {
24111
+ reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
24112
+ detail: reason && !isPredefinedReason ? reason : '',
24154
24113
  };
24114
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
24115
+ if (client.cache) {
24116
+ ingestInCache(payload);
24117
+ }
24118
+ fireEvent('comment.flagged', payload);
24119
+ return !!payload;
24155
24120
  };
24156
24121
  /* end_public_function */
24157
24122
 
24158
- var index$a = /*#__PURE__*/Object.freeze({
24159
- __proto__: null,
24160
- getCommentByIds: getCommentByIds,
24161
- createComment: createComment,
24162
- updateComment: updateComment,
24163
- deleteComment: deleteComment,
24164
- softDeleteComment: softDeleteComment,
24165
- hardDeleteComment: hardDeleteComment,
24166
- flagComment: flagComment,
24167
- unflagComment: unflagComment,
24168
- isCommentFlaggedByMe: isCommentFlaggedByMe,
24169
- onCommentCreated: onCommentCreated,
24170
- onCommentUpdated: onCommentUpdated,
24171
- onCommentDeleted: onCommentDeleted,
24172
- onCommentFlagged: onCommentFlagged,
24173
- onCommentUnflagged: onCommentUnflagged,
24174
- onCommentReactionAdded: onCommentReactionAdded,
24175
- onCommentReactionRemoved: onCommentReactionRemoved,
24176
- getComment: getComment,
24177
- getComments: getComments
24178
- });
24123
+ /* begin_public_function
24124
+ id: comment.unflag
24125
+ */
24126
+ /**
24127
+ * ```js
24128
+ * import { CommentRepository } from '@amityco/ts-sdk'
24129
+ * const unflagged = await CommentRepository.unflagComment('commentId')
24130
+ * ```
24131
+ *
24132
+ * @param commentId The ID of comment to unflag
24133
+ * @returns the unflagged result
24134
+ *
24135
+ * @category Comment API
24136
+ * @async
24137
+ * */
24138
+ const unflagComment = async (commentId) => {
24139
+ const client = getActiveClient();
24140
+ client.log('comment/unflagComment', commentId);
24141
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
24142
+ if (client.cache) {
24143
+ ingestInCache(payload);
24144
+ }
24145
+ fireEvent('comment.unflagged', payload);
24146
+ return !!payload;
24147
+ };
24148
+ /* end_public_function */
24149
+
24150
+ /* begin_public_function
24151
+ id: comment.check_flag_by_me
24152
+ */
24153
+ /**
24154
+ * ```js
24155
+ * import { CommentRepository } from '@amityco/ts-sdk'
24156
+ * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
24157
+ * ```
24158
+ *
24159
+ * @param commentId The ID of the comment to check if flagged by current user
24160
+ * @returns `true` if the comment is flagged by me, `false` if doesn't.
24161
+ *
24162
+ * @category Comment API
24163
+ * @async
24164
+ * */
24165
+ const isCommentFlaggedByMe = async (commentId) => {
24166
+ const client = getActiveClient();
24167
+ client.log('comment/isCommentFlaggedByMe', commentId);
24168
+ const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
24169
+ return result;
24170
+ };
24171
+ /* end_public_function */
24179
24172
 
24180
- const getPost$1 = async (postId) => {
24173
+ const getComment$1 = async (commentId) => {
24181
24174
  const client = getActiveClient();
24182
- client.log('post/getPost', postId);
24183
- isInTombstone('post', postId);
24184
- let payload;
24175
+ client.log('comment/getComment', commentId);
24176
+ isInTombstone('comment', commentId);
24177
+ let data;
24185
24178
  try {
24186
24179
  // API-FIX: endpoint should not be /list, parameters should be querystring.
24187
- const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
24188
- payload = response.data;
24180
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
24181
+ data = response.data;
24189
24182
  }
24190
24183
  catch (error) {
24191
24184
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24192
- pushToTombstone('post', postId);
24185
+ pushToTombstone('comment', commentId);
24193
24186
  }
24194
24187
  throw error;
24195
24188
  }
24196
- const data = prepareMembershipPayload(payload, 'communityUsers');
24197
24189
  const cachedAt = client.cache && Date.now();
24198
24190
  if (client.cache)
24199
24191
  ingestInCache(data, { cachedAt });
24200
- const { posts } = data;
24201
- const result = posts.find(post => post.postId === postId);
24192
+ const { comments } = data;
24202
24193
  return {
24203
- data: result,
24194
+ data: comments.find(comment => comment.commentId === commentId),
24204
24195
  cachedAt,
24205
24196
  };
24206
24197
  };
24207
- getPost$1.locally = (postId) => {
24198
+ getComment$1.locally = (commentId) => {
24208
24199
  const client = getActiveClient();
24209
- client.log('post/getPost.locally', postId);
24200
+ client.log('comment/getComment.locally', commentId);
24210
24201
  if (!client.cache)
24211
24202
  return;
24212
- const cached = pullFromCache(['post', 'get', postId]);
24203
+ const cached = pullFromCache(['comment', 'get', commentId]);
24213
24204
  if (!cached)
24214
24205
  return;
24215
24206
  return {
@@ -24220,110 +24211,228 @@ getPost$1.locally = (postId) => {
24220
24211
 
24221
24212
  /**
24222
24213
  * ```js
24223
- * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
24224
- * const dispose = onPostUpdatedLocal(post => {
24214
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
24215
+ * const dispose = onCommentDeleteLocal(comment => {
24225
24216
  * // ...
24226
24217
  * })
24227
24218
  * ```
24228
24219
  *
24229
- * Fired when a {@link Amity.InternalPost} has been updated
24220
+ * Fired when a {@link Amity.InternalComment} has been deleted
24230
24221
  *
24231
24222
  * @param callback The function to call when the event was fired
24232
24223
  * @returns an {@link Amity.Unsubscriber} function to stop listening
24233
24224
  *
24234
- * @category Post Events
24225
+ * @category Comment Events
24235
24226
  */
24236
- const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
24227
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
24237
24228
 
24238
24229
  /**
24239
24230
  * ```js
24240
- * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
24241
- * const dispose = onPostReactionAdded(post => {
24231
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
24232
+ * const dispose = onLocalCommentReactionAdded(comment => {
24242
24233
  * // ...
24243
24234
  * })
24244
24235
  * ```
24245
24236
  *
24246
- * Fired when a {@link Amity.InternalPost} has been reacted
24237
+ * Fired when a {@link Amity.InternalComment} has been reacted
24247
24238
  *
24248
24239
  * @param callback The function to call when the event was fired
24249
24240
  * @returns an {@link Amity.Unsubscriber} function to stop listening
24250
24241
  *
24251
- * @category Post Events
24242
+ * @category Comment Events
24252
24243
  */
24253
- const onLocalPostReactionAdded = (callback) => {
24244
+ const onLocalCommentReactionAdded = (callback) => {
24254
24245
  const client = getActiveClient();
24255
- const filter = ({ post }) => {
24246
+ const filter = ({ comment }) => {
24256
24247
  if (!client.cache) {
24257
- callback(post);
24248
+ callback(comment);
24258
24249
  }
24259
24250
  else {
24260
- upsertInCache(['post', 'get', post.postId], post);
24261
- callback(post);
24251
+ upsertInCache(['comment', 'get', comment.commentId], comment);
24252
+ callback(commentLinkedObject(comment));
24262
24253
  }
24263
24254
  };
24264
- return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
24255
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
24265
24256
  };
24266
24257
 
24267
24258
  /**
24268
24259
  * ```js
24269
- * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
24270
- * const dispose = onPostReactionRemoved(post => {
24260
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
24261
+ * const dispose = onLocalCommentReactionRemoved(comment => {
24271
24262
  * // ...
24272
24263
  * })
24273
24264
  * ```
24274
24265
  *
24275
- * Fired when a {@link Amity.InternalPost} has been reacted
24266
+ * Fired when a {@link Amity.InternalComment} has been reacted
24276
24267
  *
24277
24268
  * @param callback The function to call when the event was fired
24278
24269
  * @returns an {@link Amity.Unsubscriber} function to stop listening
24279
24270
  *
24280
- * @category Post Events
24271
+ * @category Comment Events
24281
24272
  */
24282
- const onLocalPostReactionRemoved = (callback) => {
24273
+ const onLocalCommentReactionRemoved = (callback) => {
24283
24274
  const client = getActiveClient();
24284
- const filter = ({ post }) => {
24275
+ const filter = ({ comment }) => {
24285
24276
  if (!client.cache) {
24286
- callback(post);
24277
+ callback(comment);
24287
24278
  }
24288
24279
  else {
24289
- upsertInCache(['post', 'get', post.postId], post);
24290
- callback(post);
24280
+ upsertInCache(['comment', 'get', comment.commentId], comment);
24281
+ callback(commentLinkedObject(comment));
24291
24282
  }
24292
24283
  };
24293
- return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
24284
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
24294
24285
  };
24295
24286
 
24287
+ /* begin_public_function
24288
+ id: comment.get
24289
+ */
24296
24290
  /**
24297
24291
  * ```js
24298
- * import { onLocalPostDeleted } from '@amityco/ts-sdk'
24299
- * const dispose = onLocalPostDeleted(post => {
24300
- * // ...
24301
- * })
24292
+ * import { CommentRepository } from '@amityco/ts-sdk';
24293
+ *
24294
+ * let comment;
24295
+ *
24296
+ * const unsub = CommentRepository.getComment(commentId, response => {
24297
+ * comment = response.data;
24298
+ * });
24302
24299
  * ```
24303
24300
  *
24304
- * Fired when a {@link Amity.InternalPost} has been deleted
24301
+ * Observe all mutation on a given {@link Amity.Comment}
24305
24302
  *
24306
- * @param callback The function to call when the event was fired
24307
- * @returns an {@link Amity.Unsubscriber} function to stop listening
24303
+ * @param commentId the ID of the comment to observe
24304
+ * @param callback the function to call when new data are available
24305
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
24308
24306
  *
24309
- * @category Post Events
24307
+ * @category Comment Live Object
24310
24308
  */
24311
- const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
24309
+ const getComment = (commentId, callback) => {
24310
+ return liveObject(commentId, callback, 'commentId', getComment$1, [
24311
+ onCommentDeleteLocal,
24312
+ onCommentDeleted,
24313
+ onCommentFlagged,
24314
+ onCommentReactionAdded,
24315
+ onCommentReactionRemoved,
24316
+ onCommentUnflagged,
24317
+ onCommentUpdated,
24318
+ onLocalCommentReactionAdded,
24319
+ onLocalCommentReactionRemoved,
24320
+ ]);
24321
+ };
24322
+ /* end_public_function */
24312
24323
 
24313
- class UserFeedLiveCollectionController extends LiveCollectionController {
24314
- constructor(query, callback) {
24315
- const queryStreamId = hash__default["default"](query);
24316
- const cacheKey = ['userFeed', 'collection', queryStreamId];
24317
- const paginationController = new UserFeedPaginationController(query);
24318
- super(paginationController, queryStreamId, cacheKey, callback);
24319
- this.query = query;
24320
- this.queryStreamController = new UserFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
24321
- this.callback = callback.bind(this);
24322
- this.loadPage({ initial: true });
24324
+ class CommentPaginationController extends PaginationController {
24325
+ async getRequest(queryParams, token) {
24326
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
24327
+ const baseOptions = {
24328
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
24329
+ };
24330
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
24331
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
24332
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
24333
+ });
24334
+ return queryResponse;
24323
24335
  }
24324
- setup() {
24325
- var _a;
24326
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24336
+ }
24337
+
24338
+ var EnumCommentActions;
24339
+ (function (EnumCommentActions) {
24340
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
24341
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
24342
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
24343
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
24344
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
24345
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
24346
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
24347
+ })(EnumCommentActions || (EnumCommentActions = {}));
24348
+
24349
+ class CommentQueryStreamController extends QueryStreamController {
24350
+ constructor(query, cacheKey, notifyChange, preparePayload) {
24351
+ super(query, cacheKey);
24352
+ this.notifyChange = notifyChange;
24353
+ this.preparePayload = preparePayload;
24354
+ }
24355
+ async saveToMainDB(response) {
24356
+ const processedPayload = await this.preparePayload(response);
24357
+ const client = getActiveClient();
24358
+ const cachedAt = client.cache && Date.now();
24359
+ if (client.cache) {
24360
+ ingestInCache(processedPayload, { cachedAt });
24361
+ }
24362
+ }
24363
+ appendToQueryStream(response, direction, refresh = false) {
24364
+ var _a, _b;
24365
+ if (refresh) {
24366
+ pushToCache(this.cacheKey, {
24367
+ data: response.comments.map(getResolver('comment')),
24368
+ });
24369
+ }
24370
+ else {
24371
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24372
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
24373
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
24374
+ }
24375
+ }
24376
+ reactor(action) {
24377
+ return (comment) => {
24378
+ var _a;
24379
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24380
+ if (this.query.referenceId !== comment.referenceId ||
24381
+ this.query.referenceType !== comment.referenceType ||
24382
+ !collection) {
24383
+ return;
24384
+ }
24385
+ if (this.query.parentId && this.query.parentId !== comment.parentId) {
24386
+ return;
24387
+ }
24388
+ if (!this.query.parentId && comment.parentId) {
24389
+ return;
24390
+ }
24391
+ if (action === EnumCommentActions.OnCommentCreated) {
24392
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
24393
+ }
24394
+ pushToCache(this.cacheKey, collection);
24395
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
24396
+ };
24397
+ }
24398
+ subscribeRTE(createSubscriber) {
24399
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
24400
+ }
24401
+ }
24402
+
24403
+ /**
24404
+ * ```js
24405
+ * import { onCommentCreated } from '@amityco/ts-sdk'
24406
+ * const dispose = onCommentCreated(comment => {
24407
+ * // ...
24408
+ * })
24409
+ * ```
24410
+ *
24411
+ * Fired when a {@link Amity.InternalComment} has been created
24412
+ *
24413
+ * @param callback The function to call when the event was fired
24414
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24415
+ *
24416
+ * @category Comment Events
24417
+ */
24418
+ const onCommentCreatedLocal = (callback) => {
24419
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
24420
+ };
24421
+
24422
+ class CommentLiveCollectionController extends LiveCollectionController {
24423
+ constructor(query, callback) {
24424
+ const queryStreamId = hash__default["default"](query);
24425
+ const cacheKey = ['comments', 'collection', queryStreamId];
24426
+ const paginationController = new CommentPaginationController(query);
24427
+ super(paginationController, queryStreamId, cacheKey, callback);
24428
+ this.query = query;
24429
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
24430
+ this.callback = callback.bind(this);
24431
+ this.loadPage({ initial: true });
24432
+ }
24433
+ setup() {
24434
+ var _a;
24435
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24327
24436
  if (!collection) {
24328
24437
  pushToCache(this.cacheKey, {
24329
24438
  data: [],
@@ -24339,45 +24448,17 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
24339
24448
  }
24340
24449
  startSubscription() {
24341
24450
  return this.queryStreamController.subscribeRTE([
24342
- { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
24343
- { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
24344
- { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
24345
- { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
24346
- { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
24347
- { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
24348
- { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
24349
- { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
24350
- { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24351
- { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24352
- { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
24353
- { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
24354
- { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
24355
- {
24356
- fn: convertEventPayload((callback) => {
24357
- return onCommentCreated(async (comment) => {
24358
- var _a;
24359
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24360
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24361
- return;
24362
- await getPost$1(comment.referenceId);
24363
- callback(comment);
24364
- });
24365
- }, 'referenceId', 'post'),
24366
- action: EnumPostActions.OnPostUpdated,
24367
- },
24368
- {
24369
- fn: convertEventPayload((callback) => {
24370
- return onCommentDeleted(async (comment) => {
24371
- var _a;
24372
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
24373
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
24374
- return;
24375
- await getPost$1(comment.referenceId);
24376
- callback(comment);
24377
- });
24378
- }, 'referenceId', 'post'),
24379
- action: EnumPostActions.OnPostUpdated,
24380
- },
24451
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
24452
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
24453
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
24454
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
24455
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
24456
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
24457
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
24458
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24459
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24460
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
24461
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
24381
24462
  ]);
24382
24463
  }
24383
24464
  notifyChange({ origin, loading, error }) {
@@ -24386,9 +24467,9 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
24386
24467
  if (!collection)
24387
24468
  return;
24388
24469
  const data = this.applyFilter((_b = collection.data
24389
- .map(id => pullFromCache(['post', 'get', id]))
24470
+ .map(id => pullFromCache(['comment', 'get', id]))
24390
24471
  .filter(isNonNullable)
24391
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
24472
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
24392
24473
  if (!this.shouldNotify(data) && origin === 'event')
24393
24474
  return;
24394
24475
  this.callback({
@@ -24400,560 +24481,204 @@ class UserFeedLiveCollectionController extends LiveCollectionController {
24400
24481
  });
24401
24482
  }
24402
24483
  applyFilter(data) {
24403
- var _a;
24404
- let posts = data;
24484
+ let comments = data;
24405
24485
  if (!this.query.includeDeleted) {
24406
- posts = filterByPropEquality(posts, 'isDeleted', false);
24486
+ comments = filterByPropEquality(comments, 'isDeleted', false);
24407
24487
  }
24408
- if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
24409
- posts = filterByPostDataTypes(posts, this.query.dataTypes);
24488
+ if (this.query.parentId) {
24489
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
24490
+ }
24491
+ if (typeof this.query.hasFlag === 'boolean') {
24492
+ if (this.query.hasFlag) {
24493
+ comments = comments.filter(comment => comment.hashFlag != null);
24494
+ }
24495
+ else {
24496
+ comments = comments.filter(comment => comment.hashFlag == null);
24497
+ }
24498
+ }
24499
+ if (this.query.dataTypes) {
24500
+ if (this.query.dataTypes.matchType === 'exact') {
24501
+ comments = comments.filter(comment => {
24502
+ var _a, _b;
24503
+ const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
24504
+ const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
24505
+ if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
24506
+ return false;
24507
+ }
24508
+ return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
24509
+ });
24510
+ }
24511
+ if (this.query.dataTypes.matchType === 'any') {
24512
+ comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
24513
+ }
24410
24514
  }
24411
24515
  switch (this.query.sortBy) {
24412
24516
  case 'firstCreated':
24413
- posts = posts.sort(sortByFirstCreated);
24517
+ comments = comments.sort(sortByFirstCreated);
24414
24518
  break;
24415
24519
  case 'lastCreated':
24416
24520
  default:
24417
- posts = posts.sort(sortByLastCreated);
24521
+ comments = comments.sort(sortByLastCreated);
24418
24522
  break;
24419
24523
  }
24420
- return posts;
24524
+ return comments;
24421
24525
  }
24422
24526
  }
24423
24527
 
24424
24528
  /* begin_public_function
24425
- id: feed.query.user_feed
24529
+ id: comment.query
24426
24530
  */
24427
24531
  /**
24428
24532
  * ```js
24429
- * import { FeedRepository } from '@amityco/ts-sdk'
24533
+ * import { getComments } from '@amityco/ts-sdk'
24430
24534
  *
24431
- * let posts = []
24432
- * const unsubscribe = FeedRepository.getUserFeed({
24433
- * userId: string,
24434
- * feedSources: ['user', 'community'],
24435
- * }, response => response => processResponse(response))
24535
+ * let comments = []
24536
+ * const unsub = getComments({
24537
+ * referenceType: Amity.InternalComment['referenceType'];
24538
+ * referenceId: Amity.InternalComment['referenceId'];
24539
+ * }, response => merge(comments, response.data))
24436
24540
  * ```
24437
24541
  *
24438
- * Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
24542
+ * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
24439
24543
  *
24440
- * @param params.userId the ID of the user
24441
- * @param params.feedSources the sources of the feed
24544
+ * @param referenceType the type of the target
24545
+ * @param referenceId the ID of the target
24442
24546
  * @param callback the function to call when new data are available
24443
- * @param config
24444
24547
  * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
24445
- *
24446
- * @category Posts Live Collection
24447
- */
24448
- const getUserFeed = (params, callback, config) => {
24449
- const { log, cache } = getActiveClient();
24450
- if (!cache) {
24451
- console.log(ENABLE_CACHE_MESSAGE);
24452
- }
24453
- const timestamp = Date.now();
24454
- log(`getUserFeed(tmpid: ${timestamp}) > listen`);
24455
- const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
24456
- const disposers = userFeedLiveCollection.startSubscription();
24457
- const cacheKey = userFeedLiveCollection.getCacheKey();
24458
- disposers.push(() => dropFromCache(cacheKey));
24459
- return () => {
24460
- log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
24461
- disposers.forEach(fn => fn());
24462
- };
24463
- };
24464
- /* end_public_function */
24465
-
24466
- var index$9 = /*#__PURE__*/Object.freeze({
24467
- __proto__: null,
24468
- queryGlobalFeed: queryGlobalFeed,
24469
- getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
24470
- getUserFeed: getUserFeed
24471
- });
24472
-
24473
- /* begin_public_function
24474
- id: post.get_by_ids
24475
- */
24476
- /**
24477
- * ```js
24478
- * import { getPostByIds } from '@amityco/ts-sdk'
24479
- * const { data: posts } = await getPostByIds(['foo', 'bar'])
24480
- * ```
24481
- *
24482
- * Fetches a collection of {@link Amity.Post} objects
24483
- *
24484
- * @param postIds the IDs of the {@link Amity.Post} to fetch
24485
- * @returns the associated collection of {@link Amity.Post} objects
24486
- *
24487
- * @category Post API
24488
- * @async
24489
- */
24490
- const getPostByIds = async (postIds) => {
24491
- const client = getActiveClient();
24492
- client.log('post/getPostByIds', postIds);
24493
- const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
24494
- let payload;
24495
- try {
24496
- // API-FIX: endpoint should not be /list, parameters should be querystring.
24497
- const response = await client.http.get(`/api/v3/posts/list`, {
24498
- params: { postIds: encodedPostIds },
24499
- });
24500
- payload = response.data;
24501
- }
24502
- catch (error) {
24503
- postIds.forEach(postId => {
24504
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24505
- pushToTombstone('post', postId);
24506
- }
24507
- });
24508
- throw error;
24509
- }
24510
- const data = prepareMembershipPayload(payload, 'communityUsers');
24511
- const cachedAt = client.cache && Date.now();
24512
- if (client.cache)
24513
- ingestInCache(data, { cachedAt });
24514
- return {
24515
- data: data.posts.map(LinkedObject.post),
24516
- cachedAt,
24517
- };
24518
- };
24519
- /* end_public_function */
24520
- /**
24521
- * ```js
24522
- * import { getPostByIds } from '@amityco/ts-sdk'
24523
- * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
24524
- * ```
24525
- *
24526
- * Fetches a collection of {@link Amity.Post} objects from cache
24527
- *
24528
- * @param postIds the IDs of the {@link Amity.Post} to fetch
24529
- * @returns the associated collection of {@link Amity.Post} objects
24530
- *
24531
- * @category Post API
24532
- */
24533
- getPostByIds.locally = (postIds) => {
24534
- var _a;
24535
- const client = getActiveClient();
24536
- client.log('post/getPostByIds.locally', postIds);
24537
- if (!client.cache)
24538
- return;
24539
- const cached = postIds
24540
- .map(postId => pullFromCache(['post', 'get', postId]))
24541
- .filter(Boolean);
24542
- const posts = cached.map(({ data }) => data);
24543
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
24544
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
24545
- return;
24546
- return {
24547
- data: posts.map(LinkedObject.post),
24548
- cachedAt: oldest.cachedAt,
24549
- };
24550
- };
24551
-
24552
- /* begin_public_function
24553
- id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
24554
- */
24555
- /**
24556
- * ```js
24557
- * import { PostRepository } from '@amityco/ts-sdk'
24558
- * const created = await PostRepository.createPost({
24559
- * targetType: 'user',
24560
- * targetId: 'foobar',
24561
- * data: { text: 'hello world' }
24562
- * }))
24563
- * ```
24564
- *
24565
- * Creates an {@link Amity.Post}
24566
- *
24567
- * @param bundle The data necessary to create a new {@link Amity.Post}
24568
- * @returns The newly created {@link Amity.Post}
24569
- *
24570
- * @category Post API
24571
- * @async
24572
- */
24573
- const createPost = async (bundle) => {
24574
- const client = getActiveClient();
24575
- client.log('post/createPost', bundle);
24576
- if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
24577
- // eslint-disable-next-line no-param-reassign
24578
- delete bundle.dataType;
24579
- }
24580
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
24581
- fireEvent('post.created', payload);
24582
- const data = preparePostPayload(payload);
24583
- const cachedAt = client.cache && Date.now();
24584
- if (client.cache)
24585
- ingestInCache(data, { cachedAt });
24586
- const { posts } = data;
24587
- return {
24588
- data: LinkedObject.post(posts[0]),
24589
- cachedAt,
24590
- };
24591
- };
24592
- /* end_public_function */
24593
-
24594
- /* begin_public_function
24595
- id: post.edit, post.edit.custom_post
24596
- */
24597
- /**
24598
- * ```js
24599
- * import { PostRepository } from '@amityco/ts-sdk'
24600
- * const updated = await PostRepository.editPost(postId, {
24601
- * data: { text: 'hello world' }
24602
- * })
24603
- * ```
24604
- *
24605
- * Updates an {@link Amity.Post}
24606
- *
24607
- * @param postId The ID of the {@link Amity.Post} to edit
24608
- * @param patch The patch data to apply
24609
- * @returns the updated {@link Amity.Post} object
24610
- *
24611
- * @category Post API
24612
- * @async
24613
- */
24614
- const editPost = async (postId, patch) => {
24615
- const client = getActiveClient();
24616
- client.log('user/editPost', patch);
24617
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
24618
- const data = prepareMembershipPayload(payload, 'communityUsers');
24619
- const cachedAt = client.cache && Date.now();
24620
- if (client.cache)
24621
- ingestInCache(data, { cachedAt });
24622
- fireEvent('local.post.updated', data);
24623
- const { posts } = data;
24624
- return {
24625
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
24626
- cachedAt,
24627
- };
24628
- };
24629
- /* end_public_function */
24630
-
24631
- /**
24632
- * ```js
24633
- * import { deletePost } from '@amityco/ts-sdk'
24634
- * const success = await deletePost('foobar')
24635
- * ```
24636
- *
24637
- * Deletes a {@link Amity.Post}
24638
- *
24639
- * @param postId The {@link Amity.Post} ID to delete
24640
- * @return A success boolean if the {@link Amity.Post} was deleted
24641
- *
24642
- * @private
24643
- * @async
24644
- */
24645
- const deletePost = async (postId, permanent = false) => {
24646
- var _a;
24647
- const client = getActiveClient();
24648
- const post = await getPost$2(postId);
24649
- await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
24650
- params: {
24651
- postId,
24652
- permanent,
24653
- },
24654
- });
24655
- // there is currently a limitation which doesn't allow us to fire event to tell that community
24656
- // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
24657
- // and so we cannot refetch the community or advertise on events. hopefully this should be solved
24658
- // later when realtime events covers that for us.
24659
- if (post.data.targetType === 'community') {
24660
- const community = await getCommunity$1(post.data.targetId);
24661
- const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
24662
- const communityUsers = communityUsersCache
24663
- .filter(({ key }) => {
24664
- // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
24665
- if (key[0] !== 'communityUsers')
24666
- return false;
24667
- if (key[1] !== 'get')
24668
- return false;
24669
- if (typeof key[2] === 'string')
24670
- return key[2].includes(community.data.communityId);
24671
- return false;
24672
- })
24673
- .map(({ data }) => data);
24674
- fireEvent('community.updated', {
24675
- communities: [community.data],
24676
- categories: [],
24677
- communityUsers,
24678
- feeds: [],
24679
- files: [],
24680
- users: [],
24681
- });
24682
- }
24683
- // to support hard deletion
24684
- const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
24685
- if (permanent) {
24686
- setTimeout(() => {
24687
- pushToTombstone('post', postId);
24688
- }, 0);
24689
- }
24690
- else {
24691
- upsertInCache(['post', 'get', postId], { isDeleted: true });
24692
- }
24693
- fireEvent('local.post.deleted', {
24694
- posts: [deleted],
24695
- categories: [],
24696
- comments: [],
24697
- communities: [],
24698
- communityUsers: [],
24699
- feeds: [],
24700
- files: [],
24701
- postChildren: [],
24702
- users: [],
24703
- videoStreamings: [],
24704
- });
24705
- return LinkedObject.post(deleted);
24706
- };
24707
-
24708
- /* begin_public_function
24709
- id: post.soft_delete
24710
- */
24711
- /**
24712
- * ```js
24713
- * import { PostRepository } from '@amityco/ts-sdk'
24714
- * const success = await PostRepository.softDeletePost('foobar')
24715
- * ```
24716
- *
24717
- * Soft deletes a {@link Amity.Post}
24718
- *
24719
- * @param postId The {@link Amity.Post} ID to soft delete
24720
- * @return A success boolean if the {@link Amity.Post} was deleted
24721
- *
24722
- * @category Post API
24723
- * @async
24724
- */
24725
- const softDeletePost = async (postId) => {
24726
- const client = getActiveClient();
24727
- client.log('post/softDeletePost', postId);
24728
- const softDeleted = await deletePost(postId, false);
24729
- return LinkedObject.post(softDeleted);
24730
- };
24731
- /* end_public_function */
24732
-
24733
- /* begin_public_function
24734
- id: post.hard_delete
24735
- */
24736
- /**
24737
- * ```js
24738
- * import { hardDeletePost } from '@amityco/ts-sdk'
24739
- * const success = await hardDeletePost('foobar')
24740
- * ```
24741
- *
24742
- * Hard deletes a {@link Amity.Post}
24743
- *
24744
- * @param postId The {@link Amity.Post} ID to be hard delete
24745
- * @return A success boolean if the {@link Amity.Post} was deleted
24746
- *
24747
- * @category Post API
24748
- * @async
24749
- */
24750
- const hardDeletePost = async (postId) => {
24751
- const client = getActiveClient();
24752
- client.log('post/hardDeletePost', postId);
24753
- const hardDeleted = await deletePost(postId, true);
24754
- return LinkedObject.post(hardDeleted);
24755
- };
24756
- /* end_public_function */
24757
-
24758
- /* begin_public_function
24759
- id: post.approve
24760
- */
24761
- /**
24762
- * ```js
24763
- * import { approvePost } from '@amityco/ts-sdk'
24764
- *
24765
- * const { data: post } = await approvePost('postId')
24766
- * ```
24767
- *
24768
- * Approves a {@link Amity.Post}
24769
- *
24770
- * @param postId The {@link Amity.Post} ID to be approved
24771
- * @return A {@link Amity.Post} that was approved
24772
- *
24773
- * @category Post API
24774
- * @async
24775
- */
24776
- const approvePost = async (postId) => {
24777
- const client = getActiveClient();
24778
- client.log('post/approvePost', postId);
24779
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
24780
- fireEvent('post.approved', payload);
24781
- // fire virtual event for community update
24782
- if (payload.posts[0].targetType === 'community') {
24783
- fireEvent('community.updated', payload);
24784
- }
24785
- const data = prepareMembershipPayload(payload, 'communityUsers');
24786
- const cachedAt = client.cache && Date.now();
24787
- if (client.cache)
24788
- ingestInCache(data, { cachedAt });
24789
- return {
24790
- data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
24791
- cachedAt,
24792
- };
24793
- };
24794
- /* end_public_function */
24795
-
24796
- /* begin_public_function
24797
- id: post.decline
24798
- */
24799
- /**
24800
- * ```js
24801
- * import { declinePost } from '@amityco/ts-sdk'
24802
- *
24803
- * const {data: post} = await declinePost('postId')
24804
- * ```
24805
- *
24806
- * Declines a {@link Amity.Post}
24807
- *
24808
- * @param postId The {@link Amity.Post} ID to be declined
24809
- * @return A {@link Amity.Post} that was declined
24810
- *
24811
- * @category Post API
24812
- * @async
24813
- */
24814
- const declinePost = async (postId) => {
24815
- const client = getActiveClient();
24816
- client.log('post/declinePost', postId);
24817
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
24818
- // fire virtual event
24819
- if (payload.posts[0].targetType === 'community') {
24820
- fireEvent('community.updated', payload);
24548
+ *
24549
+ * @category Comments Live Collection
24550
+ */
24551
+ const getComments = (params, callback, config) => {
24552
+ const { log, cache } = getActiveClient();
24553
+ if (!cache) {
24554
+ console.log('For using Live Collection feature you need to enable Cache!');
24821
24555
  }
24822
- fireEvent('post.declined', payload);
24823
- const data = prepareMembershipPayload(payload, 'communityUsers');
24824
- const cachedAt = client.cache && Date.now();
24825
- if (client.cache)
24826
- ingestInCache(data, { cachedAt });
24827
- return {
24828
- data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
24829
- cachedAt,
24556
+ const timestamp = Date.now();
24557
+ log(`getComments(tmpid: ${timestamp}) > listen`);
24558
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
24559
+ const disposers = commentsLiveCollection.startSubscription();
24560
+ const cacheKey = commentsLiveCollection.getCacheKey();
24561
+ disposers.push(() => dropFromCache(cacheKey));
24562
+ return () => {
24563
+ log(`getComments(tmpid: ${timestamp}) > dispose`);
24564
+ disposers.forEach(fn => fn());
24830
24565
  };
24831
24566
  };
24832
24567
  /* end_public_function */
24833
24568
 
24834
- /* begin_public_function
24835
- id: post.flag
24836
- */
24569
+ var index$9 = /*#__PURE__*/Object.freeze({
24570
+ __proto__: null,
24571
+ getCommentByIds: getCommentByIds,
24572
+ createComment: createComment,
24573
+ updateComment: updateComment,
24574
+ deleteComment: deleteComment,
24575
+ softDeleteComment: softDeleteComment,
24576
+ hardDeleteComment: hardDeleteComment,
24577
+ flagComment: flagComment,
24578
+ unflagComment: unflagComment,
24579
+ isCommentFlaggedByMe: isCommentFlaggedByMe,
24580
+ onCommentCreated: onCommentCreated,
24581
+ onCommentUpdated: onCommentUpdated,
24582
+ onCommentDeleted: onCommentDeleted,
24583
+ onCommentFlagged: onCommentFlagged,
24584
+ onCommentUnflagged: onCommentUnflagged,
24585
+ onCommentReactionAdded: onCommentReactionAdded,
24586
+ onCommentReactionRemoved: onCommentReactionRemoved,
24587
+ getComment: getComment,
24588
+ getComments: getComments
24589
+ });
24590
+
24837
24591
  /**
24838
24592
  * ```js
24839
- * import { PostRepository } from '@amityco/ts-sdk'
24840
- * const flagged = await PostRepository.flagPost(postId, reason)
24593
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
24594
+ * const dispose = onPostUpdatedLocal(post => {
24595
+ * // ...
24596
+ * })
24841
24597
  * ```
24842
24598
  *
24843
- * @param postId of the post to flag
24844
- * @param reason the reason to flag the post
24845
- * @returns a boolean
24599
+ * Fired when a {@link Amity.InternalPost} has been updated
24846
24600
  *
24847
- * @category Post API
24848
- * @async
24849
- * */
24850
- const flagPost = async (postId, reason) => {
24851
- const client = getActiveClient();
24852
- client.log('post/flagPost', postId);
24853
- const isPredefinedReason = reason &&
24854
- Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
24855
- const body = {
24856
- reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
24857
- detail: reason && !isPredefinedReason ? reason : '',
24858
- };
24859
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
24860
- if (client.cache) {
24861
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
24862
- }
24863
- fireEvent('post.flagged', payload);
24864
- return !!payload;
24865
- };
24866
- /* end_public_function */
24601
+ * @param callback The function to call when the event was fired
24602
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24603
+ *
24604
+ * @category Post Events
24605
+ */
24606
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
24867
24607
 
24868
- /* begin_public_function
24869
- id: post.unflag
24870
- */
24871
24608
  /**
24872
24609
  * ```js
24873
- * import { PostRepository } from '@amityco/ts-sdk'
24874
- * const unflagged = await PostRepository.unflagPost(postId)
24610
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
24611
+ * const dispose = onPostReactionAdded(post => {
24612
+ * // ...
24613
+ * })
24875
24614
  * ```
24876
24615
  *
24877
- * @param postId of the post to unflag
24878
- * @returns the unflag post result
24616
+ * Fired when a {@link Amity.InternalPost} has been reacted
24879
24617
  *
24880
- * @category Post API
24881
- * @async
24882
- * */
24883
- const unflagPost = async (postId) => {
24618
+ * @param callback The function to call when the event was fired
24619
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24620
+ *
24621
+ * @category Post Events
24622
+ */
24623
+ const onLocalPostReactionAdded = (callback) => {
24884
24624
  const client = getActiveClient();
24885
- client.log('post/unflagPost', postId);
24886
- const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
24887
- if (client.cache) {
24888
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
24889
- }
24890
- fireEvent('post.unflagged', payload);
24891
- return !!payload;
24625
+ const filter = ({ post }) => {
24626
+ if (!client.cache) {
24627
+ callback(post);
24628
+ }
24629
+ else {
24630
+ upsertInCache(['post', 'get', post.postId], post);
24631
+ callback(post);
24632
+ }
24633
+ };
24634
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
24892
24635
  };
24893
- /* end_public_function */
24894
24636
 
24895
- /* begin_public_function
24896
- id: post.check_flag_by_me
24897
- */
24898
24637
  /**
24899
24638
  * ```js
24900
- * import { PostRepository } from '@amityco/ts-sdk'
24901
- * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
24639
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
24640
+ * const dispose = onPostReactionRemoved(post => {
24641
+ * // ...
24642
+ * })
24902
24643
  * ```
24903
24644
  *
24904
- * @param postId of the post to check if flagged by current user
24905
- * @returns `true` if the post is flagged by me, `false` if doesn't.
24645
+ * Fired when a {@link Amity.InternalPost} has been reacted
24906
24646
  *
24907
- * @category Post API
24908
- * @async
24909
- * */
24910
- const isPostFlaggedByMe = async (postId) => {
24647
+ * @param callback The function to call when the event was fired
24648
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24649
+ *
24650
+ * @category Post Events
24651
+ */
24652
+ const onLocalPostReactionRemoved = (callback) => {
24911
24653
  const client = getActiveClient();
24912
- client.log('post/isPostFlaggedByMe', postId);
24913
- const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
24914
- return result;
24654
+ const filter = ({ post }) => {
24655
+ if (!client.cache) {
24656
+ callback(post);
24657
+ }
24658
+ else {
24659
+ upsertInCache(['post', 'get', post.postId], post);
24660
+ callback(post);
24661
+ }
24662
+ };
24663
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
24915
24664
  };
24916
- /* end_public_function */
24917
24665
 
24918
- /* begin_public_function
24919
- id: post.create.clip_post
24920
- */
24921
24666
  /**
24922
24667
  * ```js
24923
- * import { PostRepository } from '@amityco/ts-sdk'
24924
- * const created = await PostRepository.createClipPost({
24925
- * targetType: 'user',
24926
- * targetId: 'foobar',
24927
- * dataType: 'clip',
24928
- * data: { text: 'hello world' },
24929
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
24930
- * }))
24668
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk'
24669
+ * const dispose = onLocalPostDeleted(post => {
24670
+ * // ...
24671
+ * })
24931
24672
  * ```
24932
24673
  *
24933
- * Creates an {@link Amity.Post}
24674
+ * Fired when a {@link Amity.InternalPost} has been deleted
24934
24675
  *
24935
- * @param bundle The data necessary to create a new {@link Amity.Post}
24936
- * @returns The newly created {@link Amity.Post}
24676
+ * @param callback The function to call when the event was fired
24677
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
24937
24678
  *
24938
- * @category Post API
24939
- * @async
24679
+ * @category Post Events
24940
24680
  */
24941
- const createClipPost = async (bundle) => {
24942
- const client = getActiveClient();
24943
- client.log('post/createPost', bundle);
24944
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
24945
- fireEvent('post.created', payload);
24946
- const data = prepareMembershipPayload(payload, 'communityUsers');
24947
- const cachedAt = client.cache && Date.now();
24948
- if (client.cache)
24949
- ingestInCache(data, { cachedAt });
24950
- const { posts } = data;
24951
- return {
24952
- data: LinkedObject.post(posts[0]),
24953
- cachedAt,
24954
- };
24955
- };
24956
- /* end_public_function */
24681
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
24957
24682
 
24958
24683
  /* begin_public_function
24959
24684
  id: post.get
@@ -24977,7 +24702,7 @@ const createClipPost = async (bundle) => {
24977
24702
  *
24978
24703
  * @category Post Live Object
24979
24704
  */
24980
- const getPost = (postId, callback) => {
24705
+ const getPost$1 = (postId, callback) => {
24981
24706
  const responder = (snapshot) => {
24982
24707
  const { data } = snapshot;
24983
24708
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
@@ -25066,6 +24791,19 @@ class PostPaginationController extends PaginationController {
25066
24791
  }
25067
24792
  }
25068
24793
 
24794
+ var EnumPostActions;
24795
+ (function (EnumPostActions) {
24796
+ EnumPostActions["OnPostCreated"] = "onPostCreated";
24797
+ EnumPostActions["OnPostUpdated"] = "onPostUpdated";
24798
+ EnumPostActions["OnPostDeleted"] = "onPostDeleted";
24799
+ EnumPostActions["OnPostFlagged"] = "onPostFlagged";
24800
+ EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
24801
+ EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
24802
+ EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
24803
+ EnumPostActions["OnPostApproved"] = "onPostApproved";
24804
+ EnumPostActions["OnPostDeclined"] = "onPostDeclined";
24805
+ })(EnumPostActions || (EnumPostActions = {}));
24806
+
25069
24807
  class PostQueryStreamController extends QueryStreamController {
25070
24808
  constructor(query, cacheKey, notifyChange, preparePayload) {
25071
24809
  super(query, cacheKey);
@@ -25131,6 +24869,47 @@ class PostQueryStreamController extends QueryStreamController {
25131
24869
  }
25132
24870
  }
25133
24871
 
24872
+ const getPost = async (postId) => {
24873
+ const client = getActiveClient();
24874
+ client.log('post/getPost', postId);
24875
+ isInTombstone('post', postId);
24876
+ let payload;
24877
+ try {
24878
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
24879
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
24880
+ payload = response.data;
24881
+ }
24882
+ catch (error) {
24883
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
24884
+ pushToTombstone('post', postId);
24885
+ }
24886
+ throw error;
24887
+ }
24888
+ const data = prepareMembershipPayload(payload, 'communityUsers');
24889
+ const cachedAt = client.cache && Date.now();
24890
+ if (client.cache)
24891
+ ingestInCache(data, { cachedAt });
24892
+ const { posts } = data;
24893
+ const result = posts.find(post => post.postId === postId);
24894
+ return {
24895
+ data: result,
24896
+ cachedAt,
24897
+ };
24898
+ };
24899
+ getPost.locally = (postId) => {
24900
+ const client = getActiveClient();
24901
+ client.log('post/getPost.locally', postId);
24902
+ if (!client.cache)
24903
+ return;
24904
+ const cached = pullFromCache(['post', 'get', postId]);
24905
+ if (!cached)
24906
+ return;
24907
+ return {
24908
+ data: cached.data,
24909
+ cachedAt: cached.cachedAt,
24910
+ };
24911
+ };
24912
+
25134
24913
  class PostLiveCollectionController extends LiveCollectionController {
25135
24914
  constructor(query, callback) {
25136
24915
  const queryStreamId = hash__default["default"](query);
@@ -25180,7 +24959,7 @@ class PostLiveCollectionController extends LiveCollectionController {
25180
24959
  const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25181
24960
  if (!currentCollection || currentCollection.data.includes(comment.referenceId))
25182
24961
  return;
25183
- await getPost$1(comment.referenceId);
24962
+ await getPost(comment.referenceId);
25184
24963
  callback(comment);
25185
24964
  });
25186
24965
  }, 'referenceId', 'post'),
@@ -25193,7 +24972,7 @@ class PostLiveCollectionController extends LiveCollectionController {
25193
24972
  const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25194
24973
  if (!currentCollection || currentCollection.data.includes(comment.referenceId))
25195
24974
  return;
25196
- await getPost$1(comment.referenceId);
24975
+ await getPost(comment.referenceId);
25197
24976
  callback(comment);
25198
24977
  });
25199
24978
  }, 'referenceId', 'post'),
@@ -25819,7 +25598,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
25819
25598
  onPostUnflagged: onPostUnflagged,
25820
25599
  onPostReactionAdded: onPostReactionAdded,
25821
25600
  onPostReactionRemoved: onPostReactionRemoved,
25822
- getPost: getPost,
25601
+ getPost: getPost$1,
25823
25602
  getPosts: getPosts,
25824
25603
  getPinnedPosts: getPinnedPosts,
25825
25604
  getGlobalPinnedPosts: getGlobalPinnedPosts,
@@ -26188,12 +25967,9 @@ const onStreamViewerUnbanned = (callback) => {
26188
25967
  const filter = async (payloads) => {
26189
25968
  var _a;
26190
25969
  // Get new stream object to restore stream watcherUrl in cache
26191
- await Promise.all(payloads.map(({ streamId }) => getStream(streamId)));
26192
- const stream = (_a = pullFromCache([
26193
- 'stream',
26194
- 'get',
26195
- payloads[0].streamId,
26196
- ])) === null || _a === void 0 ? void 0 : _a.data;
25970
+ const { list } = payloads;
25971
+ await Promise.all(list.map(({ streamId }) => getStream(streamId)));
25972
+ const stream = (_a = pullFromCache(['stream', 'get', list[0].streamId])) === null || _a === void 0 ? void 0 : _a.data;
26197
25973
  if (!stream)
26198
25974
  return;
26199
25975
  callback(stream);
@@ -29025,13 +28801,13 @@ exports.AdRepository = index$3;
29025
28801
  exports.CategoryRepository = index$b;
29026
28802
  exports.ChannelRepository = index$f;
29027
28803
  exports.Client = index$o;
29028
- exports.CommentRepository = index$a;
28804
+ exports.CommentRepository = index$9;
29029
28805
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
29030
28806
  exports.CommunityPostSettings = CommunityPostSettings;
29031
28807
  exports.CommunityRepository = index$c;
29032
28808
  exports.ContentFeedType = ContentFeedType;
29033
28809
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
29034
- exports.FeedRepository = index$9;
28810
+ exports.FeedRepository = index$a;
29035
28811
  exports.FileRepository = index$l;
29036
28812
  exports.FileType = FileType;
29037
28813
  exports.InvitationRepository = index$1;