@amityco/ts-sdk 7.8.0 → 7.8.1-5d16a58a.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 (56) hide show
  1. package/.env +26 -26
  2. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +31 -0
  3. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
  4. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js +21 -1
  5. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
  6. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +1 -0
  7. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
  8. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js +1 -0
  9. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
  10. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +14 -0
  11. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
  12. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js +129 -0
  13. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/LiveCollectionController.js.map +1 -0
  14. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
  15. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
  16. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js +15 -0
  17. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/PaginationController.js.map +1 -0
  18. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
  19. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
  20. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js +78 -0
  21. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed/QueryStreamController.js.map +1 -0
  22. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
  23. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
  24. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js +46 -0
  25. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getUserFeed.js.map +1 -0
  26. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +2 -0
  27. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +1 -0
  28. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +2 -0
  29. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +1 -0
  30. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
  31. package/dist/@types/domains/feed.d.ts +31 -0
  32. package/dist/@types/domains/feed.d.ts.map +1 -1
  33. package/dist/feedRepository/index.d.ts +1 -0
  34. package/dist/feedRepository/index.d.ts.map +1 -1
  35. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts +14 -0
  36. package/dist/feedRepository/observers/getUserFeed/LiveCollectionController.d.ts.map +1 -0
  37. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts +5 -0
  38. package/dist/feedRepository/observers/getUserFeed/PaginationController.d.ts.map +1 -0
  39. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts +15 -0
  40. package/dist/feedRepository/observers/getUserFeed/QueryStreamController.d.ts.map +1 -0
  41. package/dist/feedRepository/observers/getUserFeed.d.ts +23 -0
  42. package/dist/feedRepository/observers/getUserFeed.d.ts.map +1 -0
  43. package/dist/feedRepository/observers/index.d.ts +2 -0
  44. package/dist/feedRepository/observers/index.d.ts.map +1 -0
  45. package/dist/index.cjs.js +1297 -1060
  46. package/dist/index.esm.js +1296 -1059
  47. package/dist/index.umd.js +4 -4
  48. package/package.json +1 -1
  49. package/src/@types/domains/feed.ts +43 -0
  50. package/src/feedRepository/index.ts +1 -0
  51. package/src/feedRepository/observers/getUserFeed/LiveCollectionController.ts +192 -0
  52. package/src/feedRepository/observers/getUserFeed/PaginationController.ts +37 -0
  53. package/src/feedRepository/observers/getUserFeed/QueryStreamController.ts +119 -0
  54. package/src/feedRepository/observers/getUserFeed.ts +56 -0
  55. package/src/feedRepository/observers/index.ts +1 -0
  56. package/tsconfig.tsbuildinfo +1 -1
package/dist/index.esm.js CHANGED
@@ -39267,1010 +39267,1035 @@ getCustomRankingGlobalFeed.locally = (query) => {
39267
39267
  : undefined;
39268
39268
  };
39269
39269
 
39270
- var index$a = /*#__PURE__*/Object.freeze({
39271
- __proto__: null,
39272
- queryGlobalFeed: queryGlobalFeed,
39273
- getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
39274
- });
39270
+ class UserFeedPaginationController extends PaginationController {
39271
+ async getRequest(queryParams, token) {
39272
+ const { userId, feedSources, dataTypes, includeDeleted, matchingOnlyParentPost, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["userId", "feedSources", "dataTypes", "includeDeleted", "matchingOnlyParentPost", "limit"]);
39273
+ const options = token ? { token } : { limit };
39274
+ const { data: queryResponse } = await this.http.get(`/api/v4/user-feeds/${userId}`, {
39275
+ 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) }),
39276
+ });
39277
+ return queryResponse;
39278
+ }
39279
+ }
39280
+
39281
+ var EnumPostActions;
39282
+ (function (EnumPostActions) {
39283
+ EnumPostActions["OnPostCreated"] = "onPostCreated";
39284
+ EnumPostActions["OnPostUpdated"] = "onPostUpdated";
39285
+ EnumPostActions["OnPostDeleted"] = "onPostDeleted";
39286
+ EnumPostActions["OnPostFlagged"] = "onPostFlagged";
39287
+ EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
39288
+ EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
39289
+ EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
39290
+ EnumPostActions["OnPostApproved"] = "onPostApproved";
39291
+ EnumPostActions["OnPostDeclined"] = "onPostDeclined";
39292
+ })(EnumPostActions || (EnumPostActions = {}));
39293
+
39294
+ class UserFeedQueryStreamController extends QueryStreamController {
39295
+ constructor(query, cacheKey, notifyChange, preparePayload) {
39296
+ super(query, cacheKey);
39297
+ this.notifyChange = notifyChange;
39298
+ this.preparePayload = preparePayload;
39299
+ }
39300
+ async saveToMainDB(response) {
39301
+ const processedPayload = await this.preparePayload(response);
39302
+ const client = getActiveClient();
39303
+ const cachedAt = client.cache && Date.now();
39304
+ if (client.cache) {
39305
+ ingestInCache(processedPayload, { cachedAt });
39306
+ }
39307
+ }
39308
+ appendToQueryStream(response, direction, refresh = false) {
39309
+ var _a, _b;
39310
+ if (refresh) {
39311
+ pushToCache(this.cacheKey, {
39312
+ data: response.posts.map(getResolver('post')),
39313
+ });
39314
+ }
39315
+ else {
39316
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39317
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
39318
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
39319
+ }
39320
+ }
39321
+ reactor(action) {
39322
+ return (post) => {
39323
+ var _a, _b;
39324
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39325
+ if (!collection)
39326
+ return;
39327
+ // if the collection is parent post collection and
39328
+ // post is not included in the collection or post is child post
39329
+ if ((!this.query.dataTypes || this.query.dataTypes.length === 0) &&
39330
+ !collection.data.includes(post.parentPostId ? post.parentPostId : post.postId))
39331
+ return;
39332
+ if (action === EnumPostActions.OnPostDeleted) {
39333
+ collection.data = collection.data.filter(postId => postId !== post.postId);
39334
+ }
39335
+ if (post.parentPostId && post.isDeleted) {
39336
+ const parentPost = (_b = pullFromCache([
39337
+ 'post',
39338
+ 'get',
39339
+ post.parentPostId,
39340
+ ])) === null || _b === void 0 ? void 0 : _b.data;
39341
+ if (!parentPost)
39342
+ return;
39343
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
39344
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
39345
+ }
39346
+ if (action === EnumPostActions.OnPostDeclined) {
39347
+ collection.data = collection.data.filter(postId => postId !== post.postId);
39348
+ }
39349
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
39350
+ if (this.query.dataTypes &&
39351
+ this.query.dataTypes.length > 0 &&
39352
+ !this.query.dataTypes.includes(post.dataType)) {
39353
+ return;
39354
+ }
39355
+ collection.data = [...new Set([post.postId, ...collection.data])];
39356
+ }
39357
+ pushToCache(this.cacheKey, collection);
39358
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
39359
+ };
39360
+ }
39361
+ subscribeRTE(createSubscriber) {
39362
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
39363
+ }
39364
+ }
39275
39365
 
39276
39366
  /* begin_public_function
39277
- id: post.get_by_ids
39367
+ id: comment.get_by_ids
39278
39368
  */
39279
39369
  /**
39280
39370
  * ```js
39281
- * import { getPostByIds } from '@amityco/ts-sdk'
39282
- * const { data: posts } = await getPostByIds(['foo', 'bar'])
39371
+ * import { CommentRepository } from '@amityco/ts-sdk'
39372
+ * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39283
39373
  * ```
39284
39374
  *
39285
- * Fetches a collection of {@link Amity.Post} objects
39375
+ * Fetches a collection of {@link Amity.Comment} objects
39286
39376
  *
39287
- * @param postIds the IDs of the {@link Amity.Post} to fetch
39288
- * @returns the associated collection of {@link Amity.Post} objects
39377
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39378
+ * @returns the associated collection of {@link Amity.Comment} objects
39289
39379
  *
39290
- * @category Post API
39380
+ * @category Comment API
39291
39381
  * @async
39292
39382
  */
39293
- const getPostByIds = async (postIds) => {
39383
+ const getCommentByIds = async (commentIds) => {
39294
39384
  const client = getActiveClient();
39295
- client.log('post/getPostByIds', postIds);
39296
- const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
39297
- let payload;
39385
+ client.log('comment/getCommentByIds', commentIds);
39386
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39387
+ let data;
39298
39388
  try {
39299
39389
  // API-FIX: endpoint should not be /list, parameters should be querystring.
39300
- const response = await client.http.get(`/api/v3/posts/list`, {
39301
- params: { postIds: encodedPostIds },
39390
+ const response = await client.http.get(`/api/v3/comments/list`, {
39391
+ params: { commentIds: encodedCommentIds },
39302
39392
  });
39303
- payload = response.data;
39393
+ data = response.data;
39304
39394
  }
39305
39395
  catch (error) {
39306
- postIds.forEach(postId => {
39396
+ commentIds.forEach(commentId => {
39307
39397
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39308
- pushToTombstone('post', postId);
39398
+ pushToTombstone('comment', commentId);
39309
39399
  }
39310
39400
  });
39311
39401
  throw error;
39312
39402
  }
39313
- const data = prepareMembershipPayload(payload, 'communityUsers');
39314
39403
  const cachedAt = client.cache && Date.now();
39315
39404
  if (client.cache)
39316
39405
  ingestInCache(data, { cachedAt });
39317
39406
  return {
39318
- data: data.posts.map(LinkedObject.post),
39407
+ data: data.comments.map(comment => LinkedObject.comment(comment)),
39319
39408
  cachedAt,
39320
39409
  };
39321
39410
  };
39322
39411
  /* end_public_function */
39323
39412
  /**
39324
39413
  * ```js
39325
- * import { getPostByIds } from '@amityco/ts-sdk'
39326
- * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
39414
+ * import { getCommentByIds } from '@amityco/ts-sdk'
39415
+ * const comments = getCommentByIds.locally(['foo', 'bar'])
39327
39416
  * ```
39328
39417
  *
39329
- * Fetches a collection of {@link Amity.Post} objects from cache
39418
+ * Fetches a collection of {@link Amity.Comment} objects from cache
39330
39419
  *
39331
- * @param postIds the IDs of the {@link Amity.Post} to fetch
39332
- * @returns the associated collection of {@link Amity.Post} objects
39420
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39421
+ * @returns the associated collection of {@link Amity.Comment} objects
39333
39422
  *
39334
- * @category Post API
39423
+ * @category Comment API
39335
39424
  */
39336
- getPostByIds.locally = (postIds) => {
39425
+ getCommentByIds.locally = (commentIds) => {
39337
39426
  var _a;
39338
39427
  const client = getActiveClient();
39339
- client.log('post/getPostByIds.locally', postIds);
39428
+ client.log('comment/getCommentByIds.locally', commentIds);
39340
39429
  if (!client.cache)
39341
39430
  return;
39342
- const cached = postIds
39343
- .map(postId => pullFromCache(['post', 'get', postId]))
39431
+ const cached = commentIds
39432
+ .map(commentId => pullFromCache(['comment', 'get', commentId]))
39344
39433
  .filter(Boolean);
39345
- const posts = cached.map(({ data }) => data);
39434
+ const comments = cached.map(({ data }) => data);
39346
39435
  const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39347
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
39436
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39348
39437
  return;
39349
39438
  return {
39350
- data: posts.map(LinkedObject.post),
39439
+ data: comments.map(comment => LinkedObject.comment(comment)),
39351
39440
  cachedAt: oldest.cachedAt,
39352
39441
  };
39353
39442
  };
39354
39443
 
39355
39444
  /* begin_public_function
39356
- 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
39445
+ id: comment.create
39357
39446
  */
39358
39447
  /**
39359
39448
  * ```js
39360
- * import { PostRepository } from '@amityco/ts-sdk'
39361
- * const created = await PostRepository.createPost({
39362
- * targetType: 'user',
39363
- * targetId: 'foobar',
39364
- * data: { text: 'hello world' }
39365
- * }))
39449
+ * import { CommentRepository } from '@amityco/ts-sdk'
39450
+ * const newComment = await CommentRepository.createComment(bundle)
39366
39451
  * ```
39367
39452
  *
39368
- * Creates an {@link Amity.Post}
39453
+ * Creates an {@link Amity.Comment}
39369
39454
  *
39370
- * @param bundle The data necessary to create a new {@link Amity.Post}
39371
- * @returns The newly created {@link Amity.Post}
39455
+ * @param bundle The data necessary to create a new {@link Amity.Comment}
39456
+ * @returns The newly created {@link Amity.Comment}
39372
39457
  *
39373
- * @category Post API
39458
+ * @category Comment API
39374
39459
  * @async
39375
39460
  */
39376
- const createPost = async (bundle) => {
39461
+ const createComment = async (bundle) => {
39462
+ var _a;
39377
39463
  const client = getActiveClient();
39378
- client.log('post/createPost', bundle);
39379
- if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
39380
- // eslint-disable-next-line no-param-reassign
39381
- delete bundle.dataType;
39382
- }
39383
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39384
- fireEvent('post.created', payload);
39385
- const data = preparePostPayload(payload);
39464
+ client.log('comment/createComment', bundle);
39465
+ const { data } = await client.http.post('/api/v3/comments', bundle);
39466
+ const { comments } = data;
39467
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39468
+ if (comments.length === 0)
39469
+ throw new Error('Comment not created');
39386
39470
  const cachedAt = client.cache && Date.now();
39387
39471
  if (client.cache)
39388
39472
  ingestInCache(data, { cachedAt });
39389
- const { posts } = data;
39473
+ if (['post', 'content'].includes(bundle.referenceType)) {
39474
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39475
+ if (post) {
39476
+ post.commentsCount += 1;
39477
+ fireEvent('local.post.updated', {
39478
+ posts: [post],
39479
+ categories: [],
39480
+ comments: [],
39481
+ communities: [],
39482
+ communityUsers: data.communityUsers,
39483
+ feeds: [],
39484
+ files: data.files,
39485
+ postChildren: [],
39486
+ users: data.users,
39487
+ videoStreamings: [],
39488
+ });
39489
+ }
39490
+ }
39491
+ else if (bundle.referenceType === 'story') {
39492
+ const storyIndex = pullFromCache([
39493
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39494
+ bundle.referenceId,
39495
+ ]);
39496
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39497
+ const cacheStory = pullFromCache([
39498
+ "story" /* STORY_KEY_CACHE.STORY */,
39499
+ 'get',
39500
+ storyIndex.data,
39501
+ ]);
39502
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39503
+ fireEvent('story.updated', {
39504
+ stories: [
39505
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39506
+ ],
39507
+ categories: [],
39508
+ comments,
39509
+ communities: [],
39510
+ communityUsers: data.communityUsers,
39511
+ files: data.files,
39512
+ users: data.users,
39513
+ });
39514
+ }
39515
+ }
39516
+ }
39517
+ fireEvent('local.comment.created', data);
39390
39518
  return {
39391
- data: LinkedObject.post(posts[0]),
39519
+ data: LinkedObject.comment(comments[0]),
39392
39520
  cachedAt,
39393
39521
  };
39394
39522
  };
39395
39523
  /* end_public_function */
39396
39524
 
39397
39525
  /* begin_public_function
39398
- id: post.edit, post.edit.custom_post
39526
+ id: comment.update_comment
39399
39527
  */
39400
39528
  /**
39401
39529
  * ```js
39402
- * import { PostRepository } from '@amityco/ts-sdk'
39403
- * const updated = await PostRepository.editPost(postId, {
39530
+ * import { CommentRepository } from '@amityco/ts-sdk'
39531
+ * const updated = await CommentRepository.updateComment(commentId, {
39404
39532
  * data: { text: 'hello world' }
39405
39533
  * })
39406
39534
  * ```
39407
39535
  *
39408
- * Updates an {@link Amity.Post}
39536
+ * Updates an {@link Amity.Comment}
39409
39537
  *
39410
- * @param postId The ID of the {@link Amity.Post} to edit
39538
+ * @param commentId The ID of the {@link Amity.Comment} to edit
39411
39539
  * @param patch The patch data to apply
39412
- * @returns the updated {@link Amity.Post} object
39540
+ * @returns the updated {@link Amity.Comment} object
39413
39541
  *
39414
- * @category Post API
39542
+ * @category Comment API
39415
39543
  * @async
39416
39544
  */
39417
- const editPost = async (postId, patch) => {
39545
+ const updateComment = async (commentId, patch) => {
39418
39546
  const client = getActiveClient();
39419
- client.log('user/editPost', patch);
39420
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
39421
- const data = prepareMembershipPayload(payload, 'communityUsers');
39547
+ client.log('user/updateComment', patch);
39548
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
39422
39549
  const cachedAt = client.cache && Date.now();
39423
39550
  if (client.cache)
39424
39551
  ingestInCache(data, { cachedAt });
39425
- fireEvent('local.post.updated', data);
39426
- const { posts } = data;
39552
+ fireEvent('comment.updated', data);
39553
+ const { comments } = data;
39427
39554
  return {
39428
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
39555
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
39429
39556
  cachedAt,
39430
39557
  };
39431
39558
  };
39432
39559
  /* end_public_function */
39433
39560
 
39561
+ // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
39562
+ const applyMissingField = (rawData, isCreated = false) => {
39563
+ const { storyId, referenceId } = rawData;
39564
+ if (!isCreated) {
39565
+ if (referenceId)
39566
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
39567
+ }
39568
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
39569
+ };
39570
+ const convertRawStoryToInternal = (data, isCreated = false) => {
39571
+ const { stories } = data;
39572
+ const storiesData = stories.map(story => applyMissingField(story, isCreated));
39573
+ return Object.assign(Object.assign({}, data), { stories: storiesData });
39574
+ };
39575
+
39576
+ const getStoryByStoryId$1 = async (storyId) => {
39577
+ const client = getActiveClient();
39578
+ client.log('story/getStoryByStoryId', storyId);
39579
+ // Get story referenceId from cache
39580
+ const cacheReferenceId = pullFromCache([
39581
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39582
+ storyId,
39583
+ ]);
39584
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39585
+ const { data: referenceId } = cacheReferenceId;
39586
+ isInTombstone('story', referenceId);
39587
+ }
39588
+ let data;
39589
+ try {
39590
+ const response = await client.http.get(`/api/v4/stories/${storyId}`);
39591
+ data = convertRawStoryToInternal(response.data);
39592
+ }
39593
+ catch (error) {
39594
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39595
+ pushToTombstone('story', storyId);
39596
+ }
39597
+ throw error;
39598
+ }
39599
+ const cachedAt = client.cache && Date.now();
39600
+ if (client.cache) {
39601
+ ingestInCache(data, { cachedAt });
39602
+ }
39603
+ return {
39604
+ data: data.stories[0],
39605
+ cachedAt,
39606
+ };
39607
+ };
39608
+ getStoryByStoryId$1.locally = (storyId) => {
39609
+ const client = getActiveClient();
39610
+ client.log('story/getStorybyStoryId', storyId);
39611
+ // Get story referenceId from cache
39612
+ const cacheReferenceId = pullFromCache([
39613
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39614
+ storyId,
39615
+ ]);
39616
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39617
+ const { data: referenceId } = cacheReferenceId;
39618
+ isInTombstone('story', referenceId);
39619
+ }
39620
+ const cachedAt = client.cache && Date.now();
39621
+ const storyCache = pullFromCache(['story', 'get', storyId]);
39622
+ if (!storyCache)
39623
+ return;
39624
+ return {
39625
+ data: storyCache.data,
39626
+ cachedAt,
39627
+ };
39628
+ };
39629
+
39630
+ /* begin_public_function
39631
+ id: comment.soft_delete, comment.hard_delete
39632
+ */
39434
39633
  /**
39435
39634
  * ```js
39436
- * import { deletePost } from '@amityco/ts-sdk'
39437
- * const success = await deletePost('foobar')
39635
+ * import { CommentRepository } from '@amityco/ts-sdk'
39636
+ * const success = await CommentRepository.deleteComment('foobar')
39438
39637
  * ```
39439
39638
  *
39440
- * Deletes a {@link Amity.Post}
39639
+ * Deletes a {@link Amity.Comment}
39441
39640
  *
39442
- * @param postId The {@link Amity.Post} ID to delete
39443
- * @return A success boolean if the {@link Amity.Post} was deleted
39641
+ * @param commentId The {@link Amity.Comment} ID to delete
39642
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39444
39643
  *
39445
- * @private
39644
+ * @category Comment API
39446
39645
  * @async
39447
39646
  */
39448
- const deletePost = async (postId, permanent = false) => {
39647
+ const deleteComment = async (commentId, permanent = false) => {
39449
39648
  var _a;
39450
39649
  const client = getActiveClient();
39451
- const post = await getPost$2(postId);
39452
- await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
39650
+ const comment = await getComment$2(commentId);
39651
+ // API-FIX: This endpoint has not been implemented yet.
39652
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
39453
39653
  params: {
39454
- postId,
39654
+ commentId,
39455
39655
  permanent,
39456
39656
  },
39457
39657
  });
39458
- // there is currently a limitation which doesn't allow us to fire event to tell that community
39459
- // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
39460
- // and so we cannot refetch the community or advertise on events. hopefully this should be solved
39461
- // later when realtime events covers that for us.
39462
- if (post.data.targetType === 'community') {
39463
- const community = await getCommunity$1(post.data.targetId);
39464
- const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
39465
- const communityUsers = communityUsersCache
39466
- .filter(({ key }) => {
39467
- // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
39468
- if (key[0] !== 'communityUsers')
39469
- return false;
39470
- if (key[1] !== 'get')
39471
- return false;
39472
- if (typeof key[2] === 'string')
39473
- return key[2].includes(community.data.communityId);
39474
- return false;
39475
- })
39476
- .map(({ data }) => data);
39477
- fireEvent('community.updated', {
39478
- communities: [community.data],
39658
+ // to support hard deletion
39659
+ const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
39660
+ if (comment.data.referenceType === 'story') {
39661
+ const story = await getStoryByStoryId$1(comment.data.referenceId);
39662
+ fireEvent('local.story.updated', {
39663
+ stories: [story.data],
39479
39664
  categories: [],
39480
- communityUsers,
39481
- feeds: [],
39665
+ comments: [],
39666
+ communities: [],
39667
+ communityUsers: [],
39482
39668
  files: [],
39483
39669
  users: [],
39484
39670
  });
39485
39671
  }
39486
- // to support hard deletion
39487
- const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
39488
- if (permanent) {
39489
- setTimeout(() => {
39490
- pushToTombstone('post', postId);
39491
- }, 0);
39492
- }
39493
39672
  else {
39494
- upsertInCache(['post', 'get', postId], { isDeleted: true });
39673
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39674
+ if (post) {
39675
+ let removeCount;
39676
+ if (!deleted.parentId) {
39677
+ // NOTE: delete the parent comment will remove all children comments
39678
+ removeCount = deleted.childrenNumber + 1;
39679
+ }
39680
+ else
39681
+ removeCount = 1;
39682
+ post.commentsCount -= removeCount;
39683
+ fireEvent('local.post.updated', {
39684
+ posts: [post],
39685
+ categories: [],
39686
+ comments: [],
39687
+ communities: [],
39688
+ communityUsers: [],
39689
+ feeds: [],
39690
+ files: [],
39691
+ postChildren: [],
39692
+ users: [],
39693
+ videoStreamings: [],
39694
+ });
39695
+ }
39495
39696
  }
39496
- fireEvent('local.post.deleted', {
39497
- posts: [deleted],
39498
- categories: [],
39499
- comments: [],
39500
- communities: [],
39501
- communityUsers: [],
39502
- feeds: [],
39697
+ fireEvent('local.comment.deleted', {
39698
+ comments: [deleted],
39699
+ commentChildren: [],
39503
39700
  files: [],
39504
- postChildren: [],
39505
39701
  users: [],
39506
- videoStreamings: [],
39702
+ communityUsers: [],
39507
39703
  });
39508
- return LinkedObject.post(deleted);
39704
+ if (permanent) {
39705
+ scheduleTask(() => pushToTombstone('comment', commentId));
39706
+ }
39707
+ else {
39708
+ upsertInCache(['comment', 'get', commentId], { isDeleted: true });
39709
+ }
39710
+ return deleted;
39509
39711
  };
39712
+ /* end_public_function */
39510
39713
 
39511
39714
  /* begin_public_function
39512
- id: post.soft_delete
39715
+ id: comment.soft_delete
39513
39716
  */
39514
39717
  /**
39515
39718
  * ```js
39516
- * import { PostRepository } from '@amityco/ts-sdk'
39517
- * const success = await PostRepository.softDeletePost('foobar')
39719
+ * import { CommentRepository } from '@amityco/ts-sdk'
39720
+ * const success = await CommentRepository.softDeleteComment('foobar')
39518
39721
  * ```
39519
39722
  *
39520
- * Soft deletes a {@link Amity.Post}
39723
+ * Deletes a {@link Amity.Comment}
39521
39724
  *
39522
- * @param postId The {@link Amity.Post} ID to soft delete
39523
- * @return A success boolean if the {@link Amity.Post} was deleted
39725
+ * @param commentId The {@link Amity.Comment} ID to delete
39726
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39524
39727
  *
39525
- * @category Post API
39728
+ * @category Comment API
39526
39729
  * @async
39527
39730
  */
39528
- const softDeletePost = async (postId) => {
39731
+ const softDeleteComment = async (commentId) => {
39529
39732
  const client = getActiveClient();
39530
- client.log('post/softDeletePost', postId);
39531
- const softDeleted = await deletePost(postId, false);
39532
- return LinkedObject.post(softDeleted);
39733
+ client.log('comment/softDeleteComment', commentId);
39734
+ const softDeleted = deleteComment(commentId);
39735
+ return softDeleted;
39533
39736
  };
39534
39737
  /* end_public_function */
39535
39738
 
39536
39739
  /* begin_public_function
39537
- id: post.hard_delete
39740
+ id: comment.hard_delete
39538
39741
  */
39539
39742
  /**
39540
39743
  * ```js
39541
- * import { hardDeletePost } from '@amityco/ts-sdk'
39542
- * const success = await hardDeletePost('foobar')
39744
+ * import { CommentRepository } from '@amityco/ts-sdk'
39745
+ * const success = await CommentRepository.hardDeleteComment('foobar')
39543
39746
  * ```
39544
39747
  *
39545
- * Hard deletes a {@link Amity.Post}
39748
+ * Deletes a {@link Amity.Comment}
39546
39749
  *
39547
- * @param postId The {@link Amity.Post} ID to be hard delete
39548
- * @return A success boolean if the {@link Amity.Post} was deleted
39750
+ * @param commentId The {@link Amity.Comment} ID to delete
39751
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39549
39752
  *
39550
- * @category Post API
39753
+ * @category Comment API
39551
39754
  * @async
39552
39755
  */
39553
- const hardDeletePost = async (postId) => {
39756
+ const hardDeleteComment = async (commentId) => {
39554
39757
  const client = getActiveClient();
39555
- client.log('post/hardDeletePost', postId);
39556
- const hardDeleted = await deletePost(postId, true);
39557
- return LinkedObject.post(hardDeleted);
39758
+ client.log('comment/hardDeleteComment', commentId);
39759
+ const hardDeleted = deleteComment(commentId, true);
39760
+ return hardDeleted;
39558
39761
  };
39559
39762
  /* end_public_function */
39560
39763
 
39561
39764
  /* begin_public_function
39562
- id: post.approve
39765
+ id: comment.flag
39563
39766
  */
39564
39767
  /**
39565
39768
  * ```js
39566
- * import { approvePost } from '@amityco/ts-sdk'
39567
- *
39568
- * const { data: post } = await approvePost('postId')
39769
+ * import { CommentRepository } from '@amityco/ts-sdk'
39770
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
39569
39771
  * ```
39570
39772
  *
39571
- * Approves a {@link Amity.Post}
39572
- *
39573
- * @param postId The {@link Amity.Post} ID to be approved
39574
- * @return A {@link Amity.Post} that was approved
39773
+ * @param commentId The ID of the comment to flag
39774
+ * @param reason the reason to flag the comment
39775
+ * @returns the created report result
39575
39776
  *
39576
- * @category Post API
39777
+ * @category Comment API
39577
39778
  * @async
39578
- */
39579
- const approvePost = async (postId) => {
39779
+ * */
39780
+ const flagComment = async (commentId, reason) => {
39580
39781
  const client = getActiveClient();
39581
- client.log('post/approvePost', postId);
39582
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
39583
- fireEvent('post.approved', payload);
39584
- // fire virtual event for community update
39585
- if (payload.posts[0].targetType === 'community') {
39586
- fireEvent('community.updated', payload);
39587
- }
39588
- const data = prepareMembershipPayload(payload, 'communityUsers');
39589
- const cachedAt = client.cache && Date.now();
39590
- if (client.cache)
39591
- ingestInCache(data, { cachedAt });
39592
- return {
39593
- data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
39594
- cachedAt,
39595
- };
39596
- };
39597
- /* end_public_function */
39598
-
39599
- /* begin_public_function
39600
- id: post.decline
39601
- */
39602
- /**
39603
- * ```js
39604
- * import { declinePost } from '@amityco/ts-sdk'
39605
- *
39606
- * const {data: post} = await declinePost('postId')
39607
- * ```
39608
- *
39609
- * Declines a {@link Amity.Post}
39610
- *
39611
- * @param postId The {@link Amity.Post} ID to be declined
39612
- * @return A {@link Amity.Post} that was declined
39613
- *
39614
- * @category Post API
39615
- * @async
39616
- */
39617
- const declinePost = async (postId) => {
39618
- const client = getActiveClient();
39619
- client.log('post/declinePost', postId);
39620
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
39621
- // fire virtual event
39622
- if (payload.posts[0].targetType === 'community') {
39623
- fireEvent('community.updated', payload);
39624
- }
39625
- fireEvent('post.declined', payload);
39626
- const data = prepareMembershipPayload(payload, 'communityUsers');
39627
- const cachedAt = client.cache && Date.now();
39628
- if (client.cache)
39629
- ingestInCache(data, { cachedAt });
39630
- return {
39631
- data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
39632
- cachedAt,
39633
- };
39634
- };
39635
- /* end_public_function */
39636
-
39637
- /* begin_public_function
39638
- id: post.flag
39639
- */
39640
- /**
39641
- * ```js
39642
- * import { PostRepository } from '@amityco/ts-sdk'
39643
- * const flagged = await PostRepository.flagPost(postId, reason)
39644
- * ```
39645
- *
39646
- * @param postId of the post to flag
39647
- * @param reason the reason to flag the post
39648
- * @returns a boolean
39649
- *
39650
- * @category Post API
39651
- * @async
39652
- * */
39653
- const flagPost = async (postId, reason) => {
39654
- const client = getActiveClient();
39655
- client.log('post/flagPost', postId);
39782
+ client.log('comment/flagComment', commentId);
39656
39783
  const isPredefinedReason = reason &&
39657
39784
  Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
39658
39785
  const body = {
39659
39786
  reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
39660
39787
  detail: reason && !isPredefinedReason ? reason : '',
39661
39788
  };
39662
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
39789
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
39663
39790
  if (client.cache) {
39664
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39791
+ ingestInCache(payload);
39665
39792
  }
39666
- fireEvent('post.flagged', payload);
39793
+ fireEvent('comment.flagged', payload);
39667
39794
  return !!payload;
39668
39795
  };
39669
39796
  /* end_public_function */
39670
39797
 
39671
39798
  /* begin_public_function
39672
- id: post.unflag
39799
+ id: comment.unflag
39673
39800
  */
39674
39801
  /**
39675
39802
  * ```js
39676
- * import { PostRepository } from '@amityco/ts-sdk'
39677
- * const unflagged = await PostRepository.unflagPost(postId)
39803
+ * import { CommentRepository } from '@amityco/ts-sdk'
39804
+ * const unflagged = await CommentRepository.unflagComment('commentId')
39678
39805
  * ```
39679
39806
  *
39680
- * @param postId of the post to unflag
39681
- * @returns the unflag post result
39807
+ * @param commentId The ID of comment to unflag
39808
+ * @returns the unflagged result
39682
39809
  *
39683
- * @category Post API
39810
+ * @category Comment API
39684
39811
  * @async
39685
39812
  * */
39686
- const unflagPost = async (postId) => {
39813
+ const unflagComment = async (commentId) => {
39687
39814
  const client = getActiveClient();
39688
- client.log('post/unflagPost', postId);
39689
- const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
39815
+ client.log('comment/unflagComment', commentId);
39816
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
39690
39817
  if (client.cache) {
39691
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39818
+ ingestInCache(payload);
39692
39819
  }
39693
- fireEvent('post.unflagged', payload);
39820
+ fireEvent('comment.unflagged', payload);
39694
39821
  return !!payload;
39695
39822
  };
39696
39823
  /* end_public_function */
39697
39824
 
39698
39825
  /* begin_public_function
39699
- id: post.check_flag_by_me
39826
+ id: comment.check_flag_by_me
39700
39827
  */
39701
39828
  /**
39702
39829
  * ```js
39703
- * import { PostRepository } from '@amityco/ts-sdk'
39704
- * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
39830
+ * import { CommentRepository } from '@amityco/ts-sdk'
39831
+ * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
39705
39832
  * ```
39706
39833
  *
39707
- * @param postId of the post to check if flagged by current user
39708
- * @returns `true` if the post is flagged by me, `false` if doesn't.
39834
+ * @param commentId The ID of the comment to check if flagged by current user
39835
+ * @returns `true` if the comment is flagged by me, `false` if doesn't.
39709
39836
  *
39710
- * @category Post API
39837
+ * @category Comment API
39711
39838
  * @async
39712
39839
  * */
39713
- const isPostFlaggedByMe = async (postId) => {
39840
+ const isCommentFlaggedByMe = async (commentId) => {
39714
39841
  const client = getActiveClient();
39715
- client.log('post/isPostFlaggedByMe', postId);
39716
- const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
39842
+ client.log('comment/isCommentFlaggedByMe', commentId);
39843
+ const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
39717
39844
  return result;
39718
39845
  };
39719
39846
  /* end_public_function */
39720
39847
 
39721
- /* begin_public_function
39722
- id: post.create.clip_post
39723
- */
39724
- /**
39725
- * ```js
39726
- * import { PostRepository } from '@amityco/ts-sdk'
39727
- * const created = await PostRepository.createClipPost({
39728
- * targetType: 'user',
39729
- * targetId: 'foobar',
39730
- * dataType: 'clip',
39731
- * data: { text: 'hello world' },
39732
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
39733
- * }))
39734
- * ```
39735
- *
39736
- * Creates an {@link Amity.Post}
39737
- *
39738
- * @param bundle The data necessary to create a new {@link Amity.Post}
39739
- * @returns The newly created {@link Amity.Post}
39740
- *
39741
- * @category Post API
39742
- * @async
39743
- */
39744
- const createClipPost = async (bundle) => {
39745
- const client = getActiveClient();
39746
- client.log('post/createPost', bundle);
39747
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39748
- fireEvent('post.created', payload);
39749
- const data = prepareMembershipPayload(payload, 'communityUsers');
39750
- const cachedAt = client.cache && Date.now();
39751
- if (client.cache)
39752
- ingestInCache(data, { cachedAt });
39753
- const { posts } = data;
39754
- return {
39755
- data: LinkedObject.post(posts[0]),
39756
- cachedAt,
39757
- };
39758
- };
39759
- /* end_public_function */
39760
-
39761
- /* begin_public_function
39762
- id: comment.get_by_ids
39763
- */
39764
- /**
39765
- * ```js
39766
- * import { CommentRepository } from '@amityco/ts-sdk'
39767
- * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39768
- * ```
39769
- *
39770
- * Fetches a collection of {@link Amity.Comment} objects
39771
- *
39772
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39773
- * @returns the associated collection of {@link Amity.Comment} objects
39774
- *
39775
- * @category Comment API
39776
- * @async
39777
- */
39778
- const getCommentByIds = async (commentIds) => {
39848
+ const getComment$1 = async (commentId) => {
39779
39849
  const client = getActiveClient();
39780
- client.log('comment/getCommentByIds', commentIds);
39781
- const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39850
+ client.log('comment/getComment', commentId);
39851
+ isInTombstone('comment', commentId);
39782
39852
  let data;
39783
39853
  try {
39784
39854
  // API-FIX: endpoint should not be /list, parameters should be querystring.
39785
- const response = await client.http.get(`/api/v3/comments/list`, {
39786
- params: { commentIds: encodedCommentIds },
39787
- });
39855
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
39788
39856
  data = response.data;
39789
39857
  }
39790
39858
  catch (error) {
39791
- commentIds.forEach(commentId => {
39792
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39793
- pushToTombstone('comment', commentId);
39794
- }
39795
- });
39859
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39860
+ pushToTombstone('comment', commentId);
39861
+ }
39796
39862
  throw error;
39797
39863
  }
39798
39864
  const cachedAt = client.cache && Date.now();
39799
39865
  if (client.cache)
39800
39866
  ingestInCache(data, { cachedAt });
39867
+ const { comments } = data;
39801
39868
  return {
39802
- data: data.comments.map(comment => LinkedObject.comment(comment)),
39869
+ data: comments.find(comment => comment.commentId === commentId),
39803
39870
  cachedAt,
39804
39871
  };
39805
39872
  };
39806
- /* end_public_function */
39807
- /**
39808
- * ```js
39809
- * import { getCommentByIds } from '@amityco/ts-sdk'
39810
- * const comments = getCommentByIds.locally(['foo', 'bar'])
39811
- * ```
39812
- *
39813
- * Fetches a collection of {@link Amity.Comment} objects from cache
39814
- *
39815
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39816
- * @returns the associated collection of {@link Amity.Comment} objects
39817
- *
39818
- * @category Comment API
39819
- */
39820
- getCommentByIds.locally = (commentIds) => {
39821
- var _a;
39873
+ getComment$1.locally = (commentId) => {
39822
39874
  const client = getActiveClient();
39823
- client.log('comment/getCommentByIds.locally', commentIds);
39875
+ client.log('comment/getComment.locally', commentId);
39824
39876
  if (!client.cache)
39825
39877
  return;
39826
- const cached = commentIds
39827
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
39828
- .filter(Boolean);
39829
- const comments = cached.map(({ data }) => data);
39830
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39831
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39878
+ const cached = pullFromCache(['comment', 'get', commentId]);
39879
+ if (!cached)
39832
39880
  return;
39833
39881
  return {
39834
- data: comments.map(comment => LinkedObject.comment(comment)),
39835
- cachedAt: oldest.cachedAt,
39882
+ data: cached.data,
39883
+ cachedAt: cached.cachedAt,
39836
39884
  };
39837
39885
  };
39838
39886
 
39839
- /* begin_public_function
39840
- id: comment.create
39841
- */
39842
39887
  /**
39843
39888
  * ```js
39844
- * import { CommentRepository } from '@amityco/ts-sdk'
39845
- * const newComment = await CommentRepository.createComment(bundle)
39889
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
39890
+ * const dispose = onCommentDeleteLocal(comment => {
39891
+ * // ...
39892
+ * })
39846
39893
  * ```
39847
39894
  *
39848
- * Creates an {@link Amity.Comment}
39895
+ * Fired when a {@link Amity.InternalComment} has been deleted
39849
39896
  *
39850
- * @param bundle The data necessary to create a new {@link Amity.Comment}
39851
- * @returns The newly created {@link Amity.Comment}
39897
+ * @param callback The function to call when the event was fired
39898
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39852
39899
  *
39853
- * @category Comment API
39854
- * @async
39900
+ * @category Comment Events
39855
39901
  */
39856
- const createComment = async (bundle) => {
39857
- var _a;
39902
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
39903
+
39904
+ /**
39905
+ * ```js
39906
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
39907
+ * const dispose = onLocalCommentReactionAdded(comment => {
39908
+ * // ...
39909
+ * })
39910
+ * ```
39911
+ *
39912
+ * Fired when a {@link Amity.InternalComment} has been reacted
39913
+ *
39914
+ * @param callback The function to call when the event was fired
39915
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39916
+ *
39917
+ * @category Comment Events
39918
+ */
39919
+ const onLocalCommentReactionAdded = (callback) => {
39858
39920
  const client = getActiveClient();
39859
- client.log('comment/createComment', bundle);
39860
- const { data } = await client.http.post('/api/v3/comments', bundle);
39861
- const { comments } = data;
39862
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39863
- if (comments.length === 0)
39864
- throw new Error('Comment not created');
39865
- const cachedAt = client.cache && Date.now();
39866
- if (client.cache)
39867
- ingestInCache(data, { cachedAt });
39868
- if (['post', 'content'].includes(bundle.referenceType)) {
39869
- const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39870
- if (post) {
39871
- post.commentsCount += 1;
39872
- fireEvent('local.post.updated', {
39873
- posts: [post],
39874
- categories: [],
39875
- comments: [],
39876
- communities: [],
39877
- communityUsers: data.communityUsers,
39878
- feeds: [],
39879
- files: data.files,
39880
- postChildren: [],
39881
- users: data.users,
39882
- videoStreamings: [],
39883
- });
39921
+ const filter = ({ comment }) => {
39922
+ if (!client.cache) {
39923
+ callback(comment);
39884
39924
  }
39885
- }
39886
- else if (bundle.referenceType === 'story') {
39887
- const storyIndex = pullFromCache([
39888
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39889
- bundle.referenceId,
39890
- ]);
39891
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39892
- const cacheStory = pullFromCache([
39893
- "story" /* STORY_KEY_CACHE.STORY */,
39894
- 'get',
39895
- storyIndex.data,
39896
- ]);
39897
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39898
- fireEvent('story.updated', {
39899
- stories: [
39900
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39901
- ],
39902
- categories: [],
39903
- comments,
39904
- communities: [],
39905
- communityUsers: data.communityUsers,
39906
- files: data.files,
39907
- users: data.users,
39908
- });
39909
- }
39925
+ else {
39926
+ upsertInCache(['comment', 'get', comment.commentId], comment);
39927
+ callback(commentLinkedObject(comment));
39910
39928
  }
39911
- }
39912
- fireEvent('local.comment.created', data);
39913
- return {
39914
- data: LinkedObject.comment(comments[0]),
39915
- cachedAt,
39916
39929
  };
39930
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
39917
39931
  };
39918
- /* end_public_function */
39919
39932
 
39920
- /* begin_public_function
39921
- id: comment.update_comment
39922
- */
39923
39933
  /**
39924
39934
  * ```js
39925
- * import { CommentRepository } from '@amityco/ts-sdk'
39926
- * const updated = await CommentRepository.updateComment(commentId, {
39927
- * data: { text: 'hello world' }
39935
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
39936
+ * const dispose = onLocalCommentReactionRemoved(comment => {
39937
+ * // ...
39928
39938
  * })
39929
39939
  * ```
39930
39940
  *
39931
- * Updates an {@link Amity.Comment}
39941
+ * Fired when a {@link Amity.InternalComment} has been reacted
39932
39942
  *
39933
- * @param commentId The ID of the {@link Amity.Comment} to edit
39934
- * @param patch The patch data to apply
39935
- * @returns the updated {@link Amity.Comment} object
39943
+ * @param callback The function to call when the event was fired
39944
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39936
39945
  *
39937
- * @category Comment API
39938
- * @async
39946
+ * @category Comment Events
39939
39947
  */
39940
- const updateComment = async (commentId, patch) => {
39941
- const client = getActiveClient();
39942
- client.log('user/updateComment', patch);
39943
- const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
39944
- const cachedAt = client.cache && Date.now();
39945
- if (client.cache)
39946
- ingestInCache(data, { cachedAt });
39947
- fireEvent('comment.updated', data);
39948
- const { comments } = data;
39949
- return {
39950
- data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
39951
- cachedAt,
39952
- };
39953
- };
39954
- /* end_public_function */
39955
-
39956
- // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
39957
- const applyMissingField = (rawData, isCreated = false) => {
39958
- const { storyId, referenceId } = rawData;
39959
- if (!isCreated) {
39960
- if (referenceId)
39961
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
39962
- }
39963
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
39964
- };
39965
- const convertRawStoryToInternal = (data, isCreated = false) => {
39966
- const { stories } = data;
39967
- const storiesData = stories.map(story => applyMissingField(story, isCreated));
39968
- return Object.assign(Object.assign({}, data), { stories: storiesData });
39969
- };
39970
-
39971
- const getStoryByStoryId$1 = async (storyId) => {
39948
+ const onLocalCommentReactionRemoved = (callback) => {
39972
39949
  const client = getActiveClient();
39973
- client.log('story/getStoryByStoryId', storyId);
39974
- // Get story referenceId from cache
39975
- const cacheReferenceId = pullFromCache([
39976
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39977
- storyId,
39978
- ]);
39979
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39980
- const { data: referenceId } = cacheReferenceId;
39981
- isInTombstone('story', referenceId);
39982
- }
39983
- let data;
39984
- try {
39985
- const response = await client.http.get(`/api/v4/stories/${storyId}`);
39986
- data = convertRawStoryToInternal(response.data);
39987
- }
39988
- catch (error) {
39989
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39990
- pushToTombstone('story', storyId);
39950
+ const filter = ({ comment }) => {
39951
+ if (!client.cache) {
39952
+ callback(comment);
39953
+ }
39954
+ else {
39955
+ upsertInCache(['comment', 'get', comment.commentId], comment);
39956
+ callback(commentLinkedObject(comment));
39991
39957
  }
39992
- throw error;
39993
- }
39994
- const cachedAt = client.cache && Date.now();
39995
- if (client.cache) {
39996
- ingestInCache(data, { cachedAt });
39997
- }
39998
- return {
39999
- data: data.stories[0],
40000
- cachedAt,
40001
- };
40002
- };
40003
- getStoryByStoryId$1.locally = (storyId) => {
40004
- const client = getActiveClient();
40005
- client.log('story/getStorybyStoryId', storyId);
40006
- // Get story referenceId from cache
40007
- const cacheReferenceId = pullFromCache([
40008
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
40009
- storyId,
40010
- ]);
40011
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
40012
- const { data: referenceId } = cacheReferenceId;
40013
- isInTombstone('story', referenceId);
40014
- }
40015
- const cachedAt = client.cache && Date.now();
40016
- const storyCache = pullFromCache(['story', 'get', storyId]);
40017
- if (!storyCache)
40018
- return;
40019
- return {
40020
- data: storyCache.data,
40021
- cachedAt,
40022
39958
  };
39959
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
40023
39960
  };
40024
39961
 
40025
39962
  /* begin_public_function
40026
- id: comment.soft_delete, comment.hard_delete
39963
+ id: comment.get
40027
39964
  */
40028
39965
  /**
40029
39966
  * ```js
40030
- * import { CommentRepository } from '@amityco/ts-sdk'
40031
- * const success = await CommentRepository.deleteComment('foobar')
39967
+ * import { CommentRepository } from '@amityco/ts-sdk';
39968
+ *
39969
+ * let comment;
39970
+ *
39971
+ * const unsub = CommentRepository.getComment(commentId, response => {
39972
+ * comment = response.data;
39973
+ * });
40032
39974
  * ```
40033
39975
  *
40034
- * Deletes a {@link Amity.Comment}
39976
+ * Observe all mutation on a given {@link Amity.Comment}
40035
39977
  *
40036
- * @param commentId The {@link Amity.Comment} ID to delete
40037
- * @return A success boolean if the {@link Amity.Comment} was deleted
39978
+ * @param commentId the ID of the comment to observe
39979
+ * @param callback the function to call when new data are available
39980
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
40038
39981
  *
40039
- * @category Comment API
40040
- * @async
39982
+ * @category Comment Live Object
40041
39983
  */
40042
- const deleteComment = async (commentId, permanent = false) => {
40043
- var _a;
40044
- const client = getActiveClient();
40045
- const comment = await getComment$2(commentId);
40046
- // API-FIX: This endpoint has not been implemented yet.
40047
- await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
40048
- params: {
40049
- commentId,
40050
- permanent,
40051
- },
40052
- });
40053
- // to support hard deletion
40054
- const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
40055
- if (comment.data.referenceType === 'story') {
40056
- const story = await getStoryByStoryId$1(comment.data.referenceId);
40057
- fireEvent('local.story.updated', {
40058
- stories: [story.data],
40059
- categories: [],
40060
- comments: [],
40061
- communities: [],
40062
- communityUsers: [],
40063
- files: [],
40064
- users: [],
39984
+ const getComment = (commentId, callback) => {
39985
+ return liveObject(commentId, callback, 'commentId', getComment$1, [
39986
+ onCommentDeleteLocal,
39987
+ onCommentDeleted,
39988
+ onCommentFlagged,
39989
+ onCommentReactionAdded,
39990
+ onCommentReactionRemoved,
39991
+ onCommentUnflagged,
39992
+ onCommentUpdated,
39993
+ onLocalCommentReactionAdded,
39994
+ onLocalCommentReactionRemoved,
39995
+ ]);
39996
+ };
39997
+ /* end_public_function */
39998
+
39999
+ class CommentPaginationController extends PaginationController {
40000
+ async getRequest(queryParams, token) {
40001
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
40002
+ const baseOptions = {
40003
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
40004
+ };
40005
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
40006
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
40007
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
40065
40008
  });
40009
+ return queryResponse;
40066
40010
  }
40067
- else {
40068
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
40069
- if (post) {
40070
- let removeCount;
40071
- if (!deleted.parentId) {
40072
- // NOTE: delete the parent comment will remove all children comments
40073
- removeCount = deleted.childrenNumber + 1;
40074
- }
40075
- else
40076
- removeCount = 1;
40077
- post.commentsCount -= removeCount;
40078
- fireEvent('local.post.updated', {
40079
- posts: [post],
40080
- categories: [],
40081
- comments: [],
40082
- communities: [],
40083
- communityUsers: [],
40084
- feeds: [],
40085
- files: [],
40086
- postChildren: [],
40087
- users: [],
40088
- videoStreamings: [],
40011
+ }
40012
+
40013
+ var EnumCommentActions;
40014
+ (function (EnumCommentActions) {
40015
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
40016
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
40017
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
40018
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
40019
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
40020
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
40021
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
40022
+ })(EnumCommentActions || (EnumCommentActions = {}));
40023
+
40024
+ class CommentQueryStreamController extends QueryStreamController {
40025
+ constructor(query, cacheKey, notifyChange, preparePayload) {
40026
+ super(query, cacheKey);
40027
+ this.notifyChange = notifyChange;
40028
+ this.preparePayload = preparePayload;
40029
+ }
40030
+ async saveToMainDB(response) {
40031
+ const processedPayload = await this.preparePayload(response);
40032
+ const client = getActiveClient();
40033
+ const cachedAt = client.cache && Date.now();
40034
+ if (client.cache) {
40035
+ ingestInCache(processedPayload, { cachedAt });
40036
+ }
40037
+ }
40038
+ appendToQueryStream(response, direction, refresh = false) {
40039
+ var _a, _b;
40040
+ if (refresh) {
40041
+ pushToCache(this.cacheKey, {
40042
+ data: response.comments.map(getResolver('comment')),
40089
40043
  });
40090
40044
  }
40045
+ else {
40046
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40047
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40048
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40049
+ }
40091
40050
  }
40092
- fireEvent('local.comment.deleted', {
40093
- comments: [deleted],
40094
- commentChildren: [],
40095
- files: [],
40096
- users: [],
40097
- communityUsers: [],
40098
- });
40099
- if (permanent) {
40100
- scheduleTask(() => pushToTombstone('comment', commentId));
40051
+ reactor(action) {
40052
+ return (comment) => {
40053
+ var _a;
40054
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40055
+ if (this.query.referenceId !== comment.referenceId ||
40056
+ this.query.referenceType !== comment.referenceType ||
40057
+ !collection) {
40058
+ return;
40059
+ }
40060
+ if (this.query.parentId && this.query.parentId !== comment.parentId) {
40061
+ return;
40062
+ }
40063
+ if (!this.query.parentId && comment.parentId) {
40064
+ return;
40065
+ }
40066
+ if (action === EnumCommentActions.OnCommentCreated) {
40067
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
40068
+ }
40069
+ pushToCache(this.cacheKey, collection);
40070
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40071
+ };
40101
40072
  }
40102
- else {
40103
- upsertInCache(['comment', 'get', commentId], { isDeleted: true });
40073
+ subscribeRTE(createSubscriber) {
40074
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40104
40075
  }
40105
- return deleted;
40106
- };
40107
- /* end_public_function */
40076
+ }
40108
40077
 
40109
- /* begin_public_function
40110
- id: comment.soft_delete
40111
- */
40112
40078
  /**
40113
40079
  * ```js
40114
- * import { CommentRepository } from '@amityco/ts-sdk'
40115
- * const success = await CommentRepository.softDeleteComment('foobar')
40080
+ * import { onCommentCreated } from '@amityco/ts-sdk'
40081
+ * const dispose = onCommentCreated(comment => {
40082
+ * // ...
40083
+ * })
40116
40084
  * ```
40117
40085
  *
40118
- * Deletes a {@link Amity.Comment}
40086
+ * Fired when a {@link Amity.InternalComment} has been created
40119
40087
  *
40120
- * @param commentId The {@link Amity.Comment} ID to delete
40121
- * @return A success boolean if the {@link Amity.Comment} was deleted
40088
+ * @param callback The function to call when the event was fired
40089
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40122
40090
  *
40123
- * @category Comment API
40124
- * @async
40091
+ * @category Comment Events
40125
40092
  */
40126
- const softDeleteComment = async (commentId) => {
40127
- const client = getActiveClient();
40128
- client.log('comment/softDeleteComment', commentId);
40129
- const softDeleted = deleteComment(commentId);
40130
- return softDeleted;
40093
+ const onCommentCreatedLocal = (callback) => {
40094
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
40131
40095
  };
40132
- /* end_public_function */
40096
+
40097
+ class CommentLiveCollectionController extends LiveCollectionController {
40098
+ constructor(query, callback) {
40099
+ const queryStreamId = hash(query);
40100
+ const cacheKey = ['comments', 'collection', queryStreamId];
40101
+ const paginationController = new CommentPaginationController(query);
40102
+ super(paginationController, queryStreamId, cacheKey, callback);
40103
+ this.query = query;
40104
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40105
+ this.callback = callback.bind(this);
40106
+ this.loadPage({ initial: true });
40107
+ }
40108
+ setup() {
40109
+ var _a;
40110
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40111
+ if (!collection) {
40112
+ pushToCache(this.cacheKey, {
40113
+ data: [],
40114
+ params: {},
40115
+ });
40116
+ }
40117
+ }
40118
+ async persistModel(queryPayload) {
40119
+ await this.queryStreamController.saveToMainDB(queryPayload);
40120
+ }
40121
+ persistQueryStream({ response, direction, refresh, }) {
40122
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40123
+ }
40124
+ startSubscription() {
40125
+ return this.queryStreamController.subscribeRTE([
40126
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40127
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40128
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40129
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40130
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40131
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40132
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40133
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40134
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40135
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40136
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40137
+ ]);
40138
+ }
40139
+ notifyChange({ origin, loading, error }) {
40140
+ var _a, _b;
40141
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40142
+ if (!collection)
40143
+ return;
40144
+ const data = this.applyFilter((_b = collection.data
40145
+ .map(id => pullFromCache(['comment', 'get', id]))
40146
+ .filter(isNonNullable)
40147
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40148
+ if (!this.shouldNotify(data) && origin === 'event')
40149
+ return;
40150
+ this.callback({
40151
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40152
+ data,
40153
+ hasNextPage: !!this.paginationController.getNextToken(),
40154
+ loading,
40155
+ error,
40156
+ });
40157
+ }
40158
+ applyFilter(data) {
40159
+ let comments = data;
40160
+ if (!this.query.includeDeleted) {
40161
+ comments = filterByPropEquality(comments, 'isDeleted', false);
40162
+ }
40163
+ if (this.query.parentId) {
40164
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
40165
+ }
40166
+ if (typeof this.query.hasFlag === 'boolean') {
40167
+ if (this.query.hasFlag) {
40168
+ comments = comments.filter(comment => comment.hashFlag != null);
40169
+ }
40170
+ else {
40171
+ comments = comments.filter(comment => comment.hashFlag == null);
40172
+ }
40173
+ }
40174
+ if (this.query.dataTypes) {
40175
+ if (this.query.dataTypes.matchType === 'exact') {
40176
+ comments = comments.filter(comment => {
40177
+ var _a, _b;
40178
+ const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40179
+ const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40180
+ if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40181
+ return false;
40182
+ }
40183
+ return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
40184
+ });
40185
+ }
40186
+ if (this.query.dataTypes.matchType === 'any') {
40187
+ 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); }); });
40188
+ }
40189
+ }
40190
+ switch (this.query.sortBy) {
40191
+ case 'firstCreated':
40192
+ comments = comments.sort(sortByFirstCreated);
40193
+ break;
40194
+ case 'lastCreated':
40195
+ default:
40196
+ comments = comments.sort(sortByLastCreated);
40197
+ break;
40198
+ }
40199
+ return comments;
40200
+ }
40201
+ }
40133
40202
 
40134
40203
  /* begin_public_function
40135
- id: comment.hard_delete
40204
+ id: comment.query
40136
40205
  */
40137
40206
  /**
40138
40207
  * ```js
40139
- * import { CommentRepository } from '@amityco/ts-sdk'
40140
- * const success = await CommentRepository.hardDeleteComment('foobar')
40208
+ * import { getComments } from '@amityco/ts-sdk'
40209
+ *
40210
+ * let comments = []
40211
+ * const unsub = getComments({
40212
+ * referenceType: Amity.InternalComment['referenceType'];
40213
+ * referenceId: Amity.InternalComment['referenceId'];
40214
+ * }, response => merge(comments, response.data))
40141
40215
  * ```
40142
40216
  *
40143
- * Deletes a {@link Amity.Comment}
40217
+ * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
40144
40218
  *
40145
- * @param commentId The {@link Amity.Comment} ID to delete
40146
- * @return A success boolean if the {@link Amity.Comment} was deleted
40219
+ * @param referenceType the type of the target
40220
+ * @param referenceId the ID of the target
40221
+ * @param callback the function to call when new data are available
40222
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40147
40223
  *
40148
- * @category Comment API
40149
- * @async
40224
+ * @category Comments Live Collection
40150
40225
  */
40151
- const hardDeleteComment = async (commentId) => {
40152
- const client = getActiveClient();
40153
- client.log('comment/hardDeleteComment', commentId);
40154
- const hardDeleted = deleteComment(commentId, true);
40155
- return hardDeleted;
40226
+ const getComments = (params, callback, config) => {
40227
+ const { log, cache } = getActiveClient();
40228
+ if (!cache) {
40229
+ console.log('For using Live Collection feature you need to enable Cache!');
40230
+ }
40231
+ const timestamp = Date.now();
40232
+ log(`getComments(tmpid: ${timestamp}) > listen`);
40233
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40234
+ const disposers = commentsLiveCollection.startSubscription();
40235
+ const cacheKey = commentsLiveCollection.getCacheKey();
40236
+ disposers.push(() => dropFromCache(cacheKey));
40237
+ return () => {
40238
+ log(`getComments(tmpid: ${timestamp}) > dispose`);
40239
+ disposers.forEach(fn => fn());
40240
+ };
40156
40241
  };
40157
40242
  /* end_public_function */
40158
40243
 
40159
- /* begin_public_function
40160
- id: comment.flag
40161
- */
40162
- /**
40163
- * ```js
40164
- * import { CommentRepository } from '@amityco/ts-sdk'
40165
- * const flagged = await CommentRepository.flagComment(commentId, reason)
40166
- * ```
40167
- *
40168
- * @param commentId The ID of the comment to flag
40169
- * @param reason the reason to flag the comment
40170
- * @returns the created report result
40171
- *
40172
- * @category Comment API
40173
- * @async
40174
- * */
40175
- const flagComment = async (commentId, reason) => {
40176
- const client = getActiveClient();
40177
- client.log('comment/flagComment', commentId);
40178
- const isPredefinedReason = reason &&
40179
- Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
40180
- const body = {
40181
- reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
40182
- detail: reason && !isPredefinedReason ? reason : '',
40183
- };
40184
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
40185
- if (client.cache) {
40186
- ingestInCache(payload);
40187
- }
40188
- fireEvent('comment.flagged', payload);
40189
- return !!payload;
40190
- };
40191
- /* end_public_function */
40192
-
40193
- /* begin_public_function
40194
- id: comment.unflag
40195
- */
40196
- /**
40197
- * ```js
40198
- * import { CommentRepository } from '@amityco/ts-sdk'
40199
- * const unflagged = await CommentRepository.unflagComment('commentId')
40200
- * ```
40201
- *
40202
- * @param commentId The ID of comment to unflag
40203
- * @returns the unflagged result
40204
- *
40205
- * @category Comment API
40206
- * @async
40207
- * */
40208
- const unflagComment = async (commentId) => {
40209
- const client = getActiveClient();
40210
- client.log('comment/unflagComment', commentId);
40211
- const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
40212
- if (client.cache) {
40213
- ingestInCache(payload);
40214
- }
40215
- fireEvent('comment.unflagged', payload);
40216
- return !!payload;
40217
- };
40218
- /* end_public_function */
40219
-
40220
- /* begin_public_function
40221
- id: comment.check_flag_by_me
40222
- */
40223
- /**
40224
- * ```js
40225
- * import { CommentRepository } from '@amityco/ts-sdk'
40226
- * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
40227
- * ```
40228
- *
40229
- * @param commentId The ID of the comment to check if flagged by current user
40230
- * @returns `true` if the comment is flagged by me, `false` if doesn't.
40231
- *
40232
- * @category Comment API
40233
- * @async
40234
- * */
40235
- const isCommentFlaggedByMe = async (commentId) => {
40236
- const client = getActiveClient();
40237
- client.log('comment/isCommentFlaggedByMe', commentId);
40238
- const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
40239
- return result;
40240
- };
40241
- /* end_public_function */
40244
+ var index$a = /*#__PURE__*/Object.freeze({
40245
+ __proto__: null,
40246
+ getCommentByIds: getCommentByIds,
40247
+ createComment: createComment,
40248
+ updateComment: updateComment,
40249
+ deleteComment: deleteComment,
40250
+ softDeleteComment: softDeleteComment,
40251
+ hardDeleteComment: hardDeleteComment,
40252
+ flagComment: flagComment,
40253
+ unflagComment: unflagComment,
40254
+ isCommentFlaggedByMe: isCommentFlaggedByMe,
40255
+ onCommentCreated: onCommentCreated,
40256
+ onCommentUpdated: onCommentUpdated,
40257
+ onCommentDeleted: onCommentDeleted,
40258
+ onCommentFlagged: onCommentFlagged,
40259
+ onCommentUnflagged: onCommentUnflagged,
40260
+ onCommentReactionAdded: onCommentReactionAdded,
40261
+ onCommentReactionRemoved: onCommentReactionRemoved,
40262
+ getComment: getComment,
40263
+ getComments: getComments
40264
+ });
40242
40265
 
40243
- const getComment$1 = async (commentId) => {
40266
+ const getPost$1 = async (postId) => {
40244
40267
  const client = getActiveClient();
40245
- client.log('comment/getComment', commentId);
40246
- isInTombstone('comment', commentId);
40247
- let data;
40268
+ client.log('post/getPost', postId);
40269
+ isInTombstone('post', postId);
40270
+ let payload;
40248
40271
  try {
40249
40272
  // API-FIX: endpoint should not be /list, parameters should be querystring.
40250
- const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
40251
- data = response.data;
40273
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
40274
+ payload = response.data;
40252
40275
  }
40253
40276
  catch (error) {
40254
40277
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40255
- pushToTombstone('comment', commentId);
40278
+ pushToTombstone('post', postId);
40256
40279
  }
40257
40280
  throw error;
40258
40281
  }
40282
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40259
40283
  const cachedAt = client.cache && Date.now();
40260
40284
  if (client.cache)
40261
40285
  ingestInCache(data, { cachedAt });
40262
- const { comments } = data;
40286
+ const { posts } = data;
40287
+ const result = posts.find(post => post.postId === postId);
40263
40288
  return {
40264
- data: comments.find(comment => comment.commentId === commentId),
40289
+ data: result,
40265
40290
  cachedAt,
40266
40291
  };
40267
40292
  };
40268
- getComment$1.locally = (commentId) => {
40293
+ getPost$1.locally = (postId) => {
40269
40294
  const client = getActiveClient();
40270
- client.log('comment/getComment.locally', commentId);
40295
+ client.log('post/getPost.locally', postId);
40271
40296
  if (!client.cache)
40272
40297
  return;
40273
- const cached = pullFromCache(['comment', 'get', commentId]);
40298
+ const cached = pullFromCache(['post', 'get', postId]);
40274
40299
  if (!cached)
40275
40300
  return;
40276
40301
  return {
@@ -40281,224 +40306,106 @@ getComment$1.locally = (commentId) => {
40281
40306
 
40282
40307
  /**
40283
40308
  * ```js
40284
- * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
40285
- * const dispose = onCommentDeleteLocal(comment => {
40309
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40310
+ * const dispose = onPostUpdatedLocal(post => {
40286
40311
  * // ...
40287
40312
  * })
40288
40313
  * ```
40289
40314
  *
40290
- * Fired when a {@link Amity.InternalComment} has been deleted
40315
+ * Fired when a {@link Amity.InternalPost} has been updated
40291
40316
  *
40292
40317
  * @param callback The function to call when the event was fired
40293
40318
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40294
40319
  *
40295
- * @category Comment Events
40320
+ * @category Post Events
40296
40321
  */
40297
- const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
40322
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
40298
40323
 
40299
40324
  /**
40300
40325
  * ```js
40301
- * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
40302
- * const dispose = onLocalCommentReactionAdded(comment => {
40326
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40327
+ * const dispose = onPostReactionAdded(post => {
40303
40328
  * // ...
40304
40329
  * })
40305
40330
  * ```
40306
40331
  *
40307
- * Fired when a {@link Amity.InternalComment} has been reacted
40332
+ * Fired when a {@link Amity.InternalPost} has been reacted
40308
40333
  *
40309
40334
  * @param callback The function to call when the event was fired
40310
40335
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40311
40336
  *
40312
- * @category Comment Events
40337
+ * @category Post Events
40313
40338
  */
40314
- const onLocalCommentReactionAdded = (callback) => {
40339
+ const onLocalPostReactionAdded = (callback) => {
40315
40340
  const client = getActiveClient();
40316
- const filter = ({ comment }) => {
40341
+ const filter = ({ post }) => {
40317
40342
  if (!client.cache) {
40318
- callback(comment);
40343
+ callback(post);
40319
40344
  }
40320
40345
  else {
40321
- upsertInCache(['comment', 'get', comment.commentId], comment);
40322
- callback(commentLinkedObject(comment));
40346
+ upsertInCache(['post', 'get', post.postId], post);
40347
+ callback(post);
40323
40348
  }
40324
40349
  };
40325
- return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
40350
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
40326
40351
  };
40327
40352
 
40328
40353
  /**
40329
40354
  * ```js
40330
- * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
40331
- * const dispose = onLocalCommentReactionRemoved(comment => {
40355
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40356
+ * const dispose = onPostReactionRemoved(post => {
40332
40357
  * // ...
40333
40358
  * })
40334
40359
  * ```
40335
40360
  *
40336
- * Fired when a {@link Amity.InternalComment} has been reacted
40361
+ * Fired when a {@link Amity.InternalPost} has been reacted
40337
40362
  *
40338
40363
  * @param callback The function to call when the event was fired
40339
40364
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40340
40365
  *
40341
- * @category Comment Events
40366
+ * @category Post Events
40342
40367
  */
40343
- const onLocalCommentReactionRemoved = (callback) => {
40368
+ const onLocalPostReactionRemoved = (callback) => {
40344
40369
  const client = getActiveClient();
40345
- const filter = ({ comment }) => {
40370
+ const filter = ({ post }) => {
40346
40371
  if (!client.cache) {
40347
- callback(comment);
40372
+ callback(post);
40348
40373
  }
40349
40374
  else {
40350
- upsertInCache(['comment', 'get', comment.commentId], comment);
40351
- callback(commentLinkedObject(comment));
40375
+ upsertInCache(['post', 'get', post.postId], post);
40376
+ callback(post);
40352
40377
  }
40353
40378
  };
40354
- return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
40379
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
40355
40380
  };
40356
40381
 
40357
- /* begin_public_function
40358
- id: comment.get
40359
- */
40360
40382
  /**
40361
40383
  * ```js
40362
- * import { CommentRepository } from '@amityco/ts-sdk';
40363
- *
40364
- * let comment;
40365
- *
40366
- * const unsub = CommentRepository.getComment(commentId, response => {
40367
- * comment = response.data;
40368
- * });
40384
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40385
+ * const dispose = onLocalPostDeleted(post => {
40386
+ * // ...
40387
+ * })
40369
40388
  * ```
40370
40389
  *
40371
- * Observe all mutation on a given {@link Amity.Comment}
40390
+ * Fired when a {@link Amity.InternalPost} has been deleted
40372
40391
  *
40373
- * @param commentId the ID of the comment to observe
40374
- * @param callback the function to call when new data are available
40375
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
40392
+ * @param callback The function to call when the event was fired
40393
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40376
40394
  *
40377
- * @category Comment Live Object
40395
+ * @category Post Events
40378
40396
  */
40379
- const getComment = (commentId, callback) => {
40380
- return liveObject(commentId, callback, 'commentId', getComment$1, [
40381
- onCommentDeleteLocal,
40382
- onCommentDeleted,
40383
- onCommentFlagged,
40384
- onCommentReactionAdded,
40385
- onCommentReactionRemoved,
40386
- onCommentUnflagged,
40387
- onCommentUpdated,
40388
- onLocalCommentReactionAdded,
40389
- onLocalCommentReactionRemoved,
40390
- ]);
40391
- };
40392
- /* end_public_function */
40393
-
40394
- class CommentPaginationController extends PaginationController {
40395
- async getRequest(queryParams, token) {
40396
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
40397
- const baseOptions = {
40398
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
40399
- };
40400
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
40401
- const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
40402
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
40403
- });
40404
- return queryResponse;
40405
- }
40406
- }
40407
-
40408
- var EnumCommentActions;
40409
- (function (EnumCommentActions) {
40410
- EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
40411
- EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
40412
- EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
40413
- EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
40414
- EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
40415
- EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
40416
- EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
40417
- })(EnumCommentActions || (EnumCommentActions = {}));
40397
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
40418
40398
 
40419
- class CommentQueryStreamController extends QueryStreamController {
40420
- constructor(query, cacheKey, notifyChange, preparePayload) {
40421
- super(query, cacheKey);
40422
- this.notifyChange = notifyChange;
40423
- this.preparePayload = preparePayload;
40424
- }
40425
- async saveToMainDB(response) {
40426
- const processedPayload = await this.preparePayload(response);
40427
- const client = getActiveClient();
40428
- const cachedAt = client.cache && Date.now();
40429
- if (client.cache) {
40430
- ingestInCache(processedPayload, { cachedAt });
40431
- }
40432
- }
40433
- appendToQueryStream(response, direction, refresh = false) {
40434
- var _a, _b;
40435
- if (refresh) {
40436
- pushToCache(this.cacheKey, {
40437
- data: response.comments.map(getResolver('comment')),
40438
- });
40439
- }
40440
- else {
40441
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40442
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40443
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40444
- }
40445
- }
40446
- reactor(action) {
40447
- return (comment) => {
40448
- var _a;
40449
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40450
- if (this.query.referenceId !== comment.referenceId ||
40451
- this.query.referenceType !== comment.referenceType ||
40452
- !collection) {
40453
- return;
40454
- }
40455
- if (this.query.parentId && this.query.parentId !== comment.parentId) {
40456
- return;
40457
- }
40458
- if (!this.query.parentId && comment.parentId) {
40459
- return;
40460
- }
40461
- if (action === EnumCommentActions.OnCommentCreated) {
40462
- collection.data = [...new Set([comment.commentId, ...collection.data])];
40463
- }
40464
- pushToCache(this.cacheKey, collection);
40465
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40466
- };
40467
- }
40468
- subscribeRTE(createSubscriber) {
40469
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40470
- }
40471
- }
40472
-
40473
- /**
40474
- * ```js
40475
- * import { onCommentCreated } from '@amityco/ts-sdk'
40476
- * const dispose = onCommentCreated(comment => {
40477
- * // ...
40478
- * })
40479
- * ```
40480
- *
40481
- * Fired when a {@link Amity.InternalComment} has been created
40482
- *
40483
- * @param callback The function to call when the event was fired
40484
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40485
- *
40486
- * @category Comment Events
40487
- */
40488
- const onCommentCreatedLocal = (callback) => {
40489
- return createLocalCommentEventSubscriber('local.comment.created', callback);
40490
- };
40491
-
40492
- class CommentLiveCollectionController extends LiveCollectionController {
40493
- constructor(query, callback) {
40494
- const queryStreamId = hash(query);
40495
- const cacheKey = ['comments', 'collection', queryStreamId];
40496
- const paginationController = new CommentPaginationController(query);
40497
- super(paginationController, queryStreamId, cacheKey, callback);
40498
- this.query = query;
40499
- this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40500
- this.callback = callback.bind(this);
40501
- this.loadPage({ initial: true });
40399
+ class UserFeedLiveCollectionController extends LiveCollectionController {
40400
+ constructor(query, callback) {
40401
+ const queryStreamId = hash(query);
40402
+ const cacheKey = ['userFeed', 'collection', queryStreamId];
40403
+ const paginationController = new UserFeedPaginationController(query);
40404
+ super(paginationController, queryStreamId, cacheKey, callback);
40405
+ this.query = query;
40406
+ this.queryStreamController = new UserFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
40407
+ this.callback = callback.bind(this);
40408
+ this.loadPage({ initial: true });
40502
40409
  }
40503
40410
  setup() {
40504
40411
  var _a;
@@ -40518,17 +40425,45 @@ class CommentLiveCollectionController extends LiveCollectionController {
40518
40425
  }
40519
40426
  startSubscription() {
40520
40427
  return this.queryStreamController.subscribeRTE([
40521
- { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40522
- { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40523
- { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40524
- { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40525
- { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40526
- { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40527
- { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40528
- { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40529
- { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40530
- { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40531
- { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40428
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
40429
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
40430
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
40431
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
40432
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
40433
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
40434
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
40435
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
40436
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40437
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40438
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40439
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40440
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
40441
+ {
40442
+ fn: convertEventPayload((callback) => {
40443
+ return onCommentCreated(async (comment) => {
40444
+ var _a;
40445
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40446
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
40447
+ return;
40448
+ await getPost$1(comment.referenceId);
40449
+ callback(comment);
40450
+ });
40451
+ }, 'referenceId', 'post'),
40452
+ action: EnumPostActions.OnPostUpdated,
40453
+ },
40454
+ {
40455
+ fn: convertEventPayload((callback) => {
40456
+ return onCommentDeleted(async (comment) => {
40457
+ var _a;
40458
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40459
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
40460
+ return;
40461
+ await getPost$1(comment.referenceId);
40462
+ callback(comment);
40463
+ });
40464
+ }, 'referenceId', 'post'),
40465
+ action: EnumPostActions.OnPostUpdated,
40466
+ },
40532
40467
  ]);
40533
40468
  }
40534
40469
  notifyChange({ origin, loading, error }) {
@@ -40537,9 +40472,9 @@ class CommentLiveCollectionController extends LiveCollectionController {
40537
40472
  if (!collection)
40538
40473
  return;
40539
40474
  const data = this.applyFilter((_b = collection.data
40540
- .map(id => pullFromCache(['comment', 'get', id]))
40475
+ .map(id => pullFromCache(['post', 'get', id]))
40541
40476
  .filter(isNonNullable)
40542
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40477
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
40543
40478
  if (!this.shouldNotify(data) && origin === 'event')
40544
40479
  return;
40545
40480
  this.callback({
@@ -40551,86 +40486,64 @@ class CommentLiveCollectionController extends LiveCollectionController {
40551
40486
  });
40552
40487
  }
40553
40488
  applyFilter(data) {
40554
- let comments = data;
40489
+ var _a;
40490
+ let posts = data;
40555
40491
  if (!this.query.includeDeleted) {
40556
- comments = filterByPropEquality(comments, 'isDeleted', false);
40557
- }
40558
- if (this.query.parentId) {
40559
- comments = comments.filter(comment => comment.parentId === this.query.parentId);
40560
- }
40561
- if (typeof this.query.hasFlag === 'boolean') {
40562
- if (this.query.hasFlag) {
40563
- comments = comments.filter(comment => comment.hashFlag != null);
40564
- }
40565
- else {
40566
- comments = comments.filter(comment => comment.hashFlag == null);
40567
- }
40492
+ posts = filterByPropEquality(posts, 'isDeleted', false);
40568
40493
  }
40569
- if (this.query.dataTypes) {
40570
- if (this.query.dataTypes.matchType === 'exact') {
40571
- comments = comments.filter(comment => {
40572
- var _a, _b;
40573
- const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40574
- const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40575
- if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40576
- return false;
40577
- }
40578
- return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
40579
- });
40580
- }
40581
- if (this.query.dataTypes.matchType === 'any') {
40582
- 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); }); });
40583
- }
40494
+ if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
40495
+ posts = filterByPostDataTypes(posts, this.query.dataTypes);
40584
40496
  }
40585
40497
  switch (this.query.sortBy) {
40586
40498
  case 'firstCreated':
40587
- comments = comments.sort(sortByFirstCreated);
40499
+ posts = posts.sort(sortByFirstCreated);
40588
40500
  break;
40589
40501
  case 'lastCreated':
40590
40502
  default:
40591
- comments = comments.sort(sortByLastCreated);
40503
+ posts = posts.sort(sortByLastCreated);
40592
40504
  break;
40593
40505
  }
40594
- return comments;
40506
+ return posts;
40595
40507
  }
40596
40508
  }
40597
40509
 
40598
40510
  /* begin_public_function
40599
- id: comment.query
40511
+ id: feed.query.user_feed
40600
40512
  */
40601
40513
  /**
40602
40514
  * ```js
40603
- * import { getComments } from '@amityco/ts-sdk'
40515
+ * import { FeedRepository } from '@amityco/ts-sdk'
40604
40516
  *
40605
- * let comments = []
40606
- * const unsub = getComments({
40607
- * referenceType: Amity.InternalComment['referenceType'];
40608
- * referenceId: Amity.InternalComment['referenceId'];
40609
- * }, response => merge(comments, response.data))
40517
+ * let posts = []
40518
+ * const unsubscribe = FeedRepository.getUserFeed({
40519
+ * userId: string,
40520
+ * feedSources: ['user', 'community'],
40521
+ * }, response => response => processResponse(response))
40610
40522
  * ```
40611
40523
  *
40612
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
40524
+ * Observe all mutations on a list of {@link Amity.Post} for a given user and feedSources
40613
40525
  *
40614
- * @param referenceType the type of the target
40615
- * @param referenceId the ID of the target
40526
+ * @param params.userId the ID of the user
40527
+ * @param params.feedSources the sources of the feed
40616
40528
  * @param callback the function to call when new data are available
40529
+ * @param config
40617
40530
  * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40618
40531
  *
40619
- * @category Comments Live Collection
40532
+ * @category Posts Live Collection
40620
40533
  */
40621
- const getComments = (params, callback, config) => {
40534
+ const getUserFeed = (params, callback, config) => {
40622
40535
  const { log, cache } = getActiveClient();
40623
40536
  if (!cache) {
40624
- console.log('For using Live Collection feature you need to enable Cache!');
40537
+ console.log(ENABLE_CACHE_MESSAGE);
40625
40538
  }
40626
40539
  const timestamp = Date.now();
40627
- log(`getComments(tmpid: ${timestamp}) > listen`);
40628
- const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40629
- const disposers = commentsLiveCollection.startSubscription();
40630
- const cacheKey = commentsLiveCollection.getCacheKey();
40540
+ log(`getUserFeed(tmpid: ${timestamp}) > listen`);
40541
+ const userFeedLiveCollection = new UserFeedLiveCollectionController(params, callback);
40542
+ const disposers = userFeedLiveCollection.startSubscription();
40543
+ const cacheKey = userFeedLiveCollection.getCacheKey();
40631
40544
  disposers.push(() => dropFromCache(cacheKey));
40632
40545
  return () => {
40633
- log(`getComments(tmpid: ${timestamp}) > dispose`);
40546
+ log(`getUserFeed(tmpid: ${timestamp}) > dispose`);
40634
40547
  disposers.forEach(fn => fn());
40635
40548
  };
40636
40549
  };
@@ -40638,117 +40551,495 @@ const getComments = (params, callback, config) => {
40638
40551
 
40639
40552
  var index$9 = /*#__PURE__*/Object.freeze({
40640
40553
  __proto__: null,
40641
- getCommentByIds: getCommentByIds,
40642
- createComment: createComment,
40643
- updateComment: updateComment,
40644
- deleteComment: deleteComment,
40645
- softDeleteComment: softDeleteComment,
40646
- hardDeleteComment: hardDeleteComment,
40647
- flagComment: flagComment,
40648
- unflagComment: unflagComment,
40649
- isCommentFlaggedByMe: isCommentFlaggedByMe,
40650
- onCommentCreated: onCommentCreated,
40651
- onCommentUpdated: onCommentUpdated,
40652
- onCommentDeleted: onCommentDeleted,
40653
- onCommentFlagged: onCommentFlagged,
40654
- onCommentUnflagged: onCommentUnflagged,
40655
- onCommentReactionAdded: onCommentReactionAdded,
40656
- onCommentReactionRemoved: onCommentReactionRemoved,
40657
- getComment: getComment,
40658
- getComments: getComments
40554
+ queryGlobalFeed: queryGlobalFeed,
40555
+ getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
40556
+ getUserFeed: getUserFeed
40659
40557
  });
40660
40558
 
40559
+ /* begin_public_function
40560
+ id: post.get_by_ids
40561
+ */
40562
+ /**
40563
+ * ```js
40564
+ * import { getPostByIds } from '@amityco/ts-sdk'
40565
+ * const { data: posts } = await getPostByIds(['foo', 'bar'])
40566
+ * ```
40567
+ *
40568
+ * Fetches a collection of {@link Amity.Post} objects
40569
+ *
40570
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
40571
+ * @returns the associated collection of {@link Amity.Post} objects
40572
+ *
40573
+ * @category Post API
40574
+ * @async
40575
+ */
40576
+ const getPostByIds = async (postIds) => {
40577
+ const client = getActiveClient();
40578
+ client.log('post/getPostByIds', postIds);
40579
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
40580
+ let payload;
40581
+ try {
40582
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
40583
+ const response = await client.http.get(`/api/v3/posts/list`, {
40584
+ params: { postIds: encodedPostIds },
40585
+ });
40586
+ payload = response.data;
40587
+ }
40588
+ catch (error) {
40589
+ postIds.forEach(postId => {
40590
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40591
+ pushToTombstone('post', postId);
40592
+ }
40593
+ });
40594
+ throw error;
40595
+ }
40596
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40597
+ const cachedAt = client.cache && Date.now();
40598
+ if (client.cache)
40599
+ ingestInCache(data, { cachedAt });
40600
+ return {
40601
+ data: data.posts.map(LinkedObject.post),
40602
+ cachedAt,
40603
+ };
40604
+ };
40605
+ /* end_public_function */
40606
+ /**
40607
+ * ```js
40608
+ * import { getPostByIds } from '@amityco/ts-sdk'
40609
+ * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
40610
+ * ```
40611
+ *
40612
+ * Fetches a collection of {@link Amity.Post} objects from cache
40613
+ *
40614
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
40615
+ * @returns the associated collection of {@link Amity.Post} objects
40616
+ *
40617
+ * @category Post API
40618
+ */
40619
+ getPostByIds.locally = (postIds) => {
40620
+ var _a;
40621
+ const client = getActiveClient();
40622
+ client.log('post/getPostByIds.locally', postIds);
40623
+ if (!client.cache)
40624
+ return;
40625
+ const cached = postIds
40626
+ .map(postId => pullFromCache(['post', 'get', postId]))
40627
+ .filter(Boolean);
40628
+ const posts = cached.map(({ data }) => data);
40629
+ const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
40630
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
40631
+ return;
40632
+ return {
40633
+ data: posts.map(LinkedObject.post),
40634
+ cachedAt: oldest.cachedAt,
40635
+ };
40636
+ };
40637
+
40638
+ /* begin_public_function
40639
+ 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
40640
+ */
40641
+ /**
40642
+ * ```js
40643
+ * import { PostRepository } from '@amityco/ts-sdk'
40644
+ * const created = await PostRepository.createPost({
40645
+ * targetType: 'user',
40646
+ * targetId: 'foobar',
40647
+ * data: { text: 'hello world' }
40648
+ * }))
40649
+ * ```
40650
+ *
40651
+ * Creates an {@link Amity.Post}
40652
+ *
40653
+ * @param bundle The data necessary to create a new {@link Amity.Post}
40654
+ * @returns The newly created {@link Amity.Post}
40655
+ *
40656
+ * @category Post API
40657
+ * @async
40658
+ */
40659
+ const createPost = async (bundle) => {
40660
+ const client = getActiveClient();
40661
+ client.log('post/createPost', bundle);
40662
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
40663
+ // eslint-disable-next-line no-param-reassign
40664
+ delete bundle.dataType;
40665
+ }
40666
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
40667
+ fireEvent('post.created', payload);
40668
+ const data = preparePostPayload(payload);
40669
+ const cachedAt = client.cache && Date.now();
40670
+ if (client.cache)
40671
+ ingestInCache(data, { cachedAt });
40672
+ const { posts } = data;
40673
+ return {
40674
+ data: LinkedObject.post(posts[0]),
40675
+ cachedAt,
40676
+ };
40677
+ };
40678
+ /* end_public_function */
40679
+
40680
+ /* begin_public_function
40681
+ id: post.edit, post.edit.custom_post
40682
+ */
40683
+ /**
40684
+ * ```js
40685
+ * import { PostRepository } from '@amityco/ts-sdk'
40686
+ * const updated = await PostRepository.editPost(postId, {
40687
+ * data: { text: 'hello world' }
40688
+ * })
40689
+ * ```
40690
+ *
40691
+ * Updates an {@link Amity.Post}
40692
+ *
40693
+ * @param postId The ID of the {@link Amity.Post} to edit
40694
+ * @param patch The patch data to apply
40695
+ * @returns the updated {@link Amity.Post} object
40696
+ *
40697
+ * @category Post API
40698
+ * @async
40699
+ */
40700
+ const editPost = async (postId, patch) => {
40701
+ const client = getActiveClient();
40702
+ client.log('user/editPost', patch);
40703
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
40704
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40705
+ const cachedAt = client.cache && Date.now();
40706
+ if (client.cache)
40707
+ ingestInCache(data, { cachedAt });
40708
+ fireEvent('local.post.updated', data);
40709
+ const { posts } = data;
40710
+ return {
40711
+ data: LinkedObject.post(posts.find(post => post.postId === postId)),
40712
+ cachedAt,
40713
+ };
40714
+ };
40715
+ /* end_public_function */
40716
+
40717
+ /**
40718
+ * ```js
40719
+ * import { deletePost } from '@amityco/ts-sdk'
40720
+ * const success = await deletePost('foobar')
40721
+ * ```
40722
+ *
40723
+ * Deletes a {@link Amity.Post}
40724
+ *
40725
+ * @param postId The {@link Amity.Post} ID to delete
40726
+ * @return A success boolean if the {@link Amity.Post} was deleted
40727
+ *
40728
+ * @private
40729
+ * @async
40730
+ */
40731
+ const deletePost = async (postId, permanent = false) => {
40732
+ var _a;
40733
+ const client = getActiveClient();
40734
+ const post = await getPost$2(postId);
40735
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
40736
+ params: {
40737
+ postId,
40738
+ permanent,
40739
+ },
40740
+ });
40741
+ // there is currently a limitation which doesn't allow us to fire event to tell that community
40742
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
40743
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
40744
+ // later when realtime events covers that for us.
40745
+ if (post.data.targetType === 'community') {
40746
+ const community = await getCommunity$1(post.data.targetId);
40747
+ const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
40748
+ const communityUsers = communityUsersCache
40749
+ .filter(({ key }) => {
40750
+ // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
40751
+ if (key[0] !== 'communityUsers')
40752
+ return false;
40753
+ if (key[1] !== 'get')
40754
+ return false;
40755
+ if (typeof key[2] === 'string')
40756
+ return key[2].includes(community.data.communityId);
40757
+ return false;
40758
+ })
40759
+ .map(({ data }) => data);
40760
+ fireEvent('community.updated', {
40761
+ communities: [community.data],
40762
+ categories: [],
40763
+ communityUsers,
40764
+ feeds: [],
40765
+ files: [],
40766
+ users: [],
40767
+ });
40768
+ }
40769
+ // to support hard deletion
40770
+ const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
40771
+ if (permanent) {
40772
+ setTimeout(() => {
40773
+ pushToTombstone('post', postId);
40774
+ }, 0);
40775
+ }
40776
+ else {
40777
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
40778
+ }
40779
+ fireEvent('local.post.deleted', {
40780
+ posts: [deleted],
40781
+ categories: [],
40782
+ comments: [],
40783
+ communities: [],
40784
+ communityUsers: [],
40785
+ feeds: [],
40786
+ files: [],
40787
+ postChildren: [],
40788
+ users: [],
40789
+ videoStreamings: [],
40790
+ });
40791
+ return LinkedObject.post(deleted);
40792
+ };
40793
+
40794
+ /* begin_public_function
40795
+ id: post.soft_delete
40796
+ */
40797
+ /**
40798
+ * ```js
40799
+ * import { PostRepository } from '@amityco/ts-sdk'
40800
+ * const success = await PostRepository.softDeletePost('foobar')
40801
+ * ```
40802
+ *
40803
+ * Soft deletes a {@link Amity.Post}
40804
+ *
40805
+ * @param postId The {@link Amity.Post} ID to soft delete
40806
+ * @return A success boolean if the {@link Amity.Post} was deleted
40807
+ *
40808
+ * @category Post API
40809
+ * @async
40810
+ */
40811
+ const softDeletePost = async (postId) => {
40812
+ const client = getActiveClient();
40813
+ client.log('post/softDeletePost', postId);
40814
+ const softDeleted = await deletePost(postId, false);
40815
+ return LinkedObject.post(softDeleted);
40816
+ };
40817
+ /* end_public_function */
40818
+
40819
+ /* begin_public_function
40820
+ id: post.hard_delete
40821
+ */
40822
+ /**
40823
+ * ```js
40824
+ * import { hardDeletePost } from '@amityco/ts-sdk'
40825
+ * const success = await hardDeletePost('foobar')
40826
+ * ```
40827
+ *
40828
+ * Hard deletes a {@link Amity.Post}
40829
+ *
40830
+ * @param postId The {@link Amity.Post} ID to be hard delete
40831
+ * @return A success boolean if the {@link Amity.Post} was deleted
40832
+ *
40833
+ * @category Post API
40834
+ * @async
40835
+ */
40836
+ const hardDeletePost = async (postId) => {
40837
+ const client = getActiveClient();
40838
+ client.log('post/hardDeletePost', postId);
40839
+ const hardDeleted = await deletePost(postId, true);
40840
+ return LinkedObject.post(hardDeleted);
40841
+ };
40842
+ /* end_public_function */
40843
+
40844
+ /* begin_public_function
40845
+ id: post.approve
40846
+ */
40847
+ /**
40848
+ * ```js
40849
+ * import { approvePost } from '@amityco/ts-sdk'
40850
+ *
40851
+ * const { data: post } = await approvePost('postId')
40852
+ * ```
40853
+ *
40854
+ * Approves a {@link Amity.Post}
40855
+ *
40856
+ * @param postId The {@link Amity.Post} ID to be approved
40857
+ * @return A {@link Amity.Post} that was approved
40858
+ *
40859
+ * @category Post API
40860
+ * @async
40861
+ */
40862
+ const approvePost = async (postId) => {
40863
+ const client = getActiveClient();
40864
+ client.log('post/approvePost', postId);
40865
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
40866
+ fireEvent('post.approved', payload);
40867
+ // fire virtual event for community update
40868
+ if (payload.posts[0].targetType === 'community') {
40869
+ fireEvent('community.updated', payload);
40870
+ }
40871
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40872
+ const cachedAt = client.cache && Date.now();
40873
+ if (client.cache)
40874
+ ingestInCache(data, { cachedAt });
40875
+ return {
40876
+ data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
40877
+ cachedAt,
40878
+ };
40879
+ };
40880
+ /* end_public_function */
40881
+
40882
+ /* begin_public_function
40883
+ id: post.decline
40884
+ */
40661
40885
  /**
40662
40886
  * ```js
40663
- * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40664
- * const dispose = onPostUpdatedLocal(post => {
40665
- * // ...
40666
- * })
40887
+ * import { declinePost } from '@amityco/ts-sdk'
40888
+ *
40889
+ * const {data: post} = await declinePost('postId')
40667
40890
  * ```
40668
40891
  *
40669
- * Fired when a {@link Amity.InternalPost} has been updated
40892
+ * Declines a {@link Amity.Post}
40670
40893
  *
40671
- * @param callback The function to call when the event was fired
40672
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40894
+ * @param postId The {@link Amity.Post} ID to be declined
40895
+ * @return A {@link Amity.Post} that was declined
40673
40896
  *
40674
- * @category Post Events
40897
+ * @category Post API
40898
+ * @async
40675
40899
  */
40676
- const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
40900
+ const declinePost = async (postId) => {
40901
+ const client = getActiveClient();
40902
+ client.log('post/declinePost', postId);
40903
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
40904
+ // fire virtual event
40905
+ if (payload.posts[0].targetType === 'community') {
40906
+ fireEvent('community.updated', payload);
40907
+ }
40908
+ fireEvent('post.declined', payload);
40909
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40910
+ const cachedAt = client.cache && Date.now();
40911
+ if (client.cache)
40912
+ ingestInCache(data, { cachedAt });
40913
+ return {
40914
+ data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
40915
+ cachedAt,
40916
+ };
40917
+ };
40918
+ /* end_public_function */
40677
40919
 
40920
+ /* begin_public_function
40921
+ id: post.flag
40922
+ */
40678
40923
  /**
40679
40924
  * ```js
40680
- * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40681
- * const dispose = onPostReactionAdded(post => {
40682
- * // ...
40683
- * })
40925
+ * import { PostRepository } from '@amityco/ts-sdk'
40926
+ * const flagged = await PostRepository.flagPost(postId, reason)
40684
40927
  * ```
40685
40928
  *
40686
- * Fired when a {@link Amity.InternalPost} has been reacted
40687
- *
40688
- * @param callback The function to call when the event was fired
40689
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40929
+ * @param postId of the post to flag
40930
+ * @param reason the reason to flag the post
40931
+ * @returns a boolean
40690
40932
  *
40691
- * @category Post Events
40692
- */
40693
- const onLocalPostReactionAdded = (callback) => {
40933
+ * @category Post API
40934
+ * @async
40935
+ * */
40936
+ const flagPost = async (postId, reason) => {
40694
40937
  const client = getActiveClient();
40695
- const filter = ({ post }) => {
40696
- if (!client.cache) {
40697
- callback(post);
40698
- }
40699
- else {
40700
- upsertInCache(['post', 'get', post.postId], post);
40701
- callback(post);
40702
- }
40938
+ client.log('post/flagPost', postId);
40939
+ const isPredefinedReason = reason &&
40940
+ Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
40941
+ const body = {
40942
+ reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
40943
+ detail: reason && !isPredefinedReason ? reason : '',
40703
40944
  };
40704
- return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
40945
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
40946
+ if (client.cache) {
40947
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
40948
+ }
40949
+ fireEvent('post.flagged', payload);
40950
+ return !!payload;
40705
40951
  };
40952
+ /* end_public_function */
40706
40953
 
40954
+ /* begin_public_function
40955
+ id: post.unflag
40956
+ */
40707
40957
  /**
40708
40958
  * ```js
40709
- * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40710
- * const dispose = onPostReactionRemoved(post => {
40711
- * // ...
40712
- * })
40959
+ * import { PostRepository } from '@amityco/ts-sdk'
40960
+ * const unflagged = await PostRepository.unflagPost(postId)
40713
40961
  * ```
40714
40962
  *
40715
- * Fired when a {@link Amity.InternalPost} has been reacted
40963
+ * @param postId of the post to unflag
40964
+ * @returns the unflag post result
40716
40965
  *
40717
- * @param callback The function to call when the event was fired
40718
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40966
+ * @category Post API
40967
+ * @async
40968
+ * */
40969
+ const unflagPost = async (postId) => {
40970
+ const client = getActiveClient();
40971
+ client.log('post/unflagPost', postId);
40972
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
40973
+ if (client.cache) {
40974
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
40975
+ }
40976
+ fireEvent('post.unflagged', payload);
40977
+ return !!payload;
40978
+ };
40979
+ /* end_public_function */
40980
+
40981
+ /* begin_public_function
40982
+ id: post.check_flag_by_me
40983
+ */
40984
+ /**
40985
+ * ```js
40986
+ * import { PostRepository } from '@amityco/ts-sdk'
40987
+ * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
40988
+ * ```
40719
40989
  *
40720
- * @category Post Events
40721
- */
40722
- const onLocalPostReactionRemoved = (callback) => {
40990
+ * @param postId of the post to check if flagged by current user
40991
+ * @returns `true` if the post is flagged by me, `false` if doesn't.
40992
+ *
40993
+ * @category Post API
40994
+ * @async
40995
+ * */
40996
+ const isPostFlaggedByMe = async (postId) => {
40723
40997
  const client = getActiveClient();
40724
- const filter = ({ post }) => {
40725
- if (!client.cache) {
40726
- callback(post);
40727
- }
40728
- else {
40729
- upsertInCache(['post', 'get', post.postId], post);
40730
- callback(post);
40731
- }
40732
- };
40733
- return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
40998
+ client.log('post/isPostFlaggedByMe', postId);
40999
+ const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
41000
+ return result;
40734
41001
  };
41002
+ /* end_public_function */
40735
41003
 
41004
+ /* begin_public_function
41005
+ id: post.create.clip_post
41006
+ */
40736
41007
  /**
40737
41008
  * ```js
40738
- * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40739
- * const dispose = onLocalPostDeleted(post => {
40740
- * // ...
40741
- * })
41009
+ * import { PostRepository } from '@amityco/ts-sdk'
41010
+ * const created = await PostRepository.createClipPost({
41011
+ * targetType: 'user',
41012
+ * targetId: 'foobar',
41013
+ * dataType: 'clip',
41014
+ * data: { text: 'hello world' },
41015
+ * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
41016
+ * }))
40742
41017
  * ```
40743
41018
  *
40744
- * Fired when a {@link Amity.InternalPost} has been deleted
41019
+ * Creates an {@link Amity.Post}
40745
41020
  *
40746
- * @param callback The function to call when the event was fired
40747
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41021
+ * @param bundle The data necessary to create a new {@link Amity.Post}
41022
+ * @returns The newly created {@link Amity.Post}
40748
41023
  *
40749
- * @category Post Events
41024
+ * @category Post API
41025
+ * @async
40750
41026
  */
40751
- const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
41027
+ const createClipPost = async (bundle) => {
41028
+ const client = getActiveClient();
41029
+ client.log('post/createPost', bundle);
41030
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
41031
+ fireEvent('post.created', payload);
41032
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41033
+ const cachedAt = client.cache && Date.now();
41034
+ if (client.cache)
41035
+ ingestInCache(data, { cachedAt });
41036
+ const { posts } = data;
41037
+ return {
41038
+ data: LinkedObject.post(posts[0]),
41039
+ cachedAt,
41040
+ };
41041
+ };
41042
+ /* end_public_function */
40752
41043
 
40753
41044
  /* begin_public_function
40754
41045
  id: post.get
@@ -40772,7 +41063,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
40772
41063
  *
40773
41064
  * @category Post Live Object
40774
41065
  */
40775
- const getPost$1 = (postId, callback) => {
41066
+ const getPost = (postId, callback) => {
40776
41067
  const responder = (snapshot) => {
40777
41068
  const { data } = snapshot;
40778
41069
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
@@ -40861,19 +41152,6 @@ class PostPaginationController extends PaginationController {
40861
41152
  }
40862
41153
  }
40863
41154
 
40864
- var EnumPostActions;
40865
- (function (EnumPostActions) {
40866
- EnumPostActions["OnPostCreated"] = "onPostCreated";
40867
- EnumPostActions["OnPostUpdated"] = "onPostUpdated";
40868
- EnumPostActions["OnPostDeleted"] = "onPostDeleted";
40869
- EnumPostActions["OnPostFlagged"] = "onPostFlagged";
40870
- EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
40871
- EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
40872
- EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
40873
- EnumPostActions["OnPostApproved"] = "onPostApproved";
40874
- EnumPostActions["OnPostDeclined"] = "onPostDeclined";
40875
- })(EnumPostActions || (EnumPostActions = {}));
40876
-
40877
41155
  class PostQueryStreamController extends QueryStreamController {
40878
41156
  constructor(query, cacheKey, notifyChange, preparePayload) {
40879
41157
  super(query, cacheKey);
@@ -40939,47 +41217,6 @@ class PostQueryStreamController extends QueryStreamController {
40939
41217
  }
40940
41218
  }
40941
41219
 
40942
- const getPost = async (postId) => {
40943
- const client = getActiveClient();
40944
- client.log('post/getPost', postId);
40945
- isInTombstone('post', postId);
40946
- let payload;
40947
- try {
40948
- // API-FIX: endpoint should not be /list, parameters should be querystring.
40949
- const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
40950
- payload = response.data;
40951
- }
40952
- catch (error) {
40953
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40954
- pushToTombstone('post', postId);
40955
- }
40956
- throw error;
40957
- }
40958
- const data = prepareMembershipPayload(payload, 'communityUsers');
40959
- const cachedAt = client.cache && Date.now();
40960
- if (client.cache)
40961
- ingestInCache(data, { cachedAt });
40962
- const { posts } = data;
40963
- const result = posts.find(post => post.postId === postId);
40964
- return {
40965
- data: result,
40966
- cachedAt,
40967
- };
40968
- };
40969
- getPost.locally = (postId) => {
40970
- const client = getActiveClient();
40971
- client.log('post/getPost.locally', postId);
40972
- if (!client.cache)
40973
- return;
40974
- const cached = pullFromCache(['post', 'get', postId]);
40975
- if (!cached)
40976
- return;
40977
- return {
40978
- data: cached.data,
40979
- cachedAt: cached.cachedAt,
40980
- };
40981
- };
40982
-
40983
41220
  class PostLiveCollectionController extends LiveCollectionController {
40984
41221
  constructor(query, callback) {
40985
41222
  const queryStreamId = hash(query);
@@ -41029,7 +41266,7 @@ class PostLiveCollectionController extends LiveCollectionController {
41029
41266
  const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41030
41267
  if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41031
41268
  return;
41032
- await getPost(comment.referenceId);
41269
+ await getPost$1(comment.referenceId);
41033
41270
  callback(comment);
41034
41271
  });
41035
41272
  }, 'referenceId', 'post'),
@@ -41042,7 +41279,7 @@ class PostLiveCollectionController extends LiveCollectionController {
41042
41279
  const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41043
41280
  if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41044
41281
  return;
41045
- await getPost(comment.referenceId);
41282
+ await getPost$1(comment.referenceId);
41046
41283
  callback(comment);
41047
41284
  });
41048
41285
  }, 'referenceId', 'post'),
@@ -41668,7 +41905,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
41668
41905
  onPostUnflagged: onPostUnflagged,
41669
41906
  onPostReactionAdded: onPostReactionAdded,
41670
41907
  onPostReactionRemoved: onPostReactionRemoved,
41671
- getPost: getPost$1,
41908
+ getPost: getPost,
41672
41909
  getPosts: getPosts,
41673
41910
  getPinnedPosts: getPinnedPosts,
41674
41911
  getGlobalPinnedPosts: getGlobalPinnedPosts,
@@ -42551,7 +42788,7 @@ var index$6 = /*#__PURE__*/Object.freeze({
42551
42788
  getPoll: getPoll
42552
42789
  });
42553
42790
 
42554
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
42791
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
42555
42792
  /*
42556
42793
  * The crypto algorithm used for importing key and signing string
42557
42794
  */
@@ -44866,4 +45103,4 @@ var index = /*#__PURE__*/Object.freeze({
44866
45103
  getReactions: getReactions
44867
45104
  });
44868
45105
 
44869
- export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$9 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$a as FeedRepository, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
45106
+ export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$a as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };